[Fix] ClickGUI panel layout overflow & position safety

This commit is contained in:
xiaozhou233 committed 2026-01-24 20:36:04 +08:00
1 parent 969699edae
commit 3d55afcca2
1 file changed
+32 -10
@@ -14,6 +14,7 @@ import cn.xiaozhou233.orangex.ui.clickgui.component.impl.ModeComponent;
import cn.xiaozhou233.orangex.ui.clickgui.component.impl.KeybindComponent; import cn.xiaozhou233.orangex.ui.clickgui.component.impl.KeybindComponent;
import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
@@ -32,22 +33,43 @@ public class ClickGuiScreen extends GuiScreen {
public void initGui() { public void initGui() {
panels.clear(); panels.clear();
double startX = 20; ScaledResolution sr = new ScaledResolution(mc);
double startY = 20; double screenWidth = sr.getScaledWidth_double();
double screenHeight = sr.getScaledHeight_double();
double margin = 20;
double startX = margin;
double startY = margin;
double panelWidth = 120; double panelWidth = 120;
double panelHeaderHeight = 20;
double gap = 10; double gap = 10;
for (ModuleCategory category : ModuleCategory.values()) { for (ModuleCategory category : ModuleCategory.values()) {
if (startX + panelWidth > screenWidth - margin) {
// Load Position from panel.json startX = margin;
PanelPosition position = OrangeX.getInstance().getConfigManager().getPanelPosition(category.name()); startY += panelHeaderHeight + gap;
Panel panel;
if (position == null) {
panel = new Panel(category.name(), startX, startY, panelWidth);
} else {
panel = new Panel(category.name(), position.getX(), position.getY(), panelWidth);
} }
PanelPosition position =
OrangeX.getInstance().getConfigManager().getPanelPosition(category.name());
double x = startX;
double y = startY;
if (position != null) {
x = Math.max(
0,
Math.min(position.getX(), screenWidth - panelWidth)
);
y = Math.max(
0,
Math.min(position.getY(), screenHeight - panelHeaderHeight)
);
}
Panel panel = new Panel(category.name(), x, y, panelWidth);
for (Module module : OrangeX.getInstance().getModuleManager().getModulesByCategory(category)) { for (Module module : OrangeX.getInstance().getModuleManager().getModulesByCategory(category)) {
ModuleButton button = new ModuleButton(0, 0, panelWidth, module, panel); ModuleButton button = new ModuleButton(0, 0, panelWidth, module, panel);