Skip to content

Commit f86a630

Browse files
authored
Simplify toggle button - fix crash
1 parent 1d386db commit f86a630

File tree

1 file changed

+15
-36
lines changed

1 file changed

+15
-36
lines changed

src/main/java/com/ldtteam/blockui/controls/ToggleButton.java

Lines changed: 15 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.ldtteam.blockui.controls;
22

3-
import com.ldtteam.blockui.BOGuiGraphics;
43
import com.ldtteam.blockui.PaneParams;
54
import com.ldtteam.blockui.Parsers;
65
import net.minecraft.resources.ResourceLocation;
@@ -15,32 +14,30 @@
1514
/**
1615
* A Button pane for conveniently cycling through different states on click
1716
* with a shorthand to define different options quickly from the parameters.
17+
*
18+
* TODO: rework in port
1819
*/
19-
public class ToggleButton extends Button
20+
public class ToggleButton extends ButtonImage
2021
{
2122
private static final Pattern SHORT_TRANSLATION = Pattern.compile("(\\$[({]\\S+)\\.\\S+([})])\\|(\\$\\.[^$|\\s]+)");
2223

2324
protected List<String> rawStates;
2425
protected List<MutableComponent> states;
2526
protected int active = 0;
2627

27-
protected Button button;
28-
2928
public ToggleButton(final PaneParams params)
3029
{
3130
super(params);
32-
button = Button.construct(params);
33-
3431
setStateList(params.getString("options", ""));
3532
}
3633

3734
/**
3835
* Creates a new toggleable vanilla button
3936
* @param options the available states as raw text strings
4037
*/
38+
@Deprecated(forRemoval = true, since = "1.20.1")
4139
public ToggleButton(String... options)
4240
{
43-
button = new ButtonVanilla();
4441
setStateList(String.join("|", options));
4542
}
4643

@@ -49,10 +46,10 @@ public ToggleButton(String... options)
4946
* @param image the image to set as the button's background
5047
* @param options the available states as raw text strings
5148
*/
49+
@Deprecated(forRemoval = true, since = "1.20.1")
5250
public ToggleButton(ResourceLocation image, String... options)
5351
{
54-
button = new ButtonImage();
55-
((ButtonImage) button).setImage(image, false);
52+
setImage(image, false);
5653
setStateList(String.join("|", options));
5754
}
5855

@@ -74,11 +71,11 @@ protected void setStateList(String options)
7471

7572
if (!states.isEmpty())
7673
{
77-
button.setText(states.get(active));
74+
setText(states.get(active));
7875
}
7976
else
8077
{
81-
button.clearText();
78+
clearText();
8279
}
8380
}
8481

@@ -133,12 +130,12 @@ public boolean setActiveState(String state)
133130
if (index >= 0)
134131
{
135132
active = index;
136-
button.setText(states.get(active));
133+
setText(states.get(active));
137134
return true;
138135
}
139136
else
140137
{
141-
button.clearText();
138+
clearText();
142139
return false;
143140
}
144141
}
@@ -147,22 +144,16 @@ public boolean setActiveState(String state)
147144
* Change the underlying button pane
148145
* @param button the new button pane to render
149146
*/
147+
@Deprecated(forRemoval = true, since = "1.20.1")
150148
public void setButton(Button button)
151149
{
152-
this.button = button;
153-
if (!states.isEmpty())
154-
{
155-
button.setText(states.get(active));
156-
}
157-
else
158-
{
159-
button.clearText();
160-
}
150+
// noop
161151
}
162152

153+
@Deprecated(forRemoval = true, since = "1.20.1")
163154
public Button getButton()
164155
{
165-
return button;
156+
return this;
166157
}
167158

168159
@Override
@@ -171,21 +162,9 @@ public boolean handleClick(final double mx, final double my)
171162
if (!states.isEmpty())
172163
{
173164
active = (active + 1) % states.size();
174-
button.setText(states.get(active));
165+
setText(states.get(active));
175166
}
176167

177168
return super.handleClick(mx, my);
178169
}
179-
180-
@Override
181-
public void drawSelf(final BOGuiGraphics ms, final double mx, final double my)
182-
{
183-
button.drawSelf(ms, mx, my);
184-
}
185-
186-
@Override
187-
public void drawSelfLast(final BOGuiGraphics ms, final double mx, final double my)
188-
{
189-
button.drawSelfLast(ms, mx, my);
190-
}
191170
}

0 commit comments

Comments
 (0)