Merge pull request #4 from xiaozhou233/altmanager

[UI] Improve AltManager interaction with double-click login
This commit is contained in:
xiaozhou233 authored and GitHub committed 2026-01-25 14:00:03 +08:00
commit dfd8775658
1 file changed
+97 -20
@@ -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"));
@@ -36,32 +50,40 @@ public class GUIAltManager extends GuiScreen {
@Override
protected void actionPerformed(GuiButton button) throws IOException {
List<Alt> alts = OrangeX.getInstance().getAltManager().getAlts();
switch (button.id) {
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);
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;
}
break;
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
@@ -82,42 +104,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<Alt> 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;