Skip to content

Commit 1fddcf8

Browse files
committed
Some final fixes for GuiSlots and ContextMenu
1 parent 751420a commit 1fddcf8

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

Diff for: src/main/java/codechicken/lib/gui/modular/elements/GuiContextMenu.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class GuiContextMenu extends GuiElement<GuiContextMenu> {
2828
private boolean closeOnItemClicked = true;
2929
private boolean closeOnOutsideClick = true;
3030
private boolean actionOnClick = false;
31+
private boolean pressed = false;
3132

3233
public GuiContextMenu(ModularGui gui) {
3334
super(gui.getRoot());
@@ -123,6 +124,7 @@ private void rebuildButtons() {
123124
@Override
124125
public boolean mouseClicked(double mouseX, double mouseY, int button, boolean consumed) {
125126
consumed = super.mouseClicked(mouseX, mouseY, button, consumed);
127+
pressed = isMouseOver();
126128
if (isMouseOver() || consumed) {
127129
if (actionOnClick) {
128130
if (consumed && closeOnItemClicked) {
@@ -143,12 +145,14 @@ public boolean mouseReleased(double mouseX, double mouseY, int button, boolean c
143145
consumed = super.mouseReleased(mouseX, mouseY, button, consumed);
144146
if (isMouseOver() || consumed) {
145147
if (!actionOnClick) {
146-
if (consumed && closeOnItemClicked) {
148+
if (consumed && closeOnItemClicked && pressed) {
147149
close();
148150
}
151+
pressed = false;
149152
return true;
150153
}
151154
}
155+
pressed = false;
152156
return consumed;
153157
}
154158

Diff for: src/main/java/codechicken/lib/gui/modular/elements/GuiSlots.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ public GuiSlots(@NotNull GuiParent<?> parent, ContainerScreenAccess<?> screenAcc
7272
if (firstSlot + slotCount > slots.size()) {
7373
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));
7474
}
75-
int columns = Math.min(gridColumns, slots.size());
75+
int columns = Math.min(gridColumns, slotCount);
7676
this.constrain(WIDTH, Constraint.dynamic(() -> (double) (columns * 18) + ((columns - 1) * xSlotSpacing)));
77-
int rows = Math.max(1, slots.size() / gridColumns);
77+
int rows = Math.max(1, slotCount / gridColumns);
7878
this.constrain(GeoParam.HEIGHT, Constraint.dynamic(() -> (double) (rows * 18) + ((rows - 1) * ySlotSpacing)));
7979
for (int index = 0; index < slotCount; index++) {
8080
Slot slot = slots.getSlot(index + firstSlot);
@@ -315,8 +315,8 @@ public double getBackgroundDepth() {
315315
}
316316

317317
private void updateSlots(GuiElement<?> root) {
318-
int columns = Math.min(this.columns, slots.size());
319-
int rows = Math.max(1, slots.size() / columns);
318+
int columns = Math.min(this.columns, slotCount);
319+
int rows = Math.max(1, slotCount / columns);
320320
double width = (columns * 18) + (columns - 1) * xSlotSpacing;
321321
double height = (rows * 18) + (rows - 1) * ySlotSpacing;
322322
int top = (int) (yCenter() - (height / 2) - root.yMin());

0 commit comments

Comments
 (0)