From 42e56b3279aa0382093841e834c44a835cb4aa18 Mon Sep 17 00:00:00 2001 From: BlayTheNinth <1933180+BlayTheNinth@users.noreply.github.com> Date: Sun, 17 Sep 2023 11:49:32 +0200 Subject: [PATCH] feat: Fix alternative button style spacing --- .../mods/craftingtweaks/api/ButtonStyle.java | 15 +++++++++++++++ .../api/CraftingTweaksButtonStyles.java | 8 ++++---- .../api/impl/DefaultGridGuiHandler.java | 12 ++++++------ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/shared/src/main/java/net/blay09/mods/craftingtweaks/api/ButtonStyle.java b/shared/src/main/java/net/blay09/mods/craftingtweaks/api/ButtonStyle.java index 691c0f5..305b9f6 100644 --- a/shared/src/main/java/net/blay09/mods/craftingtweaks/api/ButtonStyle.java +++ b/shared/src/main/java/net/blay09/mods/craftingtweaks/api/ButtonStyle.java @@ -5,6 +5,13 @@ public class ButtonStyle { private final EnumMap properties = new EnumMap<>(TweakType.class); + private final int spacingX; + private final int spacingY; + + public ButtonStyle(int spacingX, int spacingY) { + this.spacingX = spacingX; + this.spacingY = spacingY; + } public ButtonStyle withTweak(TweakType tweakType, ButtonProperties properties) { this.properties.put(tweakType, properties); @@ -14,4 +21,12 @@ public ButtonStyle withTweak(TweakType tweakType, ButtonProperties properties) { public ButtonProperties getTweak(TweakType tweakType) { return properties.get(tweakType); } + + public int getSpacingX() { + return spacingX; + } + + public int getSpacingY() { + return spacingY; + } } diff --git a/shared/src/main/java/net/blay09/mods/craftingtweaks/api/CraftingTweaksButtonStyles.java b/shared/src/main/java/net/blay09/mods/craftingtweaks/api/CraftingTweaksButtonStyles.java index de11896..3f747b1 100644 --- a/shared/src/main/java/net/blay09/mods/craftingtweaks/api/CraftingTweaksButtonStyles.java +++ b/shared/src/main/java/net/blay09/mods/craftingtweaks/api/CraftingTweaksButtonStyles.java @@ -1,7 +1,7 @@ package net.blay09.mods.craftingtweaks.api; public class CraftingTweaksButtonStyles { - public static final ButtonStyle DEFAULT = new ButtonStyle() + public static final ButtonStyle DEFAULT = new ButtonStyle(18, 18) .withTweak(TweakType.Rotate, new ButtonProperties(16, 16) .withState(ButtonState.NORMAL, 16, 0) .withState(ButtonState.HOVER, 16, 16) @@ -27,7 +27,7 @@ public class CraftingTweaksButtonStyles { .withState(ButtonState.HOVER, 96, 16) .withState(ButtonState.DISABLED, 96, 32)); - public static final ButtonStyle SMALL_HEIGHT = new ButtonStyle() + public static final ButtonStyle SMALL_HEIGHT = new ButtonStyle(18, 12) .withTweak(TweakType.Rotate, new ButtonProperties(16, 10) .withState(ButtonState.NORMAL, 16, 48) .withState(ButtonState.HOVER, 16, 58) @@ -53,7 +53,7 @@ public class CraftingTweaksButtonStyles { .withState(ButtonState.HOVER, 96, 58) .withState(ButtonState.DISABLED, 96, 68)); - public static final ButtonStyle SMALL_WIDTH = new ButtonStyle() + public static final ButtonStyle SMALL_WIDTH = new ButtonStyle(12, 18) .withTweak(TweakType.Rotate, new ButtonProperties(10, 16) .withState(ButtonState.NORMAL, 10, 78) .withState(ButtonState.HOVER, 10, 94) @@ -79,7 +79,7 @@ public class CraftingTweaksButtonStyles { .withState(ButtonState.HOVER, 60, 94) .withState(ButtonState.DISABLED, 60, 158110)); - public static final ButtonStyle SMALL = new ButtonStyle() + public static final ButtonStyle SMALL = new ButtonStyle(12, 12) .withTweak(TweakType.Rotate, new ButtonProperties(10, 10) .withState(ButtonState.NORMAL, 10, 126) .withState(ButtonState.HOVER, 10, 136) diff --git a/shared/src/main/java/net/blay09/mods/craftingtweaks/api/impl/DefaultGridGuiHandler.java b/shared/src/main/java/net/blay09/mods/craftingtweaks/api/impl/DefaultGridGuiHandler.java index 577fdf0..6ea6fd7 100644 --- a/shared/src/main/java/net/blay09/mods/craftingtweaks/api/impl/DefaultGridGuiHandler.java +++ b/shared/src/main/java/net/blay09/mods/craftingtweaks/api/impl/DefaultGridGuiHandler.java @@ -32,7 +32,7 @@ public void createButtons(AbstractContainerScreen screen, CraftingGrid grid, private boolean createTweakButton(AbstractContainerScreen screen, CraftingGrid grid, Consumer addWidgetFunc, GridGuiSettings guiSettings, int index, TweakType tweak) { if (guiSettings.isButtonVisible(tweak)) { - ButtonPosition buttonPos = guiSettings.getButtonPosition(tweak).orElseGet(() -> getAlignedPosition(screen.getMenu(), grid, guiSettings.getButtonAlignment(), index)); + ButtonPosition buttonPos = guiSettings.getButtonPosition(tweak).orElseGet(() -> getAlignedPosition(screen.getMenu(), grid, guiSettings.getButtonAlignment(), guiSettings.getButtonStyle(), index)); addWidgetFunc.accept(CraftingTweaksClientAPI.createTweakButtonRelative(grid, screen, buttonPos.getX(), buttonPos.getY(), tweak, guiSettings.getButtonStyle())); return true; } @@ -40,14 +40,14 @@ private boolean createTweakButton(AbstractContainerScreen screen, CraftingGri return false; } - private ButtonPosition getAlignedPosition(AbstractContainerMenu menu, CraftingGrid grid, ButtonAlignment alignment, int index) { + private ButtonPosition getAlignedPosition(AbstractContainerMenu menu, CraftingGrid grid, ButtonAlignment alignment, ButtonStyle style, int index) { Player player = Minecraft.getInstance().player; Slot firstSlot = menu.slots.get(grid.getGridStartSlot(player, menu)); return switch (alignment) { - case TOP -> new ButtonPosition(firstSlot.x + 18 * index, firstSlot.y - 18 - 1); - case BOTTOM -> new ButtonPosition(firstSlot.x + 18 * index, firstSlot.y + 18 * 3 + 1); - case RIGHT -> new ButtonPosition(firstSlot.x + 18 * 3 + 1, firstSlot.y + 18 * index); - case LEFT -> new ButtonPosition(firstSlot.x - 19, firstSlot.y + 18 * index); + case TOP -> new ButtonPosition(firstSlot.x + style.getSpacingX() * index, firstSlot.y - style.getSpacingY() - 1); + case BOTTOM -> new ButtonPosition(firstSlot.x + style.getSpacingX() * index, firstSlot.y + 18 * 3 + 1); + case RIGHT -> new ButtonPosition(firstSlot.x + 18 * 3 + 1, firstSlot.y + style.getSpacingY() * index); + case LEFT -> new ButtonPosition(firstSlot.x - style.getSpacingX() - 1, firstSlot.y + style.getSpacingY() * index); }; }