diff options
| author | Kevin <92656833+kevinthegreat1@users.noreply.github.com> | 2025-07-27 03:07:27 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-26 15:07:27 -0400 |
| commit | 1bf4c6535be4f38895ee10a0b62e9d7c7eaf9138 (patch) | |
| tree | 540e491bcc7224f5cd10a06542757d90583af5dd /src/main/java/de | |
| parent | 75706bd04c8cb1f1cc6126f4348351d9fe34bfc2 (diff) | |
| download | Skyblocker-1bf4c6535be4f38895ee10a0b62e9d7c7eaf9138.tar.gz Skyblocker-1bf4c6535be4f38895ee10a0b62e9d7c7eaf9138.tar.bz2 Skyblocker-1bf4c6535be4f38895ee10a0b62e9d7c7eaf9138.zip | |
Title HUD default to center (#1538)
Diffstat (limited to 'src/main/java/de')
4 files changed, 23 insertions, 10 deletions
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. * <p> - * 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<AbstractWidget> 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<AbstractWidget> widgets) { - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x = widgets.getFirst().getX(); - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y = widgets.getFirst().getY(); + protected void savePos(SkyblockerConfig config, List<AbstractWidget> widgets) { + // Save to -1 if the widget is at the default position + List<IntIntMutablePair> 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; } } |
