|
1 | 1 | package dev.isxander.yacl.gui; |
2 | 2 |
|
| 3 | +import com.mojang.blaze3d.platform.InputConstants; |
3 | 4 | import com.mojang.blaze3d.vertex.PoseStack; |
4 | 5 | import net.minecraft.client.Minecraft; |
5 | 6 | import net.minecraft.client.gui.components.ContainerObjectSelectionList; |
6 | 7 | import net.minecraft.client.gui.components.events.GuiEventListener; |
7 | 8 | import net.minecraft.util.Mth; |
8 | 9 | import org.jetbrains.annotations.Nullable; |
9 | 10 |
|
| 11 | +import java.util.Iterator; |
| 12 | + |
10 | 13 | public class ElementListWidgetExt<E extends ElementListWidgetExt.Entry<E>> extends ContainerObjectSelectionList<E> { |
11 | 14 | protected final int x, y; |
12 | 15 |
|
@@ -97,10 +100,10 @@ protected E getEntryAtPosition(double x, double y) { |
97 | 100 | public boolean mouseReleased(double mouseX, double mouseY, int button) { |
98 | 101 | // on mouseClicked, the clicked element becomes focused so you can drag. on release, we should clear the focus |
99 | 102 | 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 | +// } |
104 | 107 | return clicked; |
105 | 108 | } |
106 | 109 |
|
@@ -152,6 +155,30 @@ protected void renderList(PoseStack matrices, int mouseX, int mouseY, float delt |
152 | 155 | /* END cloth config code */ |
153 | 156 |
|
154 | 157 | 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 | + |
155 | 182 | public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { |
156 | 183 |
|
157 | 184 | } |
|
0 commit comments