Skip to content

Commit

Permalink
Some final fixes for GuiSlots and ContextMenu
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Mar 3, 2024
1 parent 751420a commit 1fddcf8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class GuiContextMenu extends GuiElement<GuiContextMenu> {
private boolean closeOnItemClicked = true;
private boolean closeOnOutsideClick = true;
private boolean actionOnClick = false;
private boolean pressed = false;

public GuiContextMenu(ModularGui gui) {
super(gui.getRoot());
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 1fddcf8

Please sign in to comment.