mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
[Perf] ClickGUI and Component display
This commit is contained in:
1 parent
b9da2830fc
commit
634f6fd34f
9 files changed
+41
-12
No files matched your search
@@ -15,4 +15,5 @@ public class FontManager {
|
||||
public FontRenderer MontserratBold32 = new FontRenderer("Montserrat-Bold.ttf", 32, Font.PLAIN, true, true);
|
||||
|
||||
public FontRenderer JelloMedium32 = new FontRenderer("JelloMedium.ttf", 32, Font.PLAIN, true, true);
|
||||
public FontRenderer JelloRegular16 = new FontRenderer("JelloRegular.ttf", 16, Font.PLAIN, true, true);
|
||||
}
|
||||
@@ -9,14 +9,29 @@ import cn.xiaozhou233.orangex.module.value.KeybindValue;
|
||||
import cn.xiaozhou233.orangex.module.value.ModeValue;
|
||||
import cn.xiaozhou233.orangex.module.value.NumberValue;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Test extends Module{
|
||||
|
||||
public Test() {
|
||||
super("Test", ModuleCategory.MISC);
|
||||
|
||||
// Boolean Examples
|
||||
addValue(new BooleanValue("Example Boolean1", "Example", true));
|
||||
addValue(new BooleanValue("Example Boolean2", "Example", false));
|
||||
|
||||
// Keybinding Examples
|
||||
addValue(new KeybindValue("Example1", "Example", 0));
|
||||
addValue(new KeybindValue("Example2", "Example", Keyboard.KEY_RSHIFT));
|
||||
|
||||
// Mode Examples
|
||||
addValue(new ModeValue("Example Mode", "Example", "ModeA", new ArrayList<>(Arrays.asList("ModeA", "ModeB", "ModeC"))));
|
||||
|
||||
// Number Examples
|
||||
addValue(new NumberValue("Example Number", "Example", 0.0, 0, 100, 0.1));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -20,9 +20,10 @@ import java.util.List;
|
||||
|
||||
public class ClickGuiScreen extends GuiScreen {
|
||||
|
||||
// Category
|
||||
private final List<Panel> panels = new ArrayList<>();
|
||||
|
||||
// 当前正在拖拽的面板
|
||||
// Dragging
|
||||
private Panel draggingPanel = null;
|
||||
|
||||
@Override
|
||||
@@ -74,23 +75,20 @@ public class ClickGuiScreen extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
// 从后往前,优先处理最上层面板
|
||||
for (int i = panels.size() - 1; i >= 0; i--) {
|
||||
Panel panel = panels.get(i);
|
||||
|
||||
if (panel.isHovered(mouseX, mouseY) || panel.isHeaderHovered(mouseX, mouseY)) {
|
||||
// 置顶:把点击的面板放到列表末尾(最后渲染)
|
||||
panels.remove(panel);
|
||||
panels.add(panel);
|
||||
|
||||
panel.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
|
||||
// 记录拖拽面板
|
||||
if (mouseButton == 0 && panel.isHeaderHovered(mouseX, mouseY)) {
|
||||
draggingPanel = panel;
|
||||
}
|
||||
|
||||
return; // 阻止下面面板响应
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+14
@@ -1,5 +1,7 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component;
|
||||
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.render.GuiRenderUtils;
|
||||
|
||||
public abstract class ValueComponent extends Component {
|
||||
|
||||
public ValueComponent(double x, double y, double width, double height, Component parent) {
|
||||
@@ -7,4 +9,16 @@ public abstract class ValueComponent extends Component {
|
||||
}
|
||||
|
||||
public abstract void applyValue();
|
||||
|
||||
protected void drawBackground(int mouseX, int mouseY) {
|
||||
double ax = getAbsoluteX();
|
||||
double ay = getAbsoluteY();
|
||||
|
||||
int bgColor = 0xFF333333;
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
bgColor = GuiRenderUtils.blendColor(bgColor, 0xFFFFFFFF, 0.12f);
|
||||
}
|
||||
GuiRenderUtils.drawRect(ax, ay, width, height, bgColor);
|
||||
}
|
||||
|
||||
}
|
||||
+4
-2
@@ -10,7 +10,7 @@ public class BooleanComponent extends ValueComponent {
|
||||
private final BooleanValue value;
|
||||
|
||||
public BooleanComponent(double x, double y, double width, BooleanValue value, Component parent) {
|
||||
super(x, y, width, 14, parent);
|
||||
super(x, y, width, 16, parent);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -24,15 +24,17 @@ public class BooleanComponent extends ValueComponent {
|
||||
double boxY = ay + (height - boxSize) / 2;
|
||||
|
||||
int boxColor = value.getValue() ? 0xFF2E8B57 : 0xFF444444;
|
||||
|
||||
if (isHovered(mouseX, mouseY)) {
|
||||
boxColor = GuiRenderUtils.blendColor(boxColor, 0xFFFFFFFF, 0.12f);
|
||||
}
|
||||
|
||||
GuiRenderUtils.enableBlend();
|
||||
|
||||
drawBackground(mouseX, mouseY);
|
||||
GuiRenderUtils.drawRect(boxX, boxY, boxSize, boxSize, boxColor);
|
||||
|
||||
GuiRenderUtils.drawString(value.getName(), ax + 4 + boxSize + 6, ay + 4, 0xFFFFFFFF);
|
||||
GuiRenderUtils.drawString(value.getName(), ax + 4 + boxSize + 6, ay + 6, 0xFFFFFFFF);
|
||||
|
||||
GuiRenderUtils.disableBlend();
|
||||
}
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ public class KeybindComponent extends ValueComponent {
|
||||
private boolean listening = false;
|
||||
|
||||
public KeybindComponent(double x, double y, double width, KeybindValue value, Component parent) {
|
||||
super(x, y, width, 14, parent);
|
||||
super(x, y, width, 16, parent);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ public class ModeComponent extends ValueComponent {
|
||||
private final ModeValue value;
|
||||
|
||||
public ModeComponent(double x, double y, double width, ModeValue value, Component parent) {
|
||||
super(x, y, width, 14, parent);
|
||||
super(x, y, width, 16, parent);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -40,7 +40,7 @@ public class ModuleButton extends Component {
|
||||
int statusColor = module.isEnabled() ? 0xFF00FF00 : 0xFF888888;
|
||||
GuiRenderUtils.drawRect(ax, ay, 2, baseHeight, statusColor);
|
||||
|
||||
GuiRenderUtils.drawString(module.getName(), ax + 6, ay + 5, 0xFFFFFFFF);
|
||||
GuiRenderUtils.drawString(module.getName(), ax + 6, ay + 6, 0xFFFFFFFF);
|
||||
GuiRenderUtils.disableBlend();
|
||||
|
||||
if (!expanded) {
|
||||
@@ -90,7 +90,6 @@ public class ModuleButton extends Component {
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int mouseX, int mouseY, int button) {
|
||||
// IMPORTANT: always propagate release to children
|
||||
for (Component component : components) {
|
||||
component.mouseReleased(mouseX, mouseY, button);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class GuiRenderUtils {
|
||||
}
|
||||
|
||||
public static void drawString(String text, double x, double y, int color) {
|
||||
OrangeX.getFontManager().MontserratRegular18
|
||||
OrangeX.getFontManager().JelloRegular16
|
||||
.drawString(text, (float) x, (float) y, color);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user