From 046b72ae8aad3a9ff228ff087385fd868fe32dbc Mon Sep 17 00:00:00 2001 From: Crendgrim Date: Mon, 27 May 2024 15:26:05 +0200 Subject: Propagate right click mouse events to widgets contained in option lists (#180) * Propagate right click mouse events to widgets contained in option lists Starting with Minecraft 1.20.2, only left click events are passed to list elements. This adds the required override to the respective versions to get right click events. With this change, right-clicking a cycling controller (like enum controller) element properly walks backwards through the list. Closes #157 * Propagate right-click drag events to controllers This requires a bit of plumbing in several places, because Minecraft aggressively filters for left-click drags. --- .../dev/isxander/yacl3/gui/ElementListWidgetExt.java | 12 ++++++++++-- .../java/dev/isxander/yacl3/gui/OptionListWidget.java | 14 ++++++++++++++ src/main/java/dev/isxander/yacl3/gui/YACLScreen.java | 18 ++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java b/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java index e5aca58..abe1107 100644 --- a/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java +++ b/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java @@ -10,6 +10,7 @@ import net.minecraft.client.gui.layouts.LayoutElement; import net.minecraft.client.gui.navigation.ScreenRectangle; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; +import org.lwjgl.glfw.GLFW; import java.util.function.Consumer; @@ -79,6 +80,13 @@ public class ElementListWidgetExt> exten returnSmoothAmount = false; } + /*? if >1.20.1 { */ + @Override + protected boolean isValidMouseClick(int button) { + return button == InputConstants.MOUSE_BUTTON_LEFT || button == InputConstants.MOUSE_BUTTON_RIGHT; + } + /*?}*/ + @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { if (button == 0 && mouseX >= getScrollbarPosition() && mouseX < getScrollbarPosition() + SCROLLBAR_WIDTH) { @@ -215,7 +223,7 @@ public class ElementListWidgetExt> exten public boolean mouseClicked(double mouseX, double mouseY, int button) { for (GuiEventListener child : this.children()) { if (child.mouseClicked(mouseX, mouseY, button)) { - if (button == InputConstants.MOUSE_BUTTON_LEFT) + if (button == InputConstants.MOUSE_BUTTON_LEFT || button == InputConstants.MOUSE_BUTTON_RIGHT) this.setDragging(true); return true; } @@ -226,7 +234,7 @@ public class ElementListWidgetExt> exten @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (isDragging() && button == InputConstants.MOUSE_BUTTON_LEFT) { + if (isDragging() && (button == InputConstants.MOUSE_BUTTON_LEFT || button == InputConstants.MOUSE_BUTTON_RIGHT)) { for (GuiEventListener child : this.children()) { if (child.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) return true; diff --git a/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java b/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java index 9827aab..1cd173b 100644 --- a/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java +++ b/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java @@ -1,6 +1,7 @@ package dev.isxander.yacl3.gui; import com.google.common.collect.ImmutableList; +import com.mojang.blaze3d.platform.InputConstants; import dev.isxander.yacl3.api.*; import dev.isxander.yacl3.api.utils.Dimension; import dev.isxander.yacl3.impl.utils.YACLConstants; @@ -166,6 +167,19 @@ public class OptionListWidget extends ElementListWidgetExt