diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..ac590a5 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -2,5 +2,7 @@
+
+
\ No newline at end of file
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiScreen.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiScreen.java
index 7845f01..d65b2f9 100644
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiScreen.java
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiScreen.java
@@ -1,5 +1,8 @@
package cn.xiaozhou233.orangex.ui.clickgui;
+import cn.xiaozhou233.orangex.OrangeX;
+import cn.xiaozhou233.orangex.module.Module;
+import cn.xiaozhou233.orangex.ui.clickgui.component.ModuleButton;
import cn.xiaozhou233.orangex.ui.clickgui.component.PanelUI;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen;
@@ -8,30 +11,52 @@ import java.awt.*;
import java.io.IOException;
public class ClickGuiScreen extends GuiScreen {
+
private PanelUI panel;
@Override
public void initGui() {
- panel = new PanelUI(10, 10, 100, 150, "Example");
+ panel = new PanelUI(10, 10, 120, 180, "Combat");
+
+ for (Module module : OrangeX.getModuleManager().getAllModules()) {
+ panel.addComponent(new ModuleButton(module, 120));
+ }
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
// Background
- int color = new Color(50, 50, 50, 100).getRGB();
- Gui.drawRect(0, 0, this.width, this.height, color);
+ Gui.drawRect(
+ 0,
+ 0,
+ width,
+ height,
+ new Color(50, 50, 50, 100).getRGB()
+ );
if (panel != null) {
- panel.draw();
+ panel.draw(mouseX, mouseY);
}
+
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
+ if (panel != null) {
+ panel.mouseClicked(mouseX, mouseY, mouseButton);
+ }
super.mouseClicked(mouseX, mouseY, mouseButton);
}
+ @Override
+ protected void mouseReleased(int mouseX, int mouseY, int state) {
+ if (panel != null) {
+ panel.mouseReleased(state);
+ }
+ super.mouseReleased(mouseX, mouseY, state);
+ }
+
@Override
public boolean doesGuiPauseGame() {
return false;
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/Component.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/Component.java
new file mode 100644
index 0000000..6d244ce
--- /dev/null
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/Component.java
@@ -0,0 +1,19 @@
+package cn.xiaozhou233.orangex.ui.clickgui.component;
+
+public abstract class Component {
+
+ protected int x, y, width, height;
+
+ public abstract void draw(int mouseX, int mouseY);
+
+ public void mouseClicked(int mouseX, int mouseY, int button) {}
+
+ public int getHeight() {
+ return height;
+ }
+
+ protected boolean isHovering(int mouseX, int mouseY) {
+ return mouseX >= x && mouseX <= x + width
+ && mouseY >= y && mouseY <= y + height;
+ }
+}
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/ModuleButton.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/ModuleButton.java
new file mode 100644
index 0000000..36a86f6
--- /dev/null
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/ModuleButton.java
@@ -0,0 +1,80 @@
+package cn.xiaozhou233.orangex.ui.clickgui.component;
+
+import cn.xiaozhou233.orangex.module.Module;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.Gui;
+
+import java.awt.*;
+
+public class ModuleButton extends Component {
+
+ private static final Minecraft mc = Minecraft.getMinecraft();
+
+ private final Module module;
+ private boolean expanded;
+
+ private static final int BUTTON_HEIGHT = 14;
+ private static final int EXPANDED_HEIGHT = 20; // placeholder
+
+ public ModuleButton(Module module, int width) {
+ this.module = module;
+ this.width = width;
+ this.height = BUTTON_HEIGHT;
+ }
+
+ @Override
+ public void draw(int mouseX, int mouseY) {
+ boolean hover = isHovering(mouseX, mouseY);
+
+ int bgColor;
+ if (module.isEnabled()) {
+ bgColor = hover
+ ? new Color(70, 130, 180, 220).getRGB()
+ : new Color(60, 120, 170, 200).getRGB();
+ } else {
+ bgColor = hover
+ ? new Color(80, 80, 80, 200).getRGB()
+ : new Color(60, 60, 60, 180).getRGB();
+ }
+
+ // Button background
+ Gui.drawRect(x, y, x + width, y + BUTTON_HEIGHT, bgColor);
+
+ // Module name
+ mc.fontRendererObj.drawString(
+ module.getName(),
+ x + 4,
+ y + 3,
+ 0xFFFFFFFF
+ );
+
+ // Expanded area (future settings)
+ if (expanded) {
+ Gui.drawRect(
+ x,
+ y + BUTTON_HEIGHT,
+ x + width,
+ y + height,
+ new Color(45, 45, 45, 200).getRGB()
+ );
+ }
+ }
+
+ @Override
+ public void mouseClicked(int mouseX, int mouseY, int button) {
+ if (!isHovering(mouseX, mouseY)) return;
+
+ // Left click: toggle
+ if (button == 0) {
+ module.toggle();
+ }
+
+ // Right click: expand
+ if (button == 1) {
+ expanded = !expanded;
+ height = expanded
+ ? BUTTON_HEIGHT + EXPANDED_HEIGHT
+ : BUTTON_HEIGHT;
+ }
+ }
+}
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/PanelUI.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/PanelUI.java
index 8cd5a7e..ff2883c 100644
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/PanelUI.java
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/component/PanelUI.java
@@ -2,11 +2,27 @@ package cn.xiaozhou233.orangex.ui.clickgui.component;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
+
import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
public class PanelUI {
+
+ private static final Minecraft mc = Minecraft.getMinecraft();
+
private int x, y, width, height;
- private String title;
+ private final String title;
+
+ /* ================= Drag ================= */
+
+ private boolean dragging;
+ private int dragOffsetX, dragOffsetY;
+
+ /* ================= Layout ================= */
+
+ private static final int TITLE_HEIGHT = 15;
+ private final List components = new ArrayList<>();
public PanelUI(int x, int y, int width, int height, String title) {
this.x = x;
@@ -16,8 +32,89 @@ public class PanelUI {
this.title = title;
}
- public void draw() {
- Gui.drawRect(x, y, x+width, y+height, new Color(32, 32, 32, 204).getRGB());
+ /* ================= Render ================= */
+ public void draw(int mouseX, int mouseY) {
+ // Handle dragging
+ if (dragging) {
+ x = mouseX - dragOffsetX;
+ y = mouseY - dragOffsetY;
+ }
+
+ // Title bar
+ Gui.drawRect(
+ x,
+ y,
+ x + width,
+ y + TITLE_HEIGHT,
+ new Color(32, 32, 32, 200).getRGB()
+ );
+
+ mc.fontRendererObj.drawString(
+ title,
+ x + 4,
+ y + 4,
+ 0xFFFFFFFF
+ );
+
+ // Auto layout components
+ int offsetY = y + TITLE_HEIGHT;
+
+ for (Component component : components) {
+ component.x = x;
+ component.y = offsetY;
+ component.width = width;
+
+ component.draw(mouseX, mouseY);
+
+ offsetY += component.getHeight();
+ }
+
+ // Panel background (based on content height)
+ height = offsetY - y;
+
+ Gui.drawRect(
+ x,
+ y + TITLE_HEIGHT,
+ x + width,
+ y + height,
+ new Color(60, 60, 60, 180).getRGB()
+ );
+ }
+
+ /* ================= Mouse ================= */
+
+ public void mouseClicked(int mouseX, int mouseY, int button) {
+ // Drag panel
+ if (button == 0 && isHoveringTitle(mouseX, mouseY)) {
+ dragging = true;
+ dragOffsetX = mouseX - x;
+ dragOffsetY = mouseY - y;
+ return;
+ }
+
+ // Forward to components
+ for (Component component : components) {
+ component.mouseClicked(mouseX, mouseY, button);
+ }
+ }
+
+ public void mouseReleased(int mouseButton) {
+ if (mouseButton == 0) {
+ dragging = false;
+ }
+ }
+
+ /* ================= Utils ================= */
+
+ public void addComponent(Component component) {
+ components.add(component);
+ }
+
+ private boolean isHoveringTitle(int mouseX, int mouseY) {
+ return mouseX >= x
+ && mouseX <= x + width
+ && mouseY >= y
+ && mouseY <= y + TITLE_HEIGHT;
}
}