From 1fddcf84b429a83dc0162cddd42a9658e8473250 Mon Sep 17 00:00:00 2001 From: brandon3055 Date: Sun, 3 Mar 2024 18:23:28 +1100 Subject: [PATCH] Some final fixes for GuiSlots and ContextMenu --- .../lib/gui/modular/elements/GuiContextMenu.java | 6 +++++- .../codechicken/lib/gui/modular/elements/GuiSlots.java | 8 ++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java index 704c701b..33f344f4 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java @@ -28,6 +28,7 @@ public class GuiContextMenu extends GuiElement { private boolean closeOnItemClicked = true; private boolean closeOnOutsideClick = true; private boolean actionOnClick = false; + private boolean pressed = false; public GuiContextMenu(ModularGui gui) { super(gui.getRoot()); @@ -123,6 +124,7 @@ private void rebuildButtons() { @Override public boolean mouseClicked(double mouseX, double mouseY, int button, boolean consumed) { consumed = super.mouseClicked(mouseX, mouseY, button, consumed); + pressed = isMouseOver(); if (isMouseOver() || consumed) { if (actionOnClick) { if (consumed && closeOnItemClicked) { @@ -143,12 +145,14 @@ public boolean mouseReleased(double mouseX, double mouseY, int button, boolean c consumed = super.mouseReleased(mouseX, mouseY, button, consumed); if (isMouseOver() || consumed) { if (!actionOnClick) { - if (consumed && closeOnItemClicked) { + if (consumed && closeOnItemClicked && pressed) { close(); } + pressed = false; return true; } } + pressed = false; return consumed; } diff --git a/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java b/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java index aa21af09..c2bfd086 100644 --- a/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java +++ b/src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java @@ -72,9 +72,9 @@ public GuiSlots(@NotNull GuiParent parent, ContainerScreenAccess screenAcc if (firstSlot + slotCount > slots.size()) { throw new IllegalStateException("Specified slot range is out of bounds, Last slot in group is at index " + (slots.size() - 1) + " Specified range is from index " + firstSlot + " to " + (firstSlot + slotCount - 1)); } - int columns = Math.min(gridColumns, slots.size()); + int columns = Math.min(gridColumns, slotCount); this.constrain(WIDTH, Constraint.dynamic(() -> (double) (columns * 18) + ((columns - 1) * xSlotSpacing))); - int rows = Math.max(1, slots.size() / gridColumns); + int rows = Math.max(1, slotCount / gridColumns); this.constrain(GeoParam.HEIGHT, Constraint.dynamic(() -> (double) (rows * 18) + ((rows - 1) * ySlotSpacing))); for (int index = 0; index < slotCount; index++) { Slot slot = slots.getSlot(index + firstSlot); @@ -315,8 +315,8 @@ public double getBackgroundDepth() { } private void updateSlots(GuiElement root) { - int columns = Math.min(this.columns, slots.size()); - int rows = Math.max(1, slots.size() / columns); + int columns = Math.min(this.columns, slotCount); + int rows = Math.max(1, slotCount / columns); double width = (columns * 18) + (columns - 1) * xSlotSpacing; double height = (rows * 18) + (rows - 1) * ySlotSpacing; int top = (int) (yCenter() - (height / 2) - root.yMin());