diff --git a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java index ac1d89666b..8e5383203b 100644 --- a/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java +++ b/src/main/java/de/hysky/skyblocker/config/HudConfigScreen.java @@ -18,8 +18,8 @@ * (i.e. one for dwarven mines, one for the end, etc.) See an implementation for an example. */ public abstract class HudConfigScreen extends Screen { - private final Screen parent; - private final List widgets; + protected final Screen parent; + protected final List widgets; private HudWidget draggingWidget; private double mouseClickRelativeX; @@ -51,7 +51,7 @@ public HudConfigScreen(Text title, Screen parent, List widgets) { @Override public final void render(DrawContext context, int mouseX, int mouseY, float delta) { super.render(context, mouseX, mouseY, delta); - renderWidget(context, widgets); + renderWidget(context, widgets, delta); context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, height / 2, Color.GRAY.getRGB()); } @@ -60,7 +60,7 @@ public final void render(DrawContext context, int mouseX, int mouseY, float delt * @param context the context to render in * @param widgets the widgets to render */ - protected void renderWidget(DrawContext context, List widgets) { + protected void renderWidget(DrawContext context, List widgets, float delta) { for (HudWidget widget : widgets) { widget.render(context); } @@ -69,7 +69,7 @@ protected void renderWidget(DrawContext context, List widgets) { @Override public final boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { if (button == 0 && draggingWidget != null) { - draggingWidget.setX((int) Math.clamp(mouseX - mouseClickRelativeX, 0, this.width - draggingWidget.getWidth())); + draggingWidget.setX((int) Math.clamp(mouseX - mouseClickRelativeX, 0, this.width - draggingWidget.getWidth()) - getWidgetXOffset(draggingWidget)); draggingWidget.setY((int) Math.clamp(mouseY - mouseClickRelativeY, 0, this.height - draggingWidget.getHeight())); } return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); @@ -79,9 +79,9 @@ public final boolean mouseDragged(double mouseX, double mouseY, int button, doub public final boolean mouseClicked(double mouseX, double mouseY, int button) { if (button == 0) { for (HudWidget widget : widgets) { - if (RenderHelper.pointIsInArea(mouseX, mouseY, widget.getX(), widget.getY(), widget.getX() + widget.getWidth(), widget.getY() + widget.getHeight())) { + if (RenderHelper.pointIsInArea(mouseX, mouseY, widget.getX() + getWidgetXOffset(widget), widget.getY(), widget.getX() + getWidgetXOffset(widget) + widget.getWidth(), widget.getY() + widget.getHeight())) { draggingWidget = widget; - mouseClickRelativeX = mouseX - widget.getX(); + mouseClickRelativeX = mouseX - widget.getX() - getWidgetXOffset(widget); mouseClickRelativeY = mouseY - widget.getY(); break; } @@ -98,6 +98,10 @@ public final boolean mouseReleased(double mouseX, double mouseY, int button) { return super.mouseReleased(mouseX, mouseY, button); } + protected int getWidgetXOffset(HudWidget widget) { + return 0; + } + /** * Resets the positions of the widgets to the positions in the config. Override to change the behavior. */ 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 510c023269..594336e541 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/UIAndVisualsConfig.java @@ -94,10 +94,14 @@ public static class TitleContainer { public int y = 10; @SerialEntry - public Direction direction = Direction.HORIZONTAL; + public Direction direction = Direction.VERTICAL; @SerialEntry public Alignment alignment = Alignment.MIDDLE; + + public float getRenderScale() { + return titleContainerScale * 0.03f; + } } public enum Direction { @@ -113,7 +117,7 @@ public String toString() { } public enum Alignment { - LEFT, RIGHT, MIDDLE; + LEFT, MIDDLE, RIGHT; @Override public String toString() { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java new file mode 100644 index 0000000000..7e98668935 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/tabhud/widget/EmptyWidget.java @@ -0,0 +1,21 @@ +package de.hysky.skyblocker.skyblock.tabhud.widget; + +import de.hysky.skyblocker.utils.Location; +import net.minecraft.client.gui.DrawContext; + +public class EmptyWidget extends HudWidget { + public EmptyWidget() { + super(""); + } + + @Override + public boolean shouldRender(Location location) { + return false; + } + + @Override + public void update() {} + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float delta) {} +} \ No newline at end of file diff --git a/src/main/java/de/hysky/skyblocker/utils/render/title/Title.java b/src/main/java/de/hysky/skyblocker/utils/render/title/Title.java index 890976aea4..fbeadf4eca 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/title/Title.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/title/Title.java @@ -1,5 +1,6 @@ package de.hysky.skyblocker.utils.render.title; +import com.demonwav.mcdev.annotations.Translatable; import net.minecraft.text.MutableText; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -20,7 +21,7 @@ public class Title { * @param textKey the translation key * @param formatting the formatting to be applied to the text */ - public Title(String textKey, Formatting formatting) { + public Title(@Translatable String textKey, Formatting formatting) { this(Text.translatable(textKey).formatted(formatting)); } 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 cb754308ae..8d583492e2 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 @@ -87,64 +87,46 @@ private static void render(DrawContext context, RenderTickCounter tickCounter) { } protected static void render(DrawContext context, Set titles, int xPos, int yPos, float tickDelta) { - var client = MinecraftClient.getInstance(); - TextRenderer textRenderer = client.textRenderer; + TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer; // Calculate Scale to use - float scale = 3F * (SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale / 100F); - + float scale = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.getRenderScale(); // Grab direction and alignment values UIAndVisualsConfig.Direction direction = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction; UIAndVisualsConfig.Alignment alignment = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; + // x/y refer to the starting position for the text + // If left or right aligned or middle aligned vertically, start at xPos, we will shift each text later + float x = xPos; // y always starts at yPos - float x = 0; float y = yPos; - //Calculate the width of combined text - float width = 0; - for (Title title : titles) { - width += textRenderer.getWidth(title.getText()) * scale + 10; - } - - if (alignment == UIAndVisualsConfig.Alignment.MIDDLE) { - if (direction == UIAndVisualsConfig.Direction.HORIZONTAL) { - //If middle aligned horizontally, start the xPosition at half of the width to the left. - x = xPos - (width / 2); - } else { - //If middle aligned vertically, start at xPos, we will shift each text to the left later - x = xPos; - } - } - if (alignment == UIAndVisualsConfig.Alignment.LEFT || alignment == UIAndVisualsConfig.Alignment.RIGHT) { - //If left or right aligned, start at xPos, we will shift each text later - x = xPos; + // Calculate the width of combined text + float totalWidth = getWidth(textRenderer, titles); + if (alignment == UIAndVisualsConfig.Alignment.MIDDLE && direction == UIAndVisualsConfig.Direction.HORIZONTAL) { + // If middle aligned horizontally, start the xPosition at half of the width to the left. + x = xPos - totalWidth / 2; } for (Title title : titles) { - //Calculate which x the text should use - float xToUse; - if (direction == UIAndVisualsConfig.Direction.HORIZONTAL) { - xToUse = alignment == UIAndVisualsConfig.Alignment.RIGHT ? - x - (textRenderer.getWidth(title.getText()) * scale) : //if right aligned we need the text position to be aligned on the right side. - x; - } else { - xToUse = alignment == UIAndVisualsConfig.Alignment.MIDDLE ? - x - (textRenderer.getWidth(title.getText()) * scale) / 2 : //if middle aligned we need the text position to be aligned in the middle. - alignment == UIAndVisualsConfig.Alignment.RIGHT ? - x - (textRenderer.getWidth(title.getText()) * scale) : //if right aligned we need the text position to be aligned on the right side. - x; + float xTextLeft = x; + if (alignment == UIAndVisualsConfig.Alignment.RIGHT) { + //if right aligned we need the text position to be aligned on the right side. + xTextLeft = x - textRenderer.getWidth(title.getText()) * scale; + } else if (direction == UIAndVisualsConfig.Direction.VERTICAL && alignment == UIAndVisualsConfig.Alignment.MIDDLE) { + //if middle aligned we need the text position to be aligned in the middle. + xTextLeft = x - (textRenderer.getWidth(title.getText()) * scale) / 2; } //Start displaying the title at the correct position, not at the default position if (title.isDefaultPos()) { - title.x = xToUse; + title.x = xTextLeft; title.y = y; } //Lerp the texts x and y variables - title.x = MathHelper.lerp(tickDelta * 0.5F, title.x, xToUse); + title.x = MathHelper.lerp(tickDelta * 0.5F, title.x, xTextLeft); title.y = MathHelper.lerp(tickDelta * 0.5F, title.y, y); //Translate the matrix to the texts position and scale @@ -160,17 +142,29 @@ protected static void render(DrawContext context, Set<Title> titles, int xPos, i if (direction == UIAndVisualsConfig.Direction.HORIZONTAL) { if (alignment == UIAndVisualsConfig.Alignment.MIDDLE || alignment == UIAndVisualsConfig.Alignment.LEFT) { //Move to the right if middle or left aligned - x += textRenderer.getWidth(title.getText()) * scale + 10; - } - - if (alignment == UIAndVisualsConfig.Alignment.RIGHT) { + x += (textRenderer.getWidth(title.getText()) + 10) * scale; + } else if (alignment == UIAndVisualsConfig.Alignment.RIGHT) { //Move to the left if right aligned - x -= textRenderer.getWidth(title.getText()) * scale + 10; + x -= (textRenderer.getWidth(title.getText()) + 10) * scale; } } else { //Y always moves by the same amount if vertical - y += textRenderer.fontHeight * scale + 10; + y += (textRenderer.fontHeight + 1) * scale; } } } -} \ No newline at end of file + + protected static int getWidth(TextRenderer textRenderer, Set<Title> titles) { + float scale = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.getRenderScale(); + return SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction == UIAndVisualsConfig.Direction.HORIZONTAL ? + (int) ((titles.stream().map(Title::getText).mapToInt(textRenderer::getWidth).mapToDouble(width -> width + 10).sum() - 10) * scale) : + (int) (titles.stream().map(Title::getText).mapToInt(textRenderer::getWidth).max().orElse(0) * scale); + } + + protected static int getHeight(TextRenderer textRenderer, Set<Title> titles) { + float scale = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.getRenderScale(); + return SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction == UIAndVisualsConfig.Direction.HORIZONTAL ? + (int) (textRenderer.fontHeight * scale) : + (int) ((textRenderer.fontHeight + 1) * titles.size() * scale); + } +} 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 a8fbbea87c..18b3b1ab57 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 @@ -1,47 +1,58 @@ package de.hysky.skyblocker.utils.render.title; +import com.google.common.collect.ImmutableSet; +import de.hysky.skyblocker.config.HudConfigScreen; +import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.config.configs.UIAndVisualsConfig; -import de.hysky.skyblocker.utils.render.RenderHelper; +import de.hysky.skyblocker.skyblock.tabhud.widget.EmptyWidget; +import de.hysky.skyblocker.skyblock.tabhud.widget.HudWidget; import dev.isxander.yacl3.api.ConfigCategory; -import dev.isxander.yacl3.api.Option; import dev.isxander.yacl3.api.OptionGroup; import dev.isxander.yacl3.gui.YACLScreen; +import it.unimi.dsi.fastutil.ints.IntIntMutablePair; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.util.math.Vector2f; import net.minecraft.text.Text; +import net.minecraft.text.TranslatableTextContent; import net.minecraft.util.Formatting; -import net.minecraft.util.Pair; import org.lwjgl.glfw.GLFW; import java.awt.*; +import java.util.List; import java.util.Set; -public class TitleContainerConfigScreen extends Screen { - private final Title example1 = new Title(Text.literal("Test1").formatted(Formatting.RED)); - private final Title example2 = new Title(Text.literal("Test23").formatted(Formatting.AQUA)); - private final Title example3 = new Title(Text.literal("Testing1234").formatted(Formatting.DARK_GREEN)); - private float hudX = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x; - private float hudY = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y; - private final Screen parent; +public class TitleContainerConfigScreen extends HudConfigScreen { + // ImmutableSet preserves insertion order + private static final Set<Title> EXAMPLES = ImmutableSet.of( + new Title(Text.literal("Test1").formatted(Formatting.RED)), + new Title(Text.literal("Test23").formatted(Formatting.AQUA)), + new Title(Text.literal("Testing1234").formatted(Formatting.DARK_GREEN)) + ); private boolean changedScale; protected TitleContainerConfigScreen() { - this(null); + this(null); } public TitleContainerConfigScreen(Screen parent) { - super(Text.of("Title Container HUD Config")); - this.parent = parent; + super(Text.of("Title Container HUD Config"), parent, new EmptyWidget()); } @Override - public void render(DrawContext context, int mouseX, int mouseY, float delta) { - super.render(context, mouseX, mouseY, delta); - renderBackground(context, mouseX, mouseY, delta); - TitleContainer.render(context, Set.of(example1, example2, example3), (int) hudX, (int) hudY, delta); + 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); + // Set the dimensions here or else Screen#textRenderer is null. + updateWidgetDimensions(); + } + + @Override + protected void renderWidget(DrawContext context, List<HudWidget> widgets, float delta) { + super.renderWidget(context, widgets, delta); + TitleContainer.render(context, EXAMPLES, widgets.getFirst().getX(), widgets.getFirst().getY(), delta); UIAndVisualsConfig.Direction direction = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction; UIAndVisualsConfig.Alignment alignment = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; context.drawCenteredTextWithShadow(textRenderer, "Press Q/E to change Alignment: " + alignment, width / 2, textRenderer.fontHeight * 2, Color.WHITE.getRGB()); @@ -49,11 +60,15 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { context.drawCenteredTextWithShadow(textRenderer, "Press +/- to change Scale", width / 2, textRenderer.fontHeight * 4 + 10, Color.WHITE.getRGB()); context.drawCenteredTextWithShadow(textRenderer, "Right Click To Reset Position", width / 2, textRenderer.fontHeight * 5 + 15, Color.GRAY.getRGB()); - Pair<Vector2f, Vector2f> boundingBox = getSelectionBoundingBox(); - int x1 = (int) boundingBox.getLeft().getX(); - int y1 = (int) boundingBox.getLeft().getY(); - int x2 = (int) boundingBox.getRight().getX(); - int y2 = (int) boundingBox.getRight().getY(); + int selectionWidth = getSelectionWidth(); + int x1 = switch (alignment) { + case LEFT -> widgets.getFirst().getX(); + case MIDDLE -> widgets.getFirst().getX() - selectionWidth / 2; + case RIGHT -> widgets.getFirst().getX() - selectionWidth; + }; + int y1 = widgets.getFirst().getY(); + int x2 = x1 + selectionWidth; + int y2 = y1 + getSelectionHeight(); context.drawHorizontalLine(x1, x2, y1, Color.RED.getRGB()); context.drawHorizontalLine(x1, x2, y2, Color.RED.getRGB()); @@ -61,131 +76,78 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { context.drawVerticalLine(x2, y1, y2, Color.RED.getRGB()); } - private Pair<Vector2f, Vector2f> getSelectionBoundingBox() { - UIAndVisualsConfig.Alignment alignment = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; - - float midWidth = getSelectionWidth() / 2F; - float x1 = 0; - float x2 = 0; - float y1 = hudY; - float y2 = hudY + getSelectionHeight(); - switch (alignment) { - case RIGHT -> { - x1 = hudX - midWidth * 2; - x2 = hudX; - } - case MIDDLE -> { - x1 = hudX - midWidth; - x2 = hudX + midWidth; - } - case LEFT -> { - x1 = hudX; - x2 = hudX + midWidth * 2; - } - } - return new Pair<>(new Vector2f(x1, y1), new Vector2f(x2, y2)); + private void updateWidgetDimensions() { + widgets.getFirst().setDimensions(getSelectionWidth(), getSelectionHeight()); } - private float getSelectionHeight() { - float scale = (3F * (SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale / 100F)); - return SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction == UIAndVisualsConfig.Direction.HORIZONTAL ? - (textRenderer.fontHeight * scale) : - (textRenderer.fontHeight + 10F) * 3F * scale; + private int getSelectionWidth() { + return TitleContainer.getWidth(textRenderer, EXAMPLES); } - private float getSelectionWidth() { - float scale = (3F * (SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale / 100F)); - return SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction == UIAndVisualsConfig.Direction.HORIZONTAL ? - (textRenderer.getWidth("Test1") + 10 + textRenderer.getWidth("Test23") + 10 + textRenderer.getWidth("Testing1234")) * scale : - textRenderer.getWidth("Testing1234") * scale; + private int getSelectionHeight() { + return TitleContainer.getHeight(textRenderer, EXAMPLES); } @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - float midWidth = getSelectionWidth() / 2; - float midHeight = getSelectionHeight() / 2; - var alignment = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; - - Pair<Vector2f, Vector2f> boundingBox = getSelectionBoundingBox(); - float x1 = boundingBox.getLeft().getX(); - float y1 = boundingBox.getLeft().getY(); - float x2 = boundingBox.getRight().getX(); - float y2 = boundingBox.getRight().getY(); - - if (RenderHelper.pointIsInArea(mouseX, mouseY, x1, y1, x2, y2) && button == 0) { - hudX = switch (alignment) { - case LEFT -> (int) mouseX - midWidth; - case MIDDLE -> (int) mouseX; - case RIGHT -> (int) mouseX + midWidth; - }; - hudY = (int) (mouseY - midHeight); + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + switch (keyCode) { + case GLFW.GLFW_KEY_Q -> SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment = cycle(SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment); + case GLFW.GLFW_KEY_E -> SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment = cycleBackwards(SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment); + case GLFW.GLFW_KEY_R -> { + SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction = cycle(SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction); + updateWidgetDimensions(); + } + case GLFW.GLFW_KEY_EQUAL -> { + SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale += 10; + updateWidgetDimensions(); + changedScale = true; + } + case GLFW.GLFW_KEY_MINUS -> { + SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale -= 10; + updateWidgetDimensions(); + changedScale = true; + } } - return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + return super.keyPressed(keyCode, scanCode, modifiers); } - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (button == 1) { - hudX = (float) this.width / 2; - hudY = this.height * 0.6F; - } - return super.mouseClicked(mouseX, mouseY, button); + private <T extends Enum<T>> T cycle(T current) { + T[] values = current.getDeclaringClass().getEnumConstants(); + return values[(current.ordinal() + 1) % values.length]; + } + + private <T extends Enum<T>> T cycleBackwards(T current) { + T[] values = current.getDeclaringClass().getEnumConstants(); + return values[(current.ordinal() - 1 + values.length) % values.length]; } @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (keyCode == GLFW.GLFW_KEY_Q) { - UIAndVisualsConfig.Alignment current = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment = switch (current) { - case LEFT -> UIAndVisualsConfig.Alignment.MIDDLE; - case MIDDLE -> UIAndVisualsConfig.Alignment.RIGHT; - case RIGHT -> UIAndVisualsConfig.Alignment.LEFT; - }; - } - if (keyCode == GLFW.GLFW_KEY_E) { - UIAndVisualsConfig.Alignment current = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment; - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment = switch (current) { - case LEFT -> UIAndVisualsConfig.Alignment.RIGHT; - case MIDDLE -> UIAndVisualsConfig.Alignment.LEFT; - case RIGHT -> UIAndVisualsConfig.Alignment.MIDDLE; - }; - } - if (keyCode == GLFW.GLFW_KEY_R) { - UIAndVisualsConfig.Direction current = SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction; - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.direction = switch (current) { - case HORIZONTAL -> UIAndVisualsConfig.Direction.VERTICAL; - case VERTICAL -> UIAndVisualsConfig.Direction.HORIZONTAL; - }; - } - if (keyCode == GLFW.GLFW_KEY_EQUAL) { - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale += 10; - changedScale = true; - } - if (keyCode == GLFW.GLFW_KEY_MINUS) { - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.titleContainerScale -= 10; - changedScale = true; - } - return super.keyPressed(keyCode, scanCode, modifiers); + protected int getWidgetXOffset(HudWidget widget) { + return switch (SkyblockerConfigManager.get().uiAndVisuals.titleContainer.alignment) { + case LEFT -> 0; + case MIDDLE -> - getSelectionWidth() / 2; + case RIGHT -> - getSelectionWidth(); + }; } + @Override + protected List<IntIntMutablePair> getConfigPos(SkyblockerConfig config) { + // This gets the reset pos. The actual config pos is loaded in #init. + return List.of(IntIntMutablePair.of(this.width / 2, (int) (this.height * 0.6))); + } @Override - public void close() { - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x = (int) hudX; - SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y = (int) hudY; + protected void savePos(SkyblockerConfig configManager, List<HudWidget> widgets) { + SkyblockerConfigManager.get().uiAndVisuals.titleContainer.x = widgets.getFirst().getX(); + SkyblockerConfigManager.get().uiAndVisuals.titleContainer.y = widgets.getFirst().getY(); //TODO Come up with a better, less hacky solution for this in the future (: - if (parent instanceof YACLScreen yaclScreen) { - ConfigCategory category = yaclScreen.config.categories().stream().filter(cat -> cat.name().getString().equals(I18n.translate("skyblocker.config.uiAndVisuals"))).findFirst().orElseThrow(); + if (changedScale && parent instanceof YACLScreen yaclScreen) { + ConfigCategory category = yaclScreen.config.categories().stream().filter(cat -> ((TranslatableTextContent) cat.name().getContent()).getKey().equals("skyblocker.config.uiAndVisuals")).findFirst().orElseThrow(); OptionGroup group = category.groups().stream().filter(grp -> grp.name().getString().equals(I18n.translate("skyblocker.config.uiAndVisuals.titleContainer"))).findFirst().orElseThrow(); - Option<?> scaleOpt = group.options().getFirst(); - // Refresh the value in the config with the bound value - if (changedScale) scaleOpt.forgetPendingValue(); + group.options().getFirst().forgetPendingValue(); } - - SkyblockerConfigManager.save(); - this.client.setScreen(parent); } }