From b72c1bc13c385d68c7057857d66ba3909644580a Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sun, 25 Jan 2026 13:42:21 +0800 Subject: [PATCH 1/2] [UI] Improve AltManager interaction with double-click login [Add] Allow double-click on alt entry to trigger login [Fix] Handle mouse input via mouseClicked to avoid multi-frame click issues [Fix] Prevent clicks on non-visible list items when scrolling [Improve] Reset click state on GUI init and alt removal [Improve] Keep selection logic independent from login behavior [Keep] Existing button-based login and navigation flow --- .../orangex/ui/altmanager/GUIAltManager.java | 106 +++++++++++++++--- 1 file changed, 90 insertions(+), 16 deletions(-) diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java index aa3bb1a..7c94274 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java @@ -4,7 +4,9 @@ import cn.xiaozhou233.orangex.OrangeX; import cn.xiaozhou233.orangex.alts.Alt; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiMultiplayer; import net.minecraft.client.gui.GuiScreen; +import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import java.awt.*; @@ -16,10 +18,22 @@ public class GUIAltManager extends GuiScreen { private int selectedIndex = -1; private int scroll = 0; + // Double click detect + private int lastClickIndex = -1; + private long lastClickTime = 0L; + + // Double click interval (ms) + private static final long DOUBLE_CLICK_DELAY = 250L; + @Override public void initGui() { this.buttonList.clear(); + // Reset click state + selectedIndex = -1; + lastClickIndex = -1; + lastClickTime = 0L; + // Add this.buttonList.add(new GuiButton(1, this.width - 110, 10, 100, 20, "Add Cracked")); this.buttonList.add(new GuiButton(2, this.width - 110, 35, 100, 20, "Add Microsoft")); @@ -40,23 +54,28 @@ public class GUIAltManager extends GuiScreen { case 1: mc.displayGuiScreen(new GUIAddCracked()); break; + case 2: mc.displayGuiScreen(new GUIAddMicrosoft()); break; + case 3: - mc.displayGuiScreen(null); + mc.displayGuiScreen(new GuiMultiplayer(null)); break; + case 4: if (selectedIndex >= 0) { Alt alt = OrangeX.getInstance().getAltManager().getAlts().get(selectedIndex); OrangeX.getInstance().getAltManager().login(alt); } break; + case 5: if (selectedIndex >= 0) { Alt alt = OrangeX.getInstance().getAltManager().getAlts().get(selectedIndex); OrangeX.getInstance().getAltManager().removeAlt(alt); selectedIndex = -1; + lastClickIndex = -1; } break; } @@ -82,42 +101,97 @@ public class GUIAltManager extends GuiScreen { int lineHeight = 20; // Draw list background - drawRect(startX - 2, startY - 2, startX + listWidth + 2, startY + listHeight + 2, 0x55000000); + drawRect( + startX - 2, + startY - 2, + startX + listWidth + 2, + startY + listHeight + 2, + 0x55000000 + ); // Scroll int wheel = Mouse.getDWheel(); if (wheel != 0) { - if (wheel > 0) scroll -= 20; - else scroll += 20; + scroll += wheel > 0 ? -20 : 20; } + + int maxScroll = Math.max(0, alts.size() * lineHeight - listHeight); if (scroll < 0) scroll = 0; - if (scroll > Math.max(0, alts.size() * lineHeight - listHeight)) { - scroll = Math.max(0, alts.size() * lineHeight - listHeight); - } + if (scroll > maxScroll) scroll = maxScroll; // Render alts for (int i = 0; i < alts.size(); i++) { int y = startY + i * lineHeight - scroll; - if (y < startY - lineHeight || y > startY + listHeight) continue; + if (y < startY - lineHeight || y > startY + listHeight) { + continue; + } if (i == selectedIndex) { drawRect(startX, y, startX + listWidth, y + lineHeight, 0x55FFFFFF); } - mc.fontRendererObj.drawString(alts.get(i).getName(), startX + 5, y + 6, Color.WHITE.getRGB()); - - // Click select - if (mouseX >= startX && mouseX <= startX + listWidth && - mouseY >= y && mouseY <= y + lineHeight && - Mouse.isButtonDown(0)) { - selectedIndex = i; - } + mc.fontRendererObj.drawString( + alts.get(i).getName(), + startX + 5, + y + 6, + Color.WHITE.getRGB() + ); } super.drawScreen(mouseX, mouseY, partialTicks); } + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + if (mouseButton != 0) return; + + List alts = OrangeX.getInstance().getAltManager().getAlts(); + + int startX = 10; + int startY = 60; + int listWidth = this.width - 20; + int listHeight = this.height - 110; + int lineHeight = 20; + + for (int i = 0; i < alts.size(); i++) { + int y = startY + i * lineHeight - scroll; + + // Only allow clicking visible items + if (y < startY - lineHeight || y > startY + listHeight) { + continue; + } + + if (mouseX >= startX && mouseX <= startX + listWidth && + mouseY >= y && mouseY <= y + lineHeight) { + + long now = System.currentTimeMillis(); + + if (lastClickIndex == i && now - lastClickTime <= DOUBLE_CLICK_DELAY) { + // Double click -> login + OrangeX.getInstance().getAltManager().login(alts.get(i)); + return; + } + + // Single click -> select + selectedIndex = i; + lastClickIndex = i; + lastClickTime = now; + break; + } + } + + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + super.keyTyped(typedChar, keyCode); + if (keyCode == Keyboard.KEY_ESCAPE) { + mc.displayGuiScreen(new GuiMultiplayer(null)); + } + } + @Override public boolean doesGuiPauseGame() { return false; From c9c2c926984a453c99fe636a0105614a7e8a40f7 Mon Sep 17 00:00:00 2001 From: xiaozhou233 Date: Sun, 25 Jan 2026 13:58:10 +0800 Subject: [PATCH 2/2] [Fix] Prevent alt list index out-of-bounds in GUI --- .../orangex/ui/altmanager/GUIAltManager.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java index 7c94274..5f68d01 100644 --- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java +++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/altmanager/GUIAltManager.java @@ -50,6 +50,8 @@ public class GUIAltManager extends GuiScreen { @Override protected void actionPerformed(GuiButton button) throws IOException { + List alts = OrangeX.getInstance().getAltManager().getAlts(); + switch (button.id) { case 1: mc.displayGuiScreen(new GUIAddCracked()); @@ -64,15 +66,15 @@ public class GUIAltManager extends GuiScreen { break; case 4: - if (selectedIndex >= 0) { - Alt alt = OrangeX.getInstance().getAltManager().getAlts().get(selectedIndex); + if (selectedIndex >= 0 && selectedIndex < alts.size()) { + Alt alt = alts.get(selectedIndex); OrangeX.getInstance().getAltManager().login(alt); } break; case 5: - if (selectedIndex >= 0) { - Alt alt = OrangeX.getInstance().getAltManager().getAlts().get(selectedIndex); + if (selectedIndex >= 0 && selectedIndex < alts.size()) { + Alt alt = alts.get(selectedIndex); OrangeX.getInstance().getAltManager().removeAlt(alt); selectedIndex = -1; lastClickIndex = -1; @@ -81,6 +83,7 @@ public class GUIAltManager extends GuiScreen { } } + @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground();