1
1
package com .ldtteam .blockui .controls ;
2
2
3
- import com .ldtteam .blockui .BOGuiGraphics ;
4
3
import com .ldtteam .blockui .PaneParams ;
5
4
import com .ldtteam .blockui .Parsers ;
6
5
import net .minecraft .resources .ResourceLocation ;
15
14
/**
16
15
* A Button pane for conveniently cycling through different states on click
17
16
* with a shorthand to define different options quickly from the parameters.
17
+ *
18
+ * TODO: rework in port
18
19
*/
19
- public class ToggleButton extends Button
20
+ public class ToggleButton extends ButtonImage
20
21
{
21
22
private static final Pattern SHORT_TRANSLATION = Pattern .compile ("(\\ $[({]\\ S+)\\ .\\ S+([})])\\ |(\\ $\\ .[^$|\\ s]+)" );
22
23
23
24
protected List <String > rawStates ;
24
25
protected List <MutableComponent > states ;
25
26
protected int active = 0 ;
26
27
27
- protected Button button ;
28
-
29
28
public ToggleButton (final PaneParams params )
30
29
{
31
30
super (params );
32
- button = Button .construct (params );
33
-
34
31
setStateList (params .getString ("options" , "" ));
35
32
}
36
33
37
34
/**
38
35
* Creates a new toggleable vanilla button
39
36
* @param options the available states as raw text strings
40
37
*/
38
+ @ Deprecated (forRemoval = true , since = "1.20.1" )
41
39
public ToggleButton (String ... options )
42
40
{
43
- button = new ButtonVanilla ();
44
41
setStateList (String .join ("|" , options ));
45
42
}
46
43
@@ -49,10 +46,10 @@ public ToggleButton(String... options)
49
46
* @param image the image to set as the button's background
50
47
* @param options the available states as raw text strings
51
48
*/
49
+ @ Deprecated (forRemoval = true , since = "1.20.1" )
52
50
public ToggleButton (ResourceLocation image , String ... options )
53
51
{
54
- button = new ButtonImage ();
55
- ((ButtonImage ) button ).setImage (image , false );
52
+ setImage (image , false );
56
53
setStateList (String .join ("|" , options ));
57
54
}
58
55
@@ -74,11 +71,11 @@ protected void setStateList(String options)
74
71
75
72
if (!states .isEmpty ())
76
73
{
77
- button . setText (states .get (active ));
74
+ setText (states .get (active ));
78
75
}
79
76
else
80
77
{
81
- button . clearText ();
78
+ clearText ();
82
79
}
83
80
}
84
81
@@ -133,12 +130,12 @@ public boolean setActiveState(String state)
133
130
if (index >= 0 )
134
131
{
135
132
active = index ;
136
- button . setText (states .get (active ));
133
+ setText (states .get (active ));
137
134
return true ;
138
135
}
139
136
else
140
137
{
141
- button . clearText ();
138
+ clearText ();
142
139
return false ;
143
140
}
144
141
}
@@ -147,22 +144,16 @@ public boolean setActiveState(String state)
147
144
* Change the underlying button pane
148
145
* @param button the new button pane to render
149
146
*/
147
+ @ Deprecated (forRemoval = true , since = "1.20.1" )
150
148
public void setButton (Button button )
151
149
{
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
161
151
}
162
152
153
+ @ Deprecated (forRemoval = true , since = "1.20.1" )
163
154
public Button getButton ()
164
155
{
165
- return button ;
156
+ return this ;
166
157
}
167
158
168
159
@ Override
@@ -171,21 +162,9 @@ public boolean handleClick(final double mx, final double my)
171
162
if (!states .isEmpty ())
172
163
{
173
164
active = (active + 1 ) % states .size ();
174
- button . setText (states .get (active ));
165
+ setText (states .get (active ));
175
166
}
176
167
177
168
return super .handleClick (mx , my );
178
169
}
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
- }
191
170
}
0 commit comments