diff options
author | isXander <xander@isxander.dev> | 2023-04-04 11:20:49 +0100 |
---|---|---|
committer | isXander <xander@isxander.dev> | 2023-04-04 11:20:49 +0100 |
commit | af801145f3d44b33c8d5644e4c624bc39b4cf7ce (patch) | |
tree | 1ec57032f482fa529ed79569458c249d1ef03856 /src | |
parent | 10bd86f0be7e5544e354fbb946962e25da413db9 (diff) | |
download | YetAnotherConfigLib-af801145f3d44b33c8d5644e4c624bc39b4cf7ce.tar.gz YetAnotherConfigLib-af801145f3d44b33c8d5644e4c624bc39b4cf7ce.tar.bz2 YetAnotherConfigLib-af801145f3d44b33c8d5644e4c624bc39b4cf7ce.zip |
🐛 Fix string controllers not focusing upon click properly (see MC-261578)
Diffstat (limited to 'src')
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java | 35 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/OptionListWidget.java | 12 |
2 files changed, 36 insertions, 11 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java index 07f5635..ec8e304 100644 --- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java +++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java @@ -1,5 +1,6 @@ package dev.isxander.yacl.gui; +import com.mojang.blaze3d.platform.InputConstants; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.ContainerObjectSelectionList; @@ -7,6 +8,8 @@ import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; +import java.util.Iterator; + public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> { protected final int x, y; @@ -97,10 +100,10 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten public boolean mouseReleased(double mouseX, double mouseY, int button) { // on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus boolean clicked = super.mouseReleased(mouseX, mouseY, button); - if (getFocused() != null) { - this.getFocused().setFocused(null); - this.setFocused(null); - } +// if (getFocused() != null) { +// this.getFocused().setFocused(null); +//// this.setFocused(null); +// } return clicked; } @@ -152,6 +155,30 @@ public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> exten /* END cloth config code */ public abstract static class Entry<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList.Entry<E> { + @Override + 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) + this.setDragging(true); + return true; + } + } + + return false; + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (isDragging() && button == InputConstants.MOUSE_BUTTON_LEFT) { + for (GuiEventListener child : this.children()) { + if (child.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) + return true; + } + } + return false; + } + public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { } diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java index 333d67c..8f96ddf 100644 --- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -150,13 +150,6 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override - public void mouseMoved(double mouseX, double mouseY) { - if (getFocused() instanceof OptionEntry optionEntry) - optionEntry.widget.unfocus(); - setFocused(null); - } - - @Override public boolean mouseScrolled(double mouseX, double mouseY, double amount) { super.mouseScrolled(mouseX, mouseY, amount); @@ -336,6 +329,11 @@ public class OptionListWidget extends ElementListWidgetExt<OptionListWidget.Entr } @Override + public void setFocused(boolean focused) { + super.setFocused(focused); + } + + @Override public List<? extends NarratableEntry> narratables() { if (resetButton == null) return ImmutableList.of(widget); |