diff options
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); |