55import dsns .betterhud .util .HudLayout ;
66import dsns .betterhud .util .HudRenderer ;
77import dsns .betterhud .util .ModSettings ;
8+ import dsns .betterhud .util .Setting ;
89import it .unimi .dsi .fastutil .objects .ObjectArrayList ;
10+ import java .util .Arrays ;
911import java .util .IdentityHashMap ;
1012import java .util .List ;
1113import java .util .Map ;
@@ -32,14 +34,25 @@ public class HudEditorScreen extends Screen {
3234
3335 private static final int SNAP_DISTANCE = 5 ;
3436
37+ private static final String [] CORNER_CYCLE = {
38+ "top-left" ,
39+ "top-right" ,
40+ "bottom-right" ,
41+ "bottom-left" ,
42+ };
43+
3544 private static final int BACKDROP_COLOR = 0x50000000 ;
45+ private static final int NO_LEVEL_BACKDROP_COLOR = 0xff181818 ;
46+ private static final int BUTTON_COLOR = 0x80000000 ;
47+ private static final int BUTTON_HOVERED_COLOR = 0xa0333333 ;
3648 private static final int OUTLINE_COLOR = 0x66ffffff ;
3749 private static final int OUTLINE_HOVERED_COLOR = 0xccffffff ;
3850 private static final int OUTLINE_DRAGGED_COLOR = 0xff55ffff ;
3951 private static final int GUIDE_COLOR = 0xaa55ffff ;
4052 private static final int TEXT_COLOR = 0xffffffff ;
4153 private static final int TEXT_MUTED_COLOR = 0xffaaaaaa ;
4254
55+ private final Screen parent ;
4356 private final List <CustomText > texts = new ObjectArrayList <>();
4457 private final Map <CustomText , BaseMod > owners = new IdentityHashMap <>();
4558 private List <HudLayout .Placed > placedElements = new ObjectArrayList <>();
@@ -50,8 +63,18 @@ public class HudEditorScreen extends Screen {
5063 private boolean snappedCenterX = false ;
5164 private boolean snappedCenterY = false ;
5265
66+ private int settingsButtonX = 0 ;
67+ private int settingsButtonY = 0 ;
68+ private int settingsButtonWidth = 0 ;
69+ private int settingsButtonHeight = 0 ;
70+
5371 public HudEditorScreen () {
72+ this (null );
73+ }
74+
75+ public HudEditorScreen (Screen parent ) {
5476 super (Component .translatable ("betterhud.editor.title" ));
77+ this .parent = parent ;
5578 }
5679
5780 @ Override
@@ -115,16 +138,51 @@ private HudLayout.Placed elementAt(double mouseX, double mouseY) {
115138 return null ;
116139 }
117140
141+ private boolean overSettingsButton (double mouseX , double mouseY ) {
142+ return (
143+ settingsButtonWidth > 0 &&
144+ mouseX >= settingsButtonX &&
145+ mouseX < settingsButtonX + settingsButtonWidth &&
146+ mouseY >= settingsButtonY &&
147+ mouseY < settingsButtonY + settingsButtonHeight
148+ );
149+ }
150+
118151 private boolean handleMouseDown (double mouseX , double mouseY , int button ) {
152+ if (button == 0 && overSettingsButton (mouseX , mouseY )) {
153+ Screen settings = ModMenu .createSettingsScreen (this );
154+ if (settings != null ) {
155+ Minecraft client = Minecraft .getInstance ();
156+ //? if >=26.2 {
157+ client .gui .setScreen (settings );
158+ //?} else {
159+ /*client.setScreen(settings);*/
160+ //?}
161+ }
162+ return true ;
163+ }
164+
119165 HudLayout .Placed placed = elementAt (mouseX , mouseY );
120166 if (placed == null ) return false ;
121167
122168 BaseMod mod = owners .get (placed .text );
123169
124170 if (button == 1 ) {
125- // Right click: give up the custom position and rejoin the corner
126- // stack selected by the Orientation setting.
127- mod .getModSettings ().getSetting ("Custom Position" ).setValue ("false" );
171+ // Right click: dock the element. A custom-positioned element goes
172+ // back to its corner stack; a docked one cycles to the next corner.
173+ ModSettings settings = mod .getModSettings ();
174+ Setting customPosition = settings .getSetting ("Custom Position" );
175+ if (customPosition .getBooleanValue ()) {
176+ customPosition .setValue ("false" );
177+ } else {
178+ Setting orientation = settings .getSetting ("Orientation" );
179+ int index = Arrays .asList (CORNER_CYCLE ).indexOf (
180+ orientation .getStringValue ()
181+ );
182+ orientation .setValue (
183+ CORNER_CYCLE [(index + 1 ) % CORNER_CYCLE .length ]
184+ );
185+ }
128186 return true ;
129187 }
130188
@@ -295,7 +353,15 @@ private void renderEditor(
295353 ) {
296354 Minecraft client = Minecraft .getInstance ();
297355
298- drawContext .fill (0 , 0 , this .width , this .height , BACKDROP_COLOR );
356+ // Opened from Mod Menu there may be no world behind the screen; use a
357+ // solid backdrop instead of a translucent one.
358+ drawContext .fill (
359+ 0 ,
360+ 0 ,
361+ this .width ,
362+ this .height ,
363+ client .level == null ? NO_LEVEL_BACKDROP_COLOR : BACKDROP_COLOR
364+ );
299365
300366 for (CustomText text : texts ) {
301367 text .applyPlacement (owners .get (text ).getModSettings ());
@@ -345,6 +411,8 @@ private void renderEditor(
345411 String heading = I18n .get ("betterhud.editor.title" );
346412 drawCenteredText (drawContext , client , heading , 8 , TEXT_COLOR );
347413
414+ drawSettingsButton (drawContext , client , mouseX , mouseY );
415+
348416 // The hints live at the bottom center, clear of the corner stacks.
349417 HudLayout .Placed described = draggedMod != null
350418 ? placedFor (draggedMod )
@@ -377,6 +445,52 @@ private void renderEditor(
377445 }
378446 }
379447
448+ private void drawSettingsButton (
449+ //? if >=26 {
450+ GuiGraphicsExtractor drawContext ,
451+ //?} else {
452+ /*GuiGraphics drawContext,*/
453+ //?}
454+ Minecraft client ,
455+ int mouseX ,
456+ int mouseY
457+ ) {
458+ if (!ModMenu .settingsScreenAvailable ()) {
459+ settingsButtonWidth = 0 ;
460+ return ;
461+ }
462+
463+ String label = I18n .get ("betterhud.editor.settings" );
464+ settingsButtonWidth = client .font .width (label ) + 12 ;
465+ settingsButtonHeight = 14 ;
466+ settingsButtonX = (this .width - settingsButtonWidth ) / 2 ;
467+ settingsButtonY = 20 ;
468+
469+ boolean hovered = overSettingsButton (mouseX , mouseY );
470+ drawContext .fill (
471+ settingsButtonX ,
472+ settingsButtonY ,
473+ settingsButtonX + settingsButtonWidth ,
474+ settingsButtonY + settingsButtonHeight ,
475+ hovered ? BUTTON_HOVERED_COLOR : BUTTON_COLOR
476+ );
477+ drawOutline (
478+ drawContext ,
479+ settingsButtonX ,
480+ settingsButtonY ,
481+ settingsButtonWidth ,
482+ settingsButtonHeight ,
483+ hovered ? OUTLINE_HOVERED_COLOR : OUTLINE_COLOR
484+ );
485+ drawCenteredText (
486+ drawContext ,
487+ client ,
488+ label ,
489+ settingsButtonY + 3 ,
490+ hovered ? TEXT_COLOR : TEXT_MUTED_COLOR
491+ );
492+ }
493+
380494 private void drawCenteredText (
381495 //? if >=26 {
382496 GuiGraphicsExtractor drawContext ,
@@ -419,6 +533,16 @@ public boolean isPauseScreen() {
419533 return false ;
420534 }
421535
536+ @ Override
537+ public void onClose () {
538+ Minecraft client = Minecraft .getInstance ();
539+ //? if >=26.2 {
540+ client .gui .setScreen (parent );
541+ //?} else {
542+ /*client.setScreen(parent);*/
543+ //?}
544+ }
545+
422546 @ Override
423547 public void removed () {
424548 Config .serialize ();
0 commit comments