77import net .fabricmc .api .EnvType ;
88import net .fabricmc .api .Environment ;
99import net .minecraft .client .font .TextRenderer ;
10- import net .minecraft .client .gui .AbstractParentElement ;
1110import net .minecraft .client .gui .Drawable ;
1211import net .minecraft .client .gui .Element ;
1312import net .minecraft .client .gui .RotatingCubeMapRenderer ;
1413import net .minecraft .client .gui .screen .Screen ;
1514import net .minecraft .client .gui .screen .TitleScreen ;
16- import net .minecraft .client .gui .widget .AbstractButtonWidget ;
1715import net .minecraft .client .gui .widget .ButtonWidget ;
16+ import net .minecraft .client .gui .widget .ClickableWidget ;
1817import net .minecraft .client .gui .widget .SliderWidget ;
1918import net .minecraft .client .gui .widget .TextFieldWidget ;
2019import net .minecraft .client .util .math .MatrixStack ;
@@ -40,12 +39,12 @@ protected ConfigScreen(Screen parent) {
4039 protected void init () {
4140 final int y_padding = 28 ;
4241
43- this .addButton (new ButtonWidget (this .width / 2 - 154 , this .height - y_padding , 150 , 20 ,
42+ this .addDrawableChild (new ButtonWidget (this .width / 2 - 154 , this .height - y_padding , 150 , 20 ,
4443 new TranslatableText ("gui.cancel" ), (button ) -> {
4544 this .restoreConfig ();
4645 client .openScreen (parent );
4746 }));
48- this .addButton (new ButtonWidget (this .width / 2 + 4 , this .height - y_padding , 150 , 20 ,
47+ this .addDrawableChild (new ButtonWidget (this .width / 2 + 4 , this .height - y_padding , 150 , 20 ,
4948 new TranslatableText ("gui.done" ), (button ) -> {
5049 this .saveConfig ();
5150 client .openScreen (parent );
@@ -57,44 +56,57 @@ protected void init() {
5756 int x = (this .width / 2 ) - 154 ;
5857 int y = ((this .height - widgetPadding ) * 0 ) / widgetCount + y_padding ;
5958
60- this .children
61- .addAll ((new OptionWidget (this .textRenderer , new TranslatableText ("panorama_tweaker.rotationSpeed" ), x ,
62- y , 308 , 20 , Config .DEFAULT_ROTATION_SPEED , PanoramaTweaker .config .rotationSpeed , -10 , 10 ,
63- val -> PanoramaTweaker .config .rotationSpeed = val )).children ());
59+ for (ClickableWidget child : (new OptionWidget (this .textRenderer ,
60+ new TranslatableText ("panorama_tweaker.rotationSpeed" ), x , y , 308 , 20 , Config .DEFAULT_ROTATION_SPEED ,
61+ PanoramaTweaker .config .rotationSpeed , -10 , 10 , val -> PanoramaTweaker .config .rotationSpeed = val ))
62+ .children ()) {
63+ this .addDrawableChild (child );
64+ }
6465
6566 y = ((this .height - widgetPadding ) * 1 ) / widgetCount + y_padding ;
66- this . children . addAll ((new OptionWidget (this .textRenderer ,
67+ for ( ClickableWidget child : ((new OptionWidget (this .textRenderer ,
6768 new TranslatableText ("panorama_tweaker.startingHorizontalAngle" ), x , y , 308 , 20 ,
6869 Config .DEFAULT_STARTING_HORIZONTAL_ANGLE , PanoramaTweaker .config .startingHorizontalAngle , -180 , 180 ,
69- val -> PanoramaTweaker .config .startingHorizontalAngle = val )).children ());
70+ val -> PanoramaTweaker .config .startingHorizontalAngle = val )).children ())) {
71+ this .addDrawableChild (child );
72+ }
7073
7174 y = ((this .height - widgetPadding ) * 2 ) / widgetCount + y_padding ;
72- this .children
73- .addAll ((new OptionWidget (this .textRenderer , new TranslatableText ("panorama_tweaker.verticalAngle" ), x ,
74- y , 308 , 20 , Config .DEFAULT_VERTICAL_ANGLE , PanoramaTweaker .config .verticalAngle , -90 , 90 ,
75- val -> PanoramaTweaker .config .verticalAngle = val )).children ());
75+ for (ClickableWidget child : ((new OptionWidget (this .textRenderer ,
76+ new TranslatableText ("panorama_tweaker.verticalAngle" ), x , y , 308 , 20 , Config .DEFAULT_VERTICAL_ANGLE ,
77+ PanoramaTweaker .config .verticalAngle , -90 , 90 , val -> PanoramaTweaker .config .verticalAngle = val ))
78+ .children ())) {
79+ this .addDrawableChild (child );
80+ }
7681
7782 y = ((this .height - widgetPadding ) * 3 ) / widgetCount + y_padding ;
78- this .children .addAll ((new OptionWidget (this .textRenderer , new TranslatableText ("panorama_tweaker.swayAngle" ), x ,
79- y , 308 , 20 , Config .DEFAULT_SWAY_ANGLE , PanoramaTweaker .config .swayAngle , -90 , 90 ,
80- val -> PanoramaTweaker .config .swayAngle = val )).children ());
83+ for (ClickableWidget child : ((new OptionWidget (this .textRenderer ,
84+ new TranslatableText ("panorama_tweaker.swayAngle" ), x , y , 308 , 20 , Config .DEFAULT_SWAY_ANGLE ,
85+ PanoramaTweaker .config .swayAngle , -90 , 90 , val -> PanoramaTweaker .config .swayAngle = val ))
86+ .children ())) {
87+ this .addDrawableChild (child );
88+ }
8189
8290 y = ((this .height - widgetPadding ) * 4 ) / widgetCount + y_padding ;
83- this .children .addAll ((new OptionWidget (this .textRenderer , new TranslatableText ("panorama_tweaker.swaySpeed" ), x ,
84- y , 308 , 20 , Config .DEFAULT_SWAY_SPEED , PanoramaTweaker .config .swaySpeed , 0 , 10 ,
85- val -> PanoramaTweaker .config .swaySpeed = val )).children ());
91+ for (ClickableWidget child : ((new OptionWidget (this .textRenderer ,
92+ new TranslatableText ("panorama_tweaker.swaySpeed" ), x , y , 308 , 20 , Config .DEFAULT_SWAY_SPEED ,
93+ PanoramaTweaker .config .swaySpeed , 0 , 10 , val -> PanoramaTweaker .config .swaySpeed = val )).children ())) {
94+ this .addDrawableChild (child );
95+ }
8696
8797 y = ((this .height - widgetPadding ) * 5 ) / widgetCount + y_padding ;
88- this .children .addAll (
89- (new OptionWidget (this .textRenderer , new TranslatableText ("panorama_tweaker.initialSwayProgress" ), x , y ,
90- 308 , 20 , Config .DEFAULT_INITIAL_SWAY_PROGRESS , PanoramaTweaker .config .initialSwayProgress , -1 ,
91- 1 , val -> PanoramaTweaker .config .initialSwayProgress = val )).children ());
98+ for (ClickableWidget child : ((new OptionWidget (this .textRenderer ,
99+ new TranslatableText ("panorama_tweaker.initialSwayProgress" ), x , y , 308 , 20 ,
100+ Config .DEFAULT_INITIAL_SWAY_PROGRESS , PanoramaTweaker .config .initialSwayProgress , -1 , 1 ,
101+ val -> PanoramaTweaker .config .initialSwayProgress = val )).children ())) {
102+ this .addDrawableChild (child );
103+ }
92104 }
93105
94106 @ Override
95107 public void render (MatrixStack matrices , int mouseX , int mouseY , float delta ) {
96108 this .backgroundRenderer .render (delta , MathHelper .clamp (1 , 0.0F , 1.0F ));
97- for (Element child : this .children ) {
109+ for (Element child : this .children () ) {
98110 if (child instanceof Drawable ) {
99111 ((Drawable ) child ).render (matrices , mouseX , mouseY , delta );
100112 }
@@ -103,10 +115,10 @@ public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
103115
104116 @ Override
105117 public boolean mouseClicked (double mouseX , double mouseY , int button ) {
106- for (Element child : this .children ) {
107- if (child instanceof AbstractButtonWidget ) {
108- if (((AbstractButtonWidget ) child ).isFocused ()) {
109- ((AbstractButtonWidget ) child ).changeFocus (false );
118+ for (Element child : this .children () ) {
119+ if (child instanceof ClickableWidget ) {
120+ if (((ClickableWidget ) child ).isFocused ()) {
121+ ((ClickableWidget ) child ).changeFocus (false );
110122 }
111123 }
112124 }
@@ -121,10 +133,10 @@ protected void saveConfig() {
121133 PanoramaTweaker .config .save ();
122134 }
123135
124- protected class OptionWidget extends AbstractParentElement {
136+ protected class OptionWidget {
125137 private final double defaultVal ;
126138
127- private final List <AbstractButtonWidget > children ;
139+ private final List <ClickableWidget > children ;
128140 private final OptionSlider slider ;
129141 private final TextFieldWidget textField ;
130142 private final ButtonWidget resetButton ;
@@ -158,12 +170,11 @@ public OptionWidget(TextRenderer font, TranslatableText text, int x, int y, int
158170 this .textField .setUneditableColor (0xFF0000 );
159171 }
160172 });
161- this .setFocused (this .textField );
162173 this .resetButton = new ButtonWidget (x + width - 50 , y , 50 , height , new TranslatableText ("controls.reset" ),
163174 (buttonWidget ) -> {
164175 this .resetToDefault ();
165176 });
166- this .children = new ArrayList <AbstractButtonWidget >();
177+ this .children = new ArrayList <ClickableWidget >();
167178 this .children .add (this .slider );
168179 this .children .add (this .textField );
169180 this .children .add (this .resetButton );
@@ -193,8 +204,7 @@ protected boolean isDefault() {
193204 return this .value == this .defaultVal ;
194205 }
195206
196- @ Override
197- public List <? extends Element > children () {
207+ public List <ClickableWidget > children () {
198208 return this .children ;
199209 }
200210
0 commit comments