diff options
author | Crendgrim <Crendgrim@users.noreply.github.com> | 2024-05-27 15:26:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-27 14:26:05 +0100 |
commit | 046b72ae8aad3a9ff228ff087385fd868fe32dbc (patch) | |
tree | c2a6a83b51e8ff11d59aa7e903e4115ebf20f0bc /src/main | |
parent | 14180a38c83c9246e28b0d5c339c8e87b2a77f8e (diff) | |
download | YetAnotherConfigLib-046b72ae8aad3a9ff228ff087385fd868fe32dbc.tar.gz YetAnotherConfigLib-046b72ae8aad3a9ff228ff087385fd868fe32dbc.tar.bz2 YetAnotherConfigLib-046b72ae8aad3a9ff228ff087385fd868fe32dbc.zip |
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.
Diffstat (limited to 'src/main')
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<E extends ElementListWidgetExt.Entry<E>> 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<E extends ElementListWidgetExt.Entry<E>> 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<E extends ElementListWidgetExt.Entry<E>> 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; @@ -167,6 +168,19 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override + protected boolean isValidClickButton(int button) { + return button == InputConstants.MOUSE_BUTTON_LEFT || button == InputConstants.MOUSE_BUTTON_RIGHT; + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (this.getFocused() != null && this.isDragging() && isValidClickButton(button)) { + return this.getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { for (Entry child : children()) { if (child.keyPressed(keyCode, scanCode, modifiers)) diff --git a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java index 59f16ff..8152d18 100644 --- a/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java +++ b/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java @@ -1,5 +1,6 @@ package dev.isxander.yacl3.gui; +import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.*; import com.mojang.math.Axis; @@ -203,6 +204,23 @@ public class YACLScreen extends Screen { } } + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (super.mouseClicked(mouseX, mouseY, button)) { + this.setDragging(true); + return true; + } + return false; + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + return this.getFocused() != null + && this.isDragging() + && (button == InputConstants.MOUSE_BUTTON_LEFT || button == InputConstants.MOUSE_BUTTON_RIGHT) + && this.getFocused().mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + public void setSaveButtonMessage(Component message, Component tooltip) { saveButtonMessage = message; saveButtonTooltipMessage = Tooltip.create(tooltip); |