Skip to content

Commit

Permalink
feat: Fix alternative button style spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Sep 17, 2023
1 parent 16a7618 commit 42e56b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
public class ButtonStyle {

private final EnumMap<TweakType, ButtonProperties> 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);
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public void createButtons(AbstractContainerScreen<?> screen, CraftingGrid grid,

private boolean createTweakButton(AbstractContainerScreen<?> screen, CraftingGrid grid, Consumer<AbstractWidget> 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;
}

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);
};
}

Expand Down

0 comments on commit 42e56b3

Please sign in to comment.