From c5917e9854958adf1e4aa1aa22251f7b3f911d38 Mon Sep 17 00:00:00 2001 From: isXander Date: Wed, 29 Mar 2023 17:11:24 +0100 Subject: Fix buttons stuck focusing after clicking the mouse. --- .../java/dev/isxander/yacl/gui/ElementListWidgetExt.java | 12 ++++++++++++ src/client/java/dev/isxander/yacl/gui/OptionListWidget.java | 7 +++++++ .../dev/isxander/yacl/gui/controllers/BooleanController.java | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) (limited to 'src/client/java/dev/isxander') diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java index e28509e..07f5635 100644 --- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java +++ b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java @@ -3,6 +3,7 @@ package dev.isxander.yacl.gui; import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.ContainerObjectSelectionList; +import net.minecraft.client.gui.components.events.GuiEventListener; import net.minecraft.util.Mth; import org.jetbrains.annotations.Nullable; @@ -92,6 +93,17 @@ public class ElementListWidgetExt> exten return null; } + @Override + 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); + } + return clicked; + } + /* below code is licensed from cloth-config under LGPL3 modified to inherit vanilla's EntryListWidget and use yarn mappings diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java index 097f076..333d67c 100644 --- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java @@ -149,6 +149,13 @@ public class OptionListWidget extends ElementListWidgetExt { @Override public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (!focused) { + if (!isFocused()) { return false; } -- cgit