Skip to content

Commit 0af03b6

Browse files
committed
Replace the placement settings UI with the HUD editor
The Orientation / Custom Position / Custom X / Custom Y entries are gone from the settings screen; placement is edited only by dragging (their config keys remain as the persistence format). Mod Menu's configure button now opens the HUD editor directly, which gains a Settings button for the remaining Cloth Config options (toggles, colors, scale) and returns to its parent screen on close. Right-clicking an element docks it back into a corner, and right-clicking a docked element cycles it through the corners, replacing the orientation dropdown. The gametests now also cover right-click docking. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016M8Paub79s9he93GZUGemX
1 parent 32e3381 commit 0af03b6

8 files changed

Lines changed: 288 additions & 107 deletions

File tree

-1.16 KB
Loading

‎.github/assets/hud-editor.png‎

-1.05 KB
Loading

‎README.md‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ Requires [Cloth Config](https://modrinth.com/mod/cloth-config), [Mod Menu](https
2020

2121
## HUD Editor
2222

23-
Press **Right Shift** in game (rebindable in Options → Controls → BetterHUD) to
24-
open the HUD editor and arrange the HUD visually instead of typing numbers:
23+
Press **Right Shift** in game (rebindable in Options → Controls → BetterHUD),
24+
or open BetterHUD from **Mod Menu**, to arrange the HUD visually instead of
25+
typing numbers:
2526

2627
- **Drag** an element to place it anywhere on the screen (it snaps to the
2728
screen edges and center lines).
2829
- **Scroll** while hovering an element to resize it.
29-
- **Right-click** an element to snap it back to its corner stack.
30+
- **Right-click** an element to dock it back into a corner; right-click a
31+
docked element to cycle it through the corners.
32+
- **Settings…** opens the settings screen (colors, toggles, scale).
3033
- **Escape** saves the layout and closes the editor.
3134

3235
## Configuration (requires Mod Menu)

‎launchtest/src/gametest-legacy/java/dsns/betterhud/gametest/BetterHudClientGameTest.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ private static void exerciseHudEditor(ClientGameTestContext context) {
7979
throw new AssertionError(
8080
"Dragging in the HUD editor did not move the FPS element: x=" + customX + "% y=" + customY + "%");
8181
}
82+
83+
// Reopen the editor and dock the element back into its corner stack
84+
// with a right click.
85+
input.pressKey(GLFW.GLFW_KEY_RIGHT_SHIFT);
86+
context.waitTicks(5);
87+
input.setCursorPos(92.0 * guiScale, 58.0 * guiScale);
88+
input.pressMouse(GLFW.GLFW_MOUSE_BUTTON_RIGHT);
89+
context.waitTicks(2);
90+
input.pressKey(GLFW.GLFW_KEY_ESCAPE);
91+
context.waitTicks(2);
92+
93+
config = loadConfig();
94+
if (!"false".equals(config.getProperty("FPS.Custom Position"))) {
95+
throw new AssertionError(
96+
"Right-clicking in the HUD editor did not dock the FPS element back: " + config);
97+
}
8298
}
8399

84100
private static Properties loadConfig() {

‎src/gametest/java/dsns/betterhud/gametest/BetterHudClientGameTest.java‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,22 @@ private static void exerciseHudEditor(ClientGameTestContext context) {
7474
throw new AssertionError(
7575
"Dragging in the HUD editor did not move the FPS element: x=" + customX + "% y=" + customY + "%");
7676
}
77+
78+
// Reopen the editor and dock the element back into its corner stack
79+
// with a right click.
80+
input.pressKey(GLFW.GLFW_KEY_RIGHT_SHIFT);
81+
context.waitTicks(5);
82+
input.setCursorPos(92.0 * guiScale, 58.0 * guiScale);
83+
input.pressMouse(GLFW.GLFW_MOUSE_BUTTON_RIGHT);
84+
context.waitTicks(2);
85+
input.pressKey(GLFW.GLFW_KEY_ESCAPE);
86+
context.waitTicks(2);
87+
88+
config = loadConfig();
89+
if (!"false".equals(config.getProperty("FPS.Custom Position"))) {
90+
throw new AssertionError(
91+
"Right-clicking in the HUD editor did not dock the FPS element back: " + config);
92+
}
7793
}
7894

7995
private static Properties loadConfig() {

‎src/main/java/dsns/betterhud/HudEditorScreen.java‎

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import dsns.betterhud.util.HudLayout;
66
import dsns.betterhud.util.HudRenderer;
77
import dsns.betterhud.util.ModSettings;
8+
import dsns.betterhud.util.Setting;
89
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
10+
import java.util.Arrays;
911
import java.util.IdentityHashMap;
1012
import java.util.List;
1113
import 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

Comments
 (0)