From d8a46a1b70b41b53f65544587eeac9582453f331 Mon Sep 17 00:00:00 2001
From: xiaozhou233
Date: Tue, 10 Nov 2026 13:26:19 +0800
Subject: [PATCH] Feat: Show module settings as a page in the ClickGUI content
area
- Replace the floating SettingsWindow with an inline settings page
- Return to the module list via the back button or a category click
- Scroll the module list and the settings page with the mouse wheel
- Share module row geometry through ContentList and add a scrollbar
helper
- Bail out of scroll input when the content fits
---
.../orangex/ui/clickgui/ClickGuiModules.java | 13 +
.../orangex/ui/clickgui/ClickGuiStyle.java | 23 ++
.../orangex/ui/clickgui/ContentList.java | 78 ++++++
.../orangex/ui/clickgui/ContentRenderer.java | 35 ++-
.../orangex/ui/clickgui/MainPanel.java | 147 +++++++---
.../orangex/ui/clickgui/SettingsSection.java | 217 +++++++++++++++
.../orangex/ui/clickgui/SettingsWindow.java | 263 ------------------
7 files changed, 456 insertions(+), 320 deletions(-)
create mode 100644 OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentList.java
create mode 100644 OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsSection.java
delete mode 100644 OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsWindow.java
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiModules.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiModules.java
index 0ac927a..7ccd951 100644
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiModules.java
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiModules.java
@@ -28,6 +28,19 @@ public final class ClickGuiModules {
return settings;
}
+ /**
+ * Allocation-free variant of {@link #settingsOf(Module)} for rows that only
+ * need to know whether a settings page can be opened.
+ */
+ public static boolean hasSettings(Module module) {
+ for (Value> value : module.getVisibleValues()) {
+ if (!(value instanceof KeybindValue)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
public static String displayName(ModuleCategory category) {
String name = category.name();
return name.substring(0, 1) + name.substring(1).toLowerCase(Locale.ROOT);
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiStyle.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiStyle.java
index a67821b..d2c5375 100644
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiStyle.java
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ClickGuiStyle.java
@@ -50,6 +50,7 @@ public final class ClickGuiStyle {
public static final int COLOR_SIDEBAR_BORDER = 0xFF24242C;
public static final int COLOR_SWITCH_OFF = 0xFF34343F;
public static final int COLOR_KNOB_OFF = 0xFF9A9AA8;
+ public static final int COLOR_SCROLLBAR = 0x40FFFFFF;
private ClickGuiStyle() {
}
@@ -81,6 +82,28 @@ public final class ClickGuiStyle {
return top + (height - font.getStringHeight()) / 2.0;
}
+ /**
+ * Draws a thin scrollbar for a scrollable list. Nothing is drawn while the
+ * content fits, so short lists look unchanged.
+ */
+ public static void drawScrollbar(Render2D graphics, double x, double top,
+ double viewHeight, double contentHeight,
+ double scroll) {
+ if (contentHeight <= viewHeight + 0.5) {
+ return;
+ }
+
+ double thumbHeight = Math.max(18.0,
+ viewHeight * (viewHeight / contentHeight));
+ double maxScroll = contentHeight - viewHeight;
+ double progress = maxScroll <= 0.0 ? 0.0
+ : clamp((float) (scroll / maxScroll), 0.0f, 1.0f);
+ double thumbY = top + (viewHeight - thumbHeight) * progress;
+
+ graphics.fillRoundedRect(x, thumbY, 2.0, thumbHeight, 1.0,
+ COLOR_SCROLLBAR);
+ }
+
public static boolean isInside(double mouseX, double mouseY,
double x, double y,
double width, double height) {
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentList.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentList.java
new file mode 100644
index 0000000..1fd0c03
--- /dev/null
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentList.java
@@ -0,0 +1,78 @@
+package cn.xiaozhou233.orangex.ui.clickgui;
+
+import cn.xiaozhou233.orangex.modules.Module;
+
+import java.util.List;
+
+/**
+ * Row geometry for the module list.
+ *
+ * Module rows are evenly sized, so a row's position is just its index times
+ * the row stride minus the scroll offset. The renderer and the input code share
+ * this class so both always agree on where a row is.
+ */
+public final class ContentList {
+
+ private final ClickGuiLayout layout;
+ private final List modules;
+
+ private float scroll;
+
+ public ContentList(ClickGuiLayout layout, List modules,
+ float scroll) {
+ this.layout = layout;
+ this.modules = modules;
+ this.scroll = scroll;
+ }
+
+ public List modules() {
+ return modules;
+ }
+
+ public float scroll() {
+ return scroll;
+ }
+
+ public void scrollBy(float amount) {
+ scroll += amount;
+ }
+
+ /**
+ * Clamps the scroll offset to the current content, so switching category
+ * never leaves the list overscrolled.
+ */
+ public void clampScroll() {
+ scroll = ClickGuiStyle.clamp(scroll, 0.0f, maxScroll());
+ }
+
+ public float rowStride() {
+ return ClickGuiStyle.MODULE_HEIGHT + ClickGuiStyle.MODULE_GAP;
+ }
+
+ public float rowTop(int index) {
+ return layout.listTop() + index * rowStride() - scroll;
+ }
+
+ public float contentHeight() {
+ return modules.isEmpty() ? 0.0f
+ : modules.size() * rowStride() - ClickGuiStyle.MODULE_GAP;
+ }
+
+ public float maxScroll() {
+ return Math.max(0.0f,
+ contentHeight() - (layout.listBottom() - layout.listTop()));
+ }
+
+ /**
+ * @return the index of the module row under {@code mouseY}, or {@code -1}.
+ */
+ public int moduleIndexAt(float mouseY) {
+ for (int i = 0; i < modules.size(); i++) {
+ float top = rowTop(i);
+ if (mouseY >= top && mouseY <= top + ClickGuiStyle.MODULE_HEIGHT) {
+ return i;
+ }
+ }
+ return -1;
+ }
+}
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentRenderer.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentRenderer.java
index e5505af..a9e4bc7 100644
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentRenderer.java
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/ContentRenderer.java
@@ -11,8 +11,9 @@ import java.util.List;
/**
* Draws the module list for the selected category.
*
- * Module settings are not drawn inline; right-clicking a module opens the
- * separate {@link SettingsWindow}.
+ * Right-clicking a module opens its settings page in this same content area
+ * (see {@link SettingsSection}). The list scrolls with the wheel and shows a
+ * scrollbar when it does not fit.
*/
public final class ContentRenderer {
@@ -20,13 +21,13 @@ public final class ContentRenderer {
}
public static void draw(Render2D graphics, ClickGuiLayout layout,
- List modules, ModuleCategory category,
+ ContentList rows, ModuleCategory category,
ClickGuiAnimator animator, float delta,
double mouseX, double mouseY) {
- float x = layout.x();
float y = layout.y();
float contentX = layout.contentX();
float contentWidth = layout.contentWidth();
+ List modules = rows.modules();
FontRenderer title = ClickGuiStyle.font(graphics, 13.0f, true);
title.drawString(ClickGuiModules.displayName(category), contentX,
@@ -57,22 +58,30 @@ public final class ContentRenderer {
contentX + (contentWidth - empty.getStringWidth(text)) / 2.0,
listTop + 14, ClickGuiStyle.COLOR_TEXT_MUTED);
} else {
- float rowY = listTop;
+ for (int i = 0; i < modules.size(); i++) {
+ Module module = modules.get(i);
+ float rowY = rows.rowTop(i);
- for (Module module : modules) {
- boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY,
- contentX, rowY, contentWidth,
- ClickGuiStyle.MODULE_HEIGHT);
+ if (rowY > listBottom
+ || rowY + ClickGuiStyle.MODULE_HEIGHT < listTop) {
+ continue;
+ }
+
+ boolean hovered = mouseY >= listTop && mouseY <= listBottom
+ && ClickGuiStyle.isInside(mouseX, mouseY, contentX,
+ rowY, contentWidth, ClickGuiStyle.MODULE_HEIGHT);
float hover = animator.hover(module, hovered, delta);
- drawModuleRow(graphics, layout, module, rowY, hover,
- animator, delta);
-
- rowY += ClickGuiStyle.MODULE_HEIGHT + ClickGuiStyle.MODULE_GAP;
+ drawModuleRow(graphics, layout, module, rowY, hover, animator,
+ delta);
}
}
graphics.disableScissor();
+
+ ClickGuiStyle.drawScrollbar(graphics, contentX + contentWidth - 3,
+ listTop, listBottom - listTop, rows.contentHeight(),
+ rows.scroll());
}
private static void drawModuleRow(Render2D graphics, ClickGuiLayout layout,
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/MainPanel.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/MainPanel.java
index e3241f5..b381394 100644
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/MainPanel.java
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/MainPanel.java
@@ -8,10 +8,9 @@ import cn.xiaozhou233.orangex.modules.ModuleCategory;
import cn.xiaozhou233.orangex.modules.ModuleManager;
import cn.xiaozhou233.orangex.render.api.Render2D;
import cn.xiaozhou233.orangex.ui.clickgui.component.Component;
-import cn.xiaozhou233.orangex.value.BooleanValue;
-import cn.xiaozhou233.orangex.value.ModeValue;
import cn.xiaozhou233.orangex.value.Value;
+import java.util.Collections;
import java.util.List;
/**
@@ -19,8 +18,9 @@ import java.util.List;
*
* A single rounded window with a category sidebar on the left and the
* selected category's modules on the right. Left-clicking a module toggles it;
- * right-clicking a module opens its settings in the separate
- * {@link SettingsWindow}. The window itself can be dragged by its header.
+ * right-clicking a module swaps the content area to its settings page, which is
+ * left with the back button next to the module name. The window itself can be
+ * dragged by its header.
*
* All coordinates are Minecraft GUI pixels. Input is polled from
* {@link ClientInput} because the empty input screen does not forward
@@ -31,14 +31,21 @@ public final class MainPanel extends Component {
private static final ModuleCategory[] CATEGORIES = ModuleCategory.values();
+ /** Pixels scrolled per wheel notch. */
+ private static final float SCROLL_STEP = 24.0f;
+
private final ModuleManager moduleManager =
OrangeX.getInstance().getModuleManager();
private final ClickGuiAnimator animator = new ClickGuiAnimator();
- private final SettingsWindow settingsWindow = new SettingsWindow();
private ModuleCategory selectedCategory = ModuleCategory.RENDER;
+ /** Module whose settings page replaces the list, or {@code null}. */
+ private Module settingsModule;
+
+ private float scrollOffset;
+
private boolean hasPosition;
private boolean dragging;
private float dragOffsetX;
@@ -56,6 +63,8 @@ public final class MainPanel extends Component {
updateBounds(graphics);
ClickGuiLayout layout = layout();
+ applyScroll(layout);
+
float delta = updateDelta();
double mouseX = ClientInput.getMouseX();
double mouseY = ClientInput.getMouseY();
@@ -68,23 +77,18 @@ public final class MainPanel extends Component {
PanelChrome.drawHeader(graphics, layout);
SidebarRenderer.draw(graphics, layout, selectedCategory,
moduleManager.getAllModules(), animator, delta, mouseX, mouseY);
- ContentRenderer.draw(graphics, layout,
- modulesOf(selectedCategory), selectedCategory,
- animator, delta, mouseX, mouseY);
- settingsWindow.render(graphics, delta, mouseX, mouseY);
+ if (settingsModule == null) {
+ ContentRenderer.draw(graphics, layout, contentList(layout),
+ selectedCategory, animator, delta, mouseX, mouseY);
+ } else {
+ SettingsSection.draw(graphics, layout, settingsModule,
+ settingsOf(), scrollOffset, animator, delta, mouseX, mouseY);
+ }
}
@Override
public void mouseClicked(float mouseX, float mouseY, int button) {
- if (settingsWindow.isOpen()) {
- if (settingsWindow.mouseClicked(mouseX, mouseY, button)) {
- return;
- }
- settingsWindow.close();
- return;
- }
-
if (!ClickGuiStyle.isInside(mouseX, mouseY, x, y, width, height)) {
return;
}
@@ -102,7 +106,15 @@ public final class MainPanel extends Component {
ClickGuiLayout layout = layout();
ModuleCategory category = categoryAt(layout, mouseX, mouseY);
if (category != null) {
- selectedCategory = category;
+ if (category != selectedCategory) {
+ selectedCategory = category;
+ }
+ closeSettings();
+ return;
+ }
+
+ if (settingsModule != null) {
+ handleSettingsClick(layout, mouseX, mouseY, button);
return;
}
@@ -111,11 +123,6 @@ public final class MainPanel extends Component {
@Override
public void mouseDragged(float mouseX, float mouseY, int button) {
- if (settingsWindow.isOpen()) {
- settingsWindow.mouseDragged(mouseX, mouseY, button);
- return;
- }
-
if (!dragging || button != 0) {
return;
}
@@ -135,7 +142,6 @@ public final class MainPanel extends Component {
@Override
public void mouseReleased(float mouseX, float mouseY, int button) {
- settingsWindow.mouseReleased(mouseX, mouseY, button);
if (button == 0) {
dragging = false;
}
@@ -143,7 +149,7 @@ public final class MainPanel extends Component {
public void resetInteraction() {
dragging = false;
- settingsWindow.close();
+ closeSettings();
}
/* ------------------------------------------------------------------ */
@@ -155,30 +161,50 @@ public final class MainPanel extends Component {
if (mouseY < layout.listTop() || mouseY > layout.listBottom()) {
return false;
}
-
- float contentX = layout.contentX();
- float contentWidth = layout.contentWidth();
- float moduleHeight = ClickGuiStyle.MODULE_HEIGHT;
- float rowY = layout.listTop();
-
- for (Module module : modulesOf(selectedCategory)) {
- if (ClickGuiStyle.isInside(mouseX, mouseY, contentX, rowY,
- contentWidth, moduleHeight)) {
- if (button == 0) {
- module.toggle();
- } else if (button == 1
- && !ClickGuiModules.settingsOf(module).isEmpty()) {
- settingsWindow.open(module, layout);
- }
- return true;
- }
-
- rowY += moduleHeight + ClickGuiStyle.MODULE_GAP;
+ if (mouseX < layout.contentX()
+ || mouseX > layout.contentX() + layout.contentWidth()) {
+ return false;
}
+ ContentList rows = contentList(layout);
+ int moduleIndex = rows.moduleIndexAt(mouseY);
+ if (moduleIndex < 0) {
+ return false;
+ }
+
+ Module module = rows.modules().get(moduleIndex);
+ if (button == 0) {
+ module.toggle();
+ } else if (button == 1 && ClickGuiModules.hasSettings(module)) {
+ settingsModule = module;
+ scrollOffset = 0.0f;
+ }
+ return true;
+ }
+
+ private boolean handleSettingsClick(ClickGuiLayout layout, float mouseX,
+ float mouseY, int button) {
+ if (button == 0 && SettingsSection.isBackButton(layout, mouseX,
+ mouseY)) {
+ closeSettings();
+ return true;
+ }
+
+ List> settings = settingsOf();
+ int index = SettingsSection.rowIndexAt(layout, settings, scrollOffset,
+ mouseY);
+ if (index >= 0) {
+ SettingsSection.click(settings, index, button);
+ return true;
+ }
return false;
}
+ private void closeSettings() {
+ settingsModule = null;
+ scrollOffset = 0.0f;
+ }
+
private ModuleCategory categoryAt(ClickGuiLayout layout, float mouseX,
float mouseY) {
float rowX = layout.categoryRowX();
@@ -205,6 +231,39 @@ public final class MainPanel extends Component {
screenWidth, screenHeight);
}
+ private ContentList contentList(ClickGuiLayout layout) {
+ return new ContentList(layout, modulesOf(selectedCategory),
+ scrollOffset);
+ }
+
+ private List> settingsOf() {
+ return settingsModule == null
+ ? Collections.>emptyList()
+ : ClickGuiModules.settingsOf(settingsModule);
+ }
+
+ /**
+ * Applies this frame's wheel input to whichever list is visible and keeps
+ * its offset inside the content.
+ */
+ private void applyScroll(ClickGuiLayout layout) {
+ double wheel = ClientInput.consumeScroll();
+ float step = (float) -wheel * SCROLL_STEP;
+
+ if (settingsModule != null) {
+ scrollOffset = ClickGuiStyle.clamp(scrollOffset + step, 0.0f,
+ SettingsSection.maxScroll(layout, settingsOf()));
+ return;
+ }
+
+ ContentList rows = contentList(layout);
+ if (wheel != 0.0) {
+ rows.scrollBy(step);
+ }
+ rows.clampScroll();
+ scrollOffset = rows.scroll();
+ }
+
private void updateBounds(Render2D graphics) {
screenWidth = graphics.getWidth();
screenHeight = graphics.getHeight();
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsSection.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsSection.java
new file mode 100644
index 0000000..041b52b
--- /dev/null
+++ b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsSection.java
@@ -0,0 +1,217 @@
+package cn.xiaozhou233.orangex.ui.clickgui;
+
+import cn.xiaozhou233.orangex.modules.Module;
+import cn.xiaozhou233.orangex.render.api.FontRenderer;
+import cn.xiaozhou233.orangex.render.api.Render2D;
+import cn.xiaozhou233.orangex.value.BooleanValue;
+import cn.xiaozhou233.orangex.value.ModeValue;
+import cn.xiaozhou233.orangex.value.Value;
+
+import java.util.List;
+
+/**
+ * The settings page shown in the content area of {@link MainPanel}.
+ *
+ * Opening a module's settings replaces the module list instead of spawning a
+ * separate window. The page keeps the list's scroll viewport and is left with
+ * the back button drawn next to the module name.
+ */
+public final class SettingsSection {
+
+ /** Height of one settings row. */
+ public static final float ROW_HEIGHT = 22f;
+
+ private static final float BACK_SIZE = 16f;
+ private static final float BACK_GAP = 6f;
+
+ private static final Object BACK_HOVER_KEY = new Object();
+
+ private SettingsSection() {
+ }
+
+ /**
+ * @return the total height of the rows, which may exceed the visible list.
+ */
+ public static float contentHeight(List> settings) {
+ return settings.size() * ROW_HEIGHT;
+ }
+
+ public static float maxScroll(ClickGuiLayout layout, List> settings) {
+ return Math.max(0.0f,
+ contentHeight(settings)
+ - (layout.listBottom() - layout.listTop()));
+ }
+
+ public static void draw(Render2D graphics, ClickGuiLayout layout,
+ Module module, List> settings, float scroll,
+ ClickGuiAnimator animator, float delta,
+ double mouseX, double mouseY) {
+ float contentX = layout.contentX();
+ float contentWidth = layout.contentWidth();
+ float headerY = layout.y() + ClickGuiStyle.HEADER_HEIGHT;
+
+ drawBackButton(graphics, layout, animator, delta, mouseX, mouseY);
+
+ FontRenderer title = ClickGuiStyle.font(graphics, 13.0f, true);
+ title.drawString(module.getName(),
+ contentX + BACK_SIZE + BACK_GAP + 4,
+ headerY + 10, ClickGuiStyle.COLOR_TEXT);
+
+ FontRenderer meta = ClickGuiStyle.font(graphics, 8.0f);
+ String metaText = "SETTINGS";
+ meta.drawString(metaText,
+ contentX + contentWidth - meta.getStringWidth(metaText),
+ headerY + 14, ClickGuiStyle.COLOR_TEXT_MUTED);
+
+ graphics.fillRect(contentX, headerY + 30, contentWidth, 1,
+ ClickGuiStyle.COLOR_DIVIDER);
+
+ float listTop = layout.listTop();
+ float listBottom = layout.listBottom();
+
+ graphics.enableScissor(contentX - 2, listTop - 2,
+ contentWidth + 4, listBottom - listTop + 4);
+
+ float rowY = listTop - scroll;
+ for (Value> value : settings) {
+ if (rowY + ROW_HEIGHT >= listTop && rowY <= listBottom) {
+ drawRow(graphics, layout, value, rowY, animator, delta,
+ mouseX, mouseY);
+ }
+ rowY += ROW_HEIGHT;
+ }
+
+ graphics.disableScissor();
+
+ ClickGuiStyle.drawScrollbar(graphics, contentX + contentWidth - 3,
+ listTop, listBottom - listTop, contentHeight(settings), scroll);
+ }
+
+ private static void drawBackButton(Render2D graphics, ClickGuiLayout layout,
+ ClickGuiAnimator animator, float delta,
+ double mouseX, double mouseY) {
+ float backX = layout.contentX();
+ float backY = backTop(layout);
+ boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY, backX, backY,
+ BACK_SIZE, BACK_SIZE);
+ float hover = animator.hover(BACK_HOVER_KEY, hovered, delta);
+
+ if (hover > 0.01f) {
+ graphics.fillRoundedRect(backX, backY, BACK_SIZE, BACK_SIZE, 4,
+ ClickGuiStyle.argb((int) (22.0f * hover),
+ ClickGuiStyle.COLOR_ACCENT_RGB));
+ }
+
+ FontRenderer arrow = ClickGuiStyle.font(graphics, 9.0f, true);
+ arrow.drawCenteredString("<", backX + BACK_SIZE / 2.0,
+ ClickGuiStyle.centeredY(arrow, backY, BACK_SIZE),
+ hovered ? ClickGuiStyle.COLOR_ACCENT
+ : ClickGuiStyle.COLOR_TEXT_MUTED);
+ }
+
+ private static void drawRow(Render2D graphics, ClickGuiLayout layout,
+ Value> value, float rowY,
+ ClickGuiAnimator animator, float delta,
+ double mouseX, double mouseY) {
+ float rowLeft = layout.contentX();
+ float rowWidth = layout.contentWidth();
+ boolean hovered = mouseY >= layout.listTop()
+ && mouseY <= layout.listBottom()
+ && ClickGuiStyle.isInside(mouseX, mouseY, rowLeft, rowY,
+ rowWidth, ROW_HEIGHT);
+ float hover = animator.hover(value, hovered, delta);
+
+ if (hover > 0.01f) {
+ graphics.fillRoundedRect(rowLeft, rowY, rowWidth, ROW_HEIGHT, 4,
+ ClickGuiStyle.argb((int) (10.0f * hover), 0x00FFFFFF));
+ }
+
+ FontRenderer label = ClickGuiStyle.font(graphics, 9.0f);
+ label.drawString(value.getName(), rowLeft + 8,
+ ClickGuiStyle.centeredY(label, rowY, ROW_HEIGHT),
+ ClickGuiStyle.COLOR_TEXT_DIM);
+
+ float right = rowLeft + rowWidth - 8;
+
+ if (value instanceof BooleanValue) {
+ BooleanValue booleanValue = (BooleanValue) value;
+ float toggleWidth = ClickGuiStyle.SMALL_TOGGLE_WIDTH;
+ float toggleHeight = ClickGuiStyle.SMALL_TOGGLE_HEIGHT;
+ ClickGuiStyle.drawSwitch(graphics,
+ right - toggleWidth,
+ rowY + (ROW_HEIGHT - toggleHeight) / 2.0f,
+ toggleWidth, toggleHeight,
+ animator.state(value, booleanValue.isEnabled(), delta));
+ } else if (value instanceof ModeValue) {
+ ModeValue modeValue = (ModeValue) value;
+ FontRenderer modeFont = ClickGuiStyle.font(graphics, 9.0f);
+ String text = "< " + modeValue.getMode() + " >";
+ double pillWidth = modeFont.getStringWidth(text) + 10;
+ double pillX = right - pillWidth;
+
+ graphics.fillRoundedRect(pillX, rowY + 4, pillWidth,
+ ROW_HEIGHT - 8, 4,
+ ClickGuiStyle.argb(16, 0x00FFFFFF));
+ modeFont.drawString(text, pillX + 5,
+ ClickGuiStyle.centeredY(modeFont, rowY, ROW_HEIGHT),
+ ClickGuiStyle.COLOR_ACCENT);
+ } else {
+ FontRenderer valueFont = ClickGuiStyle.font(graphics, 9.0f);
+ String text = String.valueOf(value.getValue());
+ valueFont.drawString(text, right - valueFont.getStringWidth(text),
+ ClickGuiStyle.centeredY(valueFont, rowY, ROW_HEIGHT),
+ ClickGuiStyle.COLOR_TEXT_MUTED);
+ }
+ }
+
+ public static boolean isBackButton(ClickGuiLayout layout, double mouseX,
+ double mouseY) {
+ return ClickGuiStyle.isInside(mouseX, mouseY, layout.contentX(),
+ backTop(layout), BACK_SIZE, BACK_SIZE);
+ }
+
+ /**
+ * @return the index of the settings row under {@code mouseY}, or {@code -1}
+ * when the pointer is between rows.
+ */
+ public static int rowIndexAt(ClickGuiLayout layout,
+ List> settings, float scroll,
+ float mouseY) {
+ if (mouseY < layout.listTop() || mouseY > layout.listBottom()) {
+ return -1;
+ }
+ float local = mouseY - (layout.listTop() - scroll);
+ int index = (int) Math.floor(local / ROW_HEIGHT);
+ return index >= 0 && index < settings.size() ? index : -1;
+ }
+
+ /**
+ * Applies a click to one settings row. Left-click toggles or advances,
+ * right-click steps a mode back; other value types are display-only.
+ */
+ public static void click(List> settings, int index, int button) {
+ if (index < 0 || index >= settings.size()) {
+ return;
+ }
+ if (button != 0 && button != 1) {
+ return;
+ }
+
+ Value> value = settings.get(index);
+ if (value instanceof BooleanValue) {
+ if (button == 0) {
+ ((BooleanValue) value).toggle();
+ }
+ } else if (value instanceof ModeValue) {
+ if (button == 0) {
+ ((ModeValue) value).next();
+ } else {
+ ((ModeValue) value).previous();
+ }
+ }
+ }
+
+ private static float backTop(ClickGuiLayout layout) {
+ return layout.y() + ClickGuiStyle.HEADER_HEIGHT + 8.0f;
+ }
+}
diff --git a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsWindow.java b/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsWindow.java
deleted file mode 100644
index 8586354..0000000
--- a/OrangeX/src/main/java/cn/xiaozhou233/orangex/ui/clickgui/SettingsWindow.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package cn.xiaozhou233.orangex.ui.clickgui;
-
-import cn.xiaozhou233.orangex.modules.Module;
-import cn.xiaozhou233.orangex.render.api.FontRenderer;
-import cn.xiaozhou233.orangex.render.api.Render2D;
-import cn.xiaozhou233.orangex.value.BooleanValue;
-import cn.xiaozhou233.orangex.value.ModeValue;
-import cn.xiaozhou233.orangex.value.Value;
-
-import java.util.List;
-
-/**
- * A small draggable window that shows the settings of one module.
- *
- * Opened by right-clicking a module row in {@link MainPanel}. Clicking
- * outside the window, pressing its close button or closing the GUI dismisses
- * it.
- */
-public final class SettingsWindow {
-
- private static final Object CLOSE_HOVER_KEY = new Object();
-
- private static final float WIDTH = 236f;
- private static final float HEADER_HEIGHT = 30f;
- private static final float ROW_HEIGHT = 22f;
- private static final float BODY_PADDING = 8f;
- private static final float RADIUS = 7f;
- private static final float CLOSE_SIZE = 16f;
-
- private final ClickGuiAnimator animator = new ClickGuiAnimator();
-
- private Module module;
- private List> settings;
-
- private float x;
- private float y;
- private float width;
- private float height;
-
- private int screenWidth = 854;
- private int screenHeight = 480;
-
- private boolean dragging;
- private float dragOffsetX;
- private float dragOffsetY;
-
- public boolean isOpen() {
- return module != null;
- }
-
- public void open(Module module, ClickGuiLayout layout) {
- List> moduleSettings = ClickGuiModules.settingsOf(module);
- if (moduleSettings.isEmpty()) {
- close();
- return;
- }
-
- this.module = module;
- this.settings = moduleSettings;
- this.width = WIDTH;
- this.height = HEADER_HEIGHT + BODY_PADDING * 2.0f
- + moduleSettings.size() * ROW_HEIGHT;
- this.screenWidth = layout.screenWidth();
- this.screenHeight = layout.screenHeight();
- this.dragging = false;
-
- this.x = layout.x() + (layout.width() - width) / 2.0f;
- this.y = layout.y() + (layout.height() - height) / 2.0f;
- this.x = ClickGuiStyle.clamp(x, 4.0f,
- Math.max(4.0f, screenWidth - width - 4.0f));
- this.y = ClickGuiStyle.clamp(y, 4.0f,
- Math.max(4.0f, screenHeight - height - 4.0f));
- this.x = Math.round(x);
- this.y = Math.round(y);
- }
-
- public void close() {
- module = null;
- settings = null;
- dragging = false;
- }
-
- public void render(Render2D graphics, float delta,
- double mouseX, double mouseY) {
- if (!isOpen()) {
- return;
- }
-
- graphics.fillRoundedRect(x - 3, y + 2, width + 6, height + 4,
- RADIUS + 3, 0x26000000);
- graphics.fillRoundedRect(x, y, width, height, RADIUS, 1.0,
- ClickGuiStyle.COLOR_PANEL, ClickGuiStyle.COLOR_BORDER);
-
- FontRenderer title = ClickGuiStyle.font(graphics, 11.0f, true);
- title.drawString(module.getName(), x + 12, y + 7,
- ClickGuiStyle.COLOR_TEXT);
-
- FontRenderer subtitle = ClickGuiStyle.font(graphics, 7.0f, true);
- subtitle.drawString("SETTINGS", x + 12, y + 19,
- ClickGuiStyle.COLOR_TEXT_MUTED);
-
- drawCloseButton(graphics, delta, mouseX, mouseY);
-
- graphics.fillRect(x + 10, y + HEADER_HEIGHT - 1, width - 20, 1,
- ClickGuiStyle.COLOR_DIVIDER);
-
- float rowY = y + HEADER_HEIGHT + BODY_PADDING;
- for (Value> value : settings) {
- drawSettingRow(graphics, value, rowY, delta, mouseX, mouseY);
- rowY += ROW_HEIGHT;
- }
- }
-
- private void drawCloseButton(Render2D graphics, float delta,
- double mouseX, double mouseY) {
- float closeX = x + width - 12 - CLOSE_SIZE;
- float closeY = y + (HEADER_HEIGHT - CLOSE_SIZE) / 2.0f;
- boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY, closeX,
- closeY, CLOSE_SIZE, CLOSE_SIZE);
- float hover = animator.hover(CLOSE_HOVER_KEY, hovered, delta);
-
- if (hover > 0.01f) {
- graphics.fillRoundedRect(closeX, closeY, CLOSE_SIZE, CLOSE_SIZE,
- 4, ClickGuiStyle.argb((int) (22.0f * hover),
- ClickGuiStyle.COLOR_ACCENT_RGB));
- }
-
- FontRenderer close = ClickGuiStyle.font(graphics, 9.0f, true);
- close.drawCenteredString("x", closeX + CLOSE_SIZE / 2.0,
- closeY + (CLOSE_SIZE - close.getStringHeight()) / 2.0,
- hovered ? ClickGuiStyle.COLOR_ACCENT
- : ClickGuiStyle.COLOR_TEXT_MUTED);
- }
-
- private void drawSettingRow(Render2D graphics, Value> value, float rowY,
- float delta, double mouseX, double mouseY) {
- boolean hovered = ClickGuiStyle.isInside(mouseX, mouseY, x + 6, rowY,
- width - 12, ROW_HEIGHT);
- float hover = animator.hover(value, hovered, delta);
-
- if (hover > 0.01f) {
- graphics.fillRoundedRect(x + 6, rowY, width - 12, ROW_HEIGHT, 4,
- ClickGuiStyle.argb((int) (10.0f * hover), 0x00FFFFFF));
- }
-
- FontRenderer label = ClickGuiStyle.font(graphics, 9.0f);
- label.drawString(value.getName(), x + 14,
- ClickGuiStyle.centeredY(label, rowY, ROW_HEIGHT),
- ClickGuiStyle.COLOR_TEXT_DIM);
-
- float right = x + width - 12;
-
- if (value instanceof BooleanValue) {
- BooleanValue booleanValue = (BooleanValue) value;
- float toggleWidth = ClickGuiStyle.SMALL_TOGGLE_WIDTH;
- float toggleHeight = ClickGuiStyle.SMALL_TOGGLE_HEIGHT;
- ClickGuiStyle.drawSwitch(graphics,
- right - toggleWidth,
- rowY + (ROW_HEIGHT - toggleHeight) / 2.0f,
- toggleWidth, toggleHeight,
- animator.state(value, booleanValue.isEnabled(), delta));
- } else if (value instanceof ModeValue) {
- ModeValue modeValue = (ModeValue) value;
- FontRenderer modeFont = ClickGuiStyle.font(graphics, 9.0f);
- String text = "< " + modeValue.getMode() + " >";
- double pillWidth = modeFont.getStringWidth(text) + 10;
- double pillX = right - pillWidth;
-
- graphics.fillRoundedRect(pillX, rowY + 3, pillWidth,
- ROW_HEIGHT - 6, 4,
- ClickGuiStyle.argb(16, 0x00FFFFFF));
- modeFont.drawString(text, pillX + 5,
- ClickGuiStyle.centeredY(modeFont, rowY, ROW_HEIGHT),
- ClickGuiStyle.COLOR_ACCENT);
- } else {
- FontRenderer valueFont = ClickGuiStyle.font(graphics, 9.0f);
- String text = String.valueOf(value.getValue());
- valueFont.drawString(text, right - valueFont.getStringWidth(text),
- ClickGuiStyle.centeredY(valueFont, rowY, ROW_HEIGHT),
- ClickGuiStyle.COLOR_TEXT_MUTED);
- }
- }
-
- /**
- * @return {@code true} when the click was inside the window (and has been
- * consumed), {@code false} when the caller should dismiss it.
- */
- public boolean mouseClicked(float mouseX, float mouseY, int button) {
- if (!isOpen()
- || !ClickGuiStyle.isInside(mouseX, mouseY, x, y,
- width, height)) {
- return false;
- }
-
- float closeX = x + width - 12 - CLOSE_SIZE;
- float closeY = y + (HEADER_HEIGHT - CLOSE_SIZE) / 2.0f;
- if (button == 0 && ClickGuiStyle.isInside(mouseX, mouseY, closeX,
- closeY, CLOSE_SIZE, CLOSE_SIZE)) {
- close();
- return true;
- }
-
- if (ClickGuiStyle.isInside(mouseX, mouseY, x, y,
- width, HEADER_HEIGHT)) {
- if (button == 0) {
- dragging = true;
- dragOffsetX = mouseX - x;
- dragOffsetY = mouseY - y;
- }
- return true;
- }
-
- float rowY = y + HEADER_HEIGHT + BODY_PADDING;
- for (Value> value : settings) {
- if (ClickGuiStyle.isInside(mouseX, mouseY, x + 6, rowY,
- width - 12, ROW_HEIGHT)) {
- applySetting(value, button);
- return true;
- }
- rowY += ROW_HEIGHT;
- }
-
- return true;
- }
-
- public void mouseDragged(float mouseX, float mouseY, int button) {
- if (!isOpen() || !dragging || button != 0) {
- return;
- }
-
- x = ClickGuiStyle.clamp(mouseX - dragOffsetX, 4.0f,
- Math.max(4.0f, screenWidth - width - 4.0f));
- y = ClickGuiStyle.clamp(mouseY - dragOffsetY, 4.0f,
- Math.max(4.0f, screenHeight - height - 4.0f));
- x = Math.round(x);
- y = Math.round(y);
- }
-
- public void mouseReleased(float mouseX, float mouseY, int button) {
- if (button == 0) {
- dragging = false;
- }
- }
-
- private void applySetting(Value> value, int button) {
- if (button != 0 && button != 1) {
- return;
- }
-
- if (value instanceof BooleanValue) {
- if (button == 0) {
- ((BooleanValue) value).toggle();
- }
- } else if (value instanceof ModeValue) {
- ModeValue modeValue = (ModeValue) value;
- if (button == 0) {
- modeValue.next();
- } else {
- modeValue.previous();
- }
- }
- }
-}