Skip to content

Commit af80114

Browse files
committed
πŸ› Fix string controllers not focusing upon click properly (see MC-261578)
1 parent 10bd86f commit af80114

2 files changed

Lines changed: 36 additions & 11 deletions

File tree

β€Žsrc/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.javaβ€Ž

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package dev.isxander.yacl.gui;
22

3+
import com.mojang.blaze3d.platform.InputConstants;
34
import com.mojang.blaze3d.vertex.PoseStack;
45
import net.minecraft.client.Minecraft;
56
import net.minecraft.client.gui.components.ContainerObjectSelectionList;
67
import net.minecraft.client.gui.components.events.GuiEventListener;
78
import net.minecraft.util.Mth;
89
import org.jetbrains.annotations.Nullable;
910

11+
import java.util.Iterator;
12+
1013
public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> {
1114
protected final int x, y;
1215

@@ -97,10 +100,10 @@ protected E getEntryAtPosition(double x, double y) {
97100
public boolean mouseReleased(double mouseX, double mouseY, int button) {
98101
// on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus
99102
boolean clicked = super.mouseReleased(mouseX, mouseY, button);
100-
if (getFocused() != null) {
101-
this.getFocused().setFocused(null);
102-
this.setFocused(null);
103-
}
103+
// if (getFocused() != null) {
104+
// this.getFocused().setFocused(null);
105+
//// this.setFocused(null);
106+
// }
104107
return clicked;
105108
}
106109

@@ -152,6 +155,30 @@ protected void renderList(PoseStack matrices, int mouseX, int mouseY, float delt
152155
/* END cloth config code */
153156

154157
public abstract static class Entry<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList.Entry<E> {
158+
@Override
159+
public boolean mouseClicked(double mouseX, double mouseY, int button) {
160+
for (GuiEventListener child : this.children()) {
161+
if (child.mouseClicked(mouseX, mouseY, button)) {
162+
if (button == InputConstants.MOUSE_BUTTON_LEFT)
163+
this.setDragging(true);
164+
return true;
165+
}
166+
}
167+
168+
return false;
169+
}
170+
171+
@Override
172+
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
173+
if (isDragging() && button == InputConstants.MOUSE_BUTTON_LEFT) {
174+
for (GuiEventListener child : this.children()) {
175+
if (child.mouseDragged(mouseX, mouseY, button, deltaX, deltaY))
176+
return true;
177+
}
178+
}
179+
return false;
180+
}
181+
155182
public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) {
156183

157184
}

β€Žsrc/client/java/dev/isxander/yacl/gui/OptionListWidget.javaβ€Ž

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -149,13 +149,6 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
149149
return super.mouseClicked(mouseX, mouseY, button);
150150
}
151151

152-
@Override
153-
public void mouseMoved(double mouseX, double mouseY) {
154-
if (getFocused() instanceof OptionEntry optionEntry)
155-
optionEntry.widget.unfocus();
156-
setFocused(null);
157-
}
158-
159152
@Override
160153
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
161154
super.mouseScrolled(mouseX, mouseY, amount);
@@ -335,6 +328,11 @@ public int getItemHeight() {
335328
return Math.max(widget.getDimension().height(), resetButton != null ? resetButton.getHeight() : 0) + 2;
336329
}
337330

331+
@Override
332+
public void setFocused(boolean focused) {
333+
super.setFocused(focused);
334+
}
335+
338336
@Override
339337
public List<? extends NarratableEntry> narratables() {
340338
if (resetButton == null)

0 commit comments

Comments
Β (0)