1717package dev .terminalmc .commandkeys .gui .screen ;
1818
1919import com .mojang .blaze3d .platform .InputConstants ;
20- import com .mojang .blaze3d .platform .Window ;
2120import dev .terminalmc .commandkeys .CommandKeys ;
2221import dev .terminalmc .commandkeys .config .Config ;
22+ import dev .terminalmc .commandkeys .gui .widget .list .MainOptionList ;
2323import dev .terminalmc .commandkeys .gui .widget .list .OptionList ;
2424import dev .terminalmc .commandkeys .gui .widget .list .ProfileOptionList ;
25- import dev .terminalmc .commandkeys .gui .widget .list .MainOptionList ;
2625import net .minecraft .client .Minecraft ;
2726import net .minecraft .client .gui .Font ;
2827import net .minecraft .client .gui .GuiGraphics ;
2928import net .minecraft .client .gui .components .Button ;
3029import net .minecraft .client .gui .components .StringWidget ;
30+ import net .minecraft .client .gui .screens .OptionsSubScreen ;
3131import net .minecraft .client .gui .screens .Screen ;
32- import net .minecraft .client .gui .screens .options .OptionsSubScreen ;
3332import net .minecraft .network .chat .CommonComponents ;
3433import net .minecraft .network .chat .Component ;
3534import org .jetbrains .annotations .NotNull ;
3635
36+ import java .util .function .Supplier ;
37+
3738import static dev .terminalmc .commandkeys .util .Localization .localized ;
3839
3940/**
4041 * Contains one tightly-coupled {@link OptionList}, which is used to display
4142 * all option control widgets.
4243 */
4344public class OptionsScreen extends OptionsSubScreen {
44- public static final int TOP_MARGIN = 32 ;
45- public static final int BOTTOM_MARGIN = 32 ;
46- public static final int LIST_ENTRY_SPACE = 25 ;
47- public static final int LIST_ENTRY_HEIGHT = 20 ;
48- public static final int BASE_ROW_WIDTH = Window . BASE_WIDTH ;
49- public static final int BASE_LIST_ENTRY_WIDTH = BASE_ROW_WIDTH - 20 ;
45+ public final int listTop = 32 ;
46+ public final Supplier < Integer > listBottom = () -> height - 32 ;
47+ public static final int listItemHeight = 25 ;
48+ public static final int listEntryHeight = 20 ;
49+ public static final int baseRowWidth = 320 ;
50+ public static final int baseListEntryWidth = baseRowWidth - 20 ;
5051
5152 protected OptionList optionList ;
5253
@@ -55,13 +56,13 @@ public OptionsScreen(Screen lastScreen, boolean inGame) {
5556 inGame ? localized ("option" , "profile" , CommandKeys .profile ().getDisplayName ())
5657 : localized ("option" , "main" ));
5758 if (inGame ) {
58- optionList = new ProfileOptionList (Minecraft .getInstance (), 0 , 0 , TOP_MARGIN ,
59- LIST_ENTRY_SPACE , BASE_LIST_ENTRY_WIDTH , LIST_ENTRY_HEIGHT ,
59+ optionList = new ProfileOptionList (Minecraft .getInstance (), 0 , 0 , listTop ,
60+ listBottom . get (), listItemHeight , baseListEntryWidth , listEntryHeight ,
6061 CommandKeys .profile ());
6162 }
6263 else {
63- optionList = new MainOptionList (Minecraft .getInstance (), 0 , 0 , TOP_MARGIN ,
64- LIST_ENTRY_SPACE , BASE_LIST_ENTRY_WIDTH , LIST_ENTRY_HEIGHT , null );
64+ optionList = new MainOptionList (Minecraft .getInstance (), 0 , 0 , listTop ,
65+ listBottom . get (), listItemHeight , baseListEntryWidth , listEntryHeight , null );
6566 }
6667 }
6768
@@ -75,11 +76,6 @@ protected void init() {
7576 reload ();
7677 }
7778
78- @ Override
79- protected void addOptions () {
80- // Not currently used
81- }
82-
8379 @ Override
8480 public void resize (@ NotNull Minecraft mc , int width , int height ) {
8581 super .resize (mc , width , height );
@@ -113,6 +109,7 @@ public boolean mouseReleased(double mouseX, double mouseY, int delta) {
113109
114110 @ Override
115111 public void render (@ NotNull GuiGraphics graphics , int mouseX , int mouseY , float delta ) {
112+ renderDirtBackground (graphics );
116113 super .render (graphics , mouseX , mouseY , delta );
117114 }
118115
@@ -136,21 +133,21 @@ public OptionList reload() {
136133
137134 public OptionList reload (int width , int height ) {
138135 clearWidgets ();
139- optionList = optionList .reload (this , width , height - TOP_MARGIN - BOTTOM_MARGIN ,
140- optionList .getScrollAmount ());
136+ optionList = optionList .reload (this , width , listBottom . get () - listTop ,
137+ listTop , listBottom . get (), optionList .getScrollAmount ());
141138 addRenderableWidget (optionList );
142139
143140 // Title text
144141 Font font = Minecraft .getInstance ().font ;
145142 addRenderableWidget (new StringWidget (width / 2 - (font .width (title ) / 2 ),
146- Math .max (0 , TOP_MARGIN / 2 - font .lineHeight / 2 ),
143+ Math .max (0 , listTop / 2 - font .lineHeight / 2 ),
147144 font .width (title ), font .lineHeight , title , font ).alignLeft ());
148145
149146 // Done button
150147 addRenderableWidget (Button .builder (CommonComponents .GUI_DONE , (button ) -> onClose ())
151- .pos (width / 2 - BASE_LIST_ENTRY_WIDTH / 2 , Math .min (height - LIST_ENTRY_HEIGHT ,
152- height - BOTTOM_MARGIN / 2 - LIST_ENTRY_HEIGHT / 2 ))
153- .size (BASE_LIST_ENTRY_WIDTH , LIST_ENTRY_HEIGHT )
148+ .pos (width / 2 - baseListEntryWidth / 2 , Math .min (height - listEntryHeight ,
149+ height - 32 / 2 - listEntryHeight / 2 ))
150+ .size (baseListEntryWidth , listEntryHeight )
154151 .build ());
155152
156153 return optionList ;
0 commit comments