@@ -28,6 +28,9 @@ public class OptionListWidget extends ElementListWidget<OptionListWidget.Entry>
2828
2929 private ImmutableList <Entry > viewableChildren ;
3030
31+ private double smoothScrollAmount = getScrollAmount ();
32+ private boolean returnSmoothAmount = false ;
33+
3134 public OptionListWidget (YACLScreen screen , MinecraftClient client , int width , int height ) {
3235 super (client , width / 3 * 2 , height , 0 , height , 22 );
3336 this .yaclScreen = screen ;
@@ -62,7 +65,7 @@ public void refreshOptions() {
6265
6366 List <OptionEntry > optionEntries = new ArrayList <>();
6467 for (Option <?> option : group .options ()) {
65- OptionEntry entry = new OptionEntry (category , group , option .controller ().provideWidget (yaclScreen , Dimension .ofInt (getRowLeft (), 0 , getRowWidth (), 20 )), viewableSupplier );
68+ OptionEntry entry = new OptionEntry (option , category , group , option .controller ().provideWidget (yaclScreen , Dimension .ofInt (getRowLeft (), 0 , getRowWidth (), 20 )), viewableSupplier );
6669 addEntry (entry );
6770 optionEntries .add (entry );
6871 }
@@ -148,14 +151,34 @@ protected void renderList(MatrixStack matrices, int mouseX, int mouseY, float de
148151 }
149152 }
150153
154+ /* END cloth config code */
155+
156+ @ Override
157+ public void render (MatrixStack matrices , int mouseX , int mouseY , float delta ) {
158+ smoothScrollAmount = MathHelper .lerp (MinecraftClient .getInstance ().getLastFrameDuration () * 0.5 , smoothScrollAmount , getScrollAmount ());
159+ returnSmoothAmount = true ;
160+ super .render (matrices , mouseX , mouseY , delta );
161+ returnSmoothAmount = false ;
162+ }
163+
164+ /**
165+ * awful code to only use smooth scroll state when rendering,
166+ * not other code that needs target scroll amount
167+ */
168+ @ Override
169+ public double getScrollAmount () {
170+ if (returnSmoothAmount )
171+ return smoothScrollAmount ;
172+
173+ return super .getScrollAmount ();
174+ }
175+
151176 public void postRender (MatrixStack matrices , int mouseX , int mouseY , float delta ) {
152177 for (Entry entry : children ()) {
153178 entry .postRender (matrices , mouseX , mouseY , delta );
154179 }
155180 }
156181
157- /* END cloth config code */
158-
159182 @ Override
160183 public int getRowWidth () {
161184 return Math .min (396 , (int )(width / 1.3f ));
@@ -178,7 +201,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
178201 return true ;
179202 }
180203
181- this .setScrollAmount (this .getScrollAmount () - amount * (double ) (getMaxScroll () / getEntryCount ()) / 2.0D );
204+ this .setScrollAmount (this .getScrollAmount () - amount * 20 /* * (double) (getMaxScroll() / getEntryCount()) / 2.0D */ );
182205 return true ;
183206 }
184207
@@ -221,7 +244,7 @@ public void recacheViewableChildren() {
221244 int i = 0 ;
222245 for (Entry entry : viewableChildren ) {
223246 if (entry instanceof OptionEntry optionEntry )
224- optionEntry .widget .setDimension (optionEntry .widget .getDimension ().setY (getRowTop (i )));
247+ optionEntry .widget .setDimension (optionEntry .widget .getDimension ().withY (getRowTop (i )));
225248 i ++;
226249 }
227250 }
@@ -250,29 +273,48 @@ protected boolean isHovered() {
250273 }
251274
252275 public class OptionEntry extends Entry {
276+ public final Option <?> option ;
253277 public final ConfigCategory category ;
254278 public final OptionGroup group ;
255279
256280 public final AbstractWidget widget ;
257281 private final Supplier <Boolean > viewableSupplier ;
258282
283+ private final TextScaledButtonWidget resetButton ;
284+
259285 private final String categoryName ;
260286 private final String groupName ;
261287
262- private OptionEntry (ConfigCategory category , OptionGroup group , AbstractWidget widget , Supplier <Boolean > viewableSupplier ) {
288+ private OptionEntry (Option <?> option , ConfigCategory category , OptionGroup group , AbstractWidget widget , Supplier <Boolean > viewableSupplier ) {
289+ this .option = option ;
263290 this .category = category ;
264291 this .group = group ;
265292 this .widget = widget ;
266293 this .viewableSupplier = viewableSupplier ;
267294 this .categoryName = category .name ().getString ().toLowerCase ();
268295 this .groupName = group .name ().getString ().toLowerCase ();
296+ if (this .widget .canReset ()) {
297+ this .widget .setDimension (this .widget .getDimension ().expanded (-21 , 0 ));
298+ this .resetButton = new TextScaledButtonWidget (widget .getDimension ().xLimit () + 1 , -50 , 20 , 20 , 2f , Text .of ("\u21BB " ), button -> {
299+ option .requestSetDefault ();
300+ });
301+ option .addListener ((opt , val ) -> this .resetButton .active = !opt .isPendingValueDefault () && opt .available ());
302+ this .resetButton .active = !option .isPendingValueDefault () && option .available ();
303+ } else {
304+ this .resetButton = null ;
305+ }
269306 }
270307
271308 @ Override
272309 public void render (MatrixStack matrices , int index , int y , int x , int entryWidth , int entryHeight , int mouseX , int mouseY , boolean hovered , float tickDelta ) {
273- widget .setDimension (widget .getDimension ().setY (y ));
310+ widget .setDimension (widget .getDimension ().withY (y ));
274311
275312 widget .render (matrices , mouseX , mouseY , tickDelta );
313+
314+ if (resetButton != null ) {
315+ resetButton .y = y ;
316+ resetButton .render (matrices , mouseX , mouseY , tickDelta );
317+ }
276318 }
277319
278320 @ Override
@@ -312,12 +354,18 @@ public int getItemHeight() {
312354
313355 @ Override
314356 public List <? extends Selectable > selectableChildren () {
315- return ImmutableList .of (widget );
357+ if (resetButton == null )
358+ return ImmutableList .of (widget );
359+
360+ return ImmutableList .of (widget , resetButton );
316361 }
317362
318363 @ Override
319364 public List <? extends Element > children () {
320- return ImmutableList .of (widget );
365+ if (resetButton == null )
366+ return ImmutableList .of (widget );
367+
368+ return ImmutableList .of (widget , resetButton );
321369 }
322370 }
323371
0 commit comments