From 1bf4c6535be4f38895ee10a0b62e9d7c7eaf9138 Mon Sep 17 00:00:00 2001 From: Kevin <92656833+kevinthegreat1@users.noreply.github.com> Date: Sun, 27 Jul 2025 03:07:27 +0800 Subject: Title HUD default to center (#1538) --- .../java/de/hysky/skyblocker/config/HudConfigScreen.java | 9 ++++++++- .../skyblocker/config/configs/UIAndVisualsConfig.java | 4 ++-- .../skyblocker/utils/render/title/TitleContainer.java | 5 +++-- .../utils/render/title/TitleContainerConfigScreen.java | 15 ++++++++++----- 4 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java index 82ac889e..9c725fa7 100644 --- a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java @@ -49,6 +49,12 @@ public abstract class HudConfigScreen extends Screen { super(title); this.parent = parent; this.widgets = widgets; + } + + @Override + protected void init() { + super.init(); + // Reset positions here, so width and height are available. resetPos(); } @@ -140,10 +146,11 @@ public abstract class HudConfigScreen extends Screen { /** * Saves the passed positions to the config. *

- * NOTE: The parent class will call {@link SkyblockerConfigManager#save()} right after this method + * NOTE: The config manager will save the config right after this method is called. * * @param configManager the config so you don't have to get it * @param widgets the widgets to save + * @see SkyblockerConfigManager#update(java.util.function.Consumer) */ protected abstract void savePos(SkyblockerConfig configManager, List widgets); } diff --git a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java index 620354cf..d0592437 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -124,9 +124,9 @@ public class UIAndVisualsConfig { public static class TitleContainer { public float titleContainerScale = 100; - public int x = 540; + public int x = -1; - public int y = 10; + public int y = -1; public Direction direction = Direction.VERTICAL; diff --git a/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java b/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java index 03ca5acd..465f9899 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainer.java @@ -142,10 +142,11 @@ public class TitleContainer { UIAndVisualsConfig.Alignment alignment = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; // x/y refer to the starting position for the text + // If xPos or yPos is negative, use the default values // If left or right aligned or middle aligned vertically, start at xPos, we will shift each text later - float x = xPos; + float x = xPos >= 0 ? xPos : MinecraftClient.getInstance().getWindow().getScaledWidth() / 2f; // y always starts at yPos - float y = yPos; + float y = yPos >= 0 ? yPos : MinecraftClient.getInstance().getWindow().getScaledHeight() * 0.6f; // Calculate the width of combined text float totalWidth = getWidth(textRenderer, titles); diff --git a/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainerConfigScreen.java b/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainerConfigScreen.java index 4a72f55a..99547219 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainerConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/title/TitleContainerConfigScreen.java @@ -38,8 +38,11 @@ public class TitleContainerConfigScreen extends HudConfigScreen { @Override protected void init() { super.init(); - // Load the config positions here since #getConfigPos is used for resetting. This loads the config pos after the supertype constructor calls HudConfigScreen#resetPos. - widgets.getFirst().setPosition(SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x, SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y); + // Only load config positions if they are not default + if (SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x >= 0 && SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y >= 0) { + // Load the config positions here since #getConfigPos is used for resetting. This loads the config pos after HudConfigScreen#init calls HudConfigScreen#resetPos. + widgets.getFirst().setPosition(SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x, SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y); + } // Set the dimensions here or else Screen#textRenderer is null. updateWidgetDimensions(); } @@ -120,8 +123,10 @@ public class TitleContainerConfigScreen extends HudConfigScreen { } @Override - protected void savePos(SkyblockerConfig configManager, List widgets) { - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x = widgets.getFirst().getX(); - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y = widgets.getFirst().getY(); + protected void savePos(SkyblockerConfig config, List widgets) { + // Save to -1 if the widget is at the default position + List defaultPos = getConfigPos(config); + config.uiAndVisuals.titleContainer.x = widgets.getFirst().getX() != defaultPos.getFirst().leftInt() ? widgets.getFirst().getX() : -1; + config.uiAndVisuals.titleContainer.y = widgets.getFirst().getY() != defaultPos.getFirst().rightInt() ? widgets.getFirst().getY() : -1; } } -- cgit