summaryrefslogtreecommitdiff
path: root/src/main/java/com/arslaancodes/arslaansmagichax/screens
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/arslaancodes/arslaansmagichax/screens')
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ClickGUIScreen.java82
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java124
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java97
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/CheckBox.java50
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Component.java37
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/KeybindingSelector.java74
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/ModeBox.java56
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Slider.java92
8 files changed, 612 insertions, 0 deletions
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ClickGUIScreen.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ClickGUIScreen.java
new file mode 100644
index 0000000..962a18e
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ClickGUIScreen.java
@@ -0,0 +1,82 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui;
+
+import com.arslaancodes.arslaansmagichax.ArslaansMagicHaxClient;
+import com.arslaancodes.arslaansmagichax.modules.Category;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.setting.Component;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.setting.KeybindingSelector;
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.client.gui.screens.Screen;
+
+public class ClickGUIScreen extends Screen {
+ public static final ClickGUIScreen INSTANCE = new ClickGUIScreen();
+
+ private List<Frame> frames;
+
+ private ClickGUIScreen() {
+ super(net.minecraft.network.chat.Component.literal("ClickGUI"));
+
+ frames = new ArrayList<>();
+
+ int offset = 20;
+ for (Category category : Category.values()) {
+ frames.add(new Frame(category, offset, 30, 100, 20));
+ offset += 120;
+ }
+ }
+
+ @Override
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ for (Frame frame : frames) {
+ frame.render(context, mouseX, mouseY, deltaTicks);
+ frame.updatePosition(mouseX, mouseY);
+ }
+ super.render(context, mouseX, mouseY, deltaTicks);
+ }
+
+ @Override
+ public boolean mouseClicked(double mouseX, double mouseY, int button) {
+ for (Frame frame : frames) {
+ frame.mouseClicked(mouseX, mouseY, button);
+ }
+ return super.mouseClicked(mouseX, mouseY, button);
+ }
+
+ @Override
+ public boolean mouseReleased(double mouseX, double mouseY, int button) {
+ for (Frame frame : frames) {
+ frame.mouseReleased(mouseX, mouseY, button);
+ }
+ return super.mouseReleased(mouseX, mouseY, button);
+ }
+
+ @Override
+ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
+ for (Frame frame : frames) {
+ if (frame.isOpen) {
+ for (ModuleButton button : frame.getButtons()) {
+ if (button.extended) {
+ for (Component comp : button.components) {
+ if (comp instanceof KeybindingSelector keybindingSelector) {
+ keybindingSelector.onKeyPressed(keyCode);
+ }
+ }
+ }
+ }
+ }
+ }
+ return super.keyPressed(keyCode, scanCode, modifiers);
+ }
+
+ @Override
+ public boolean isPauseScreen() {
+ return false;
+ }
+
+ @Override
+ public void onClose() {
+ super.onClose();
+ ArslaansMagicHaxClient.clickGUI.setEnabled(false);
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java
new file mode 100644
index 0000000..6a99973
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java
@@ -0,0 +1,124 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui;
+
+import com.arslaancodes.arslaansmagichax.modules.Category;
+import com.arslaancodes.arslaansmagichax.modules.Module;
+import com.arslaancodes.arslaansmagichax.modules.ModuleManager;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.setting.Component;
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiGraphics;
+
+public class Frame {
+ public int x, y, width, height, dragX, dragY;
+ public Category category;
+
+ public boolean dragging;
+
+ public boolean isOpen = false;
+
+ private List<ModuleButton> buttons;
+
+ protected Minecraft mc = Minecraft.getInstance();
+
+ public Frame(Category category, int x, int y, int width, int height) {
+ this.category = category;
+ this.x = x;
+ this.y = y;
+ this.width = width;
+ this.height = height;
+ this.dragging = false;
+
+ buttons = new ArrayList<>();
+
+ int offset = height;
+ for (Module module : ModuleManager.INSTANCE.getModulesWithCategory(category)) {
+ buttons.add(new ModuleButton(module, this, offset));
+ offset += height;
+ }
+ }
+
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ context.fill(x, y, x + width, y + height, new Color(252, 210, 77, 255).getRGB());
+
+ String text = category.name();
+ int textY = y + (height - mc.font.lineHeight) / 2;
+
+ context.drawString(mc.font, net.minecraft.network.chat.Component.literal(text), x + 5, textY, new Color(30, 30, 47, 255).getRGB(), false);
+ context.drawString(mc.font, isOpen ? "-" : "+", x + width - 5 - mc.font.width("+"), textY, new Color(30, 30, 47, 255).getRGB(), false);
+
+ if (isOpen) {
+ for (ModuleButton button : buttons) {
+ button.render(context, mouseX, mouseY, deltaTicks);
+ }
+ }
+ }
+
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+ if (isHovered(mouseX, mouseY)) {
+ if (button == 0) {
+ dragging = true;
+ dragX = (int) (mouseX - x);
+ dragY = (int) (mouseY - y);
+ } else {
+ isOpen = !isOpen;
+ }
+ }
+
+ if (isOpen) {
+ for (ModuleButton moduleButton : buttons) {
+ moduleButton.mouseClicked(mouseX, mouseY, button);
+ }
+ }
+ }
+
+ public void mouseReleased(double mouseX, double mouseY, int button) {
+ if (button == 0 && dragging) {
+ dragging = false;
+ }
+
+ if (isOpen) {
+ for (ModuleButton moduleButton : buttons) {
+ moduleButton.mouseReleased(mouseX, mouseY, button);
+ }
+ }
+ }
+
+ public boolean isHovered(double mouseX, double mouseY) {
+ return mouseX > x && mouseX < x + width && mouseY > y && mouseY < y + height;
+ }
+
+ public void updatePosition(double mouseX, double mouseY) {
+ if (dragging) {
+ x = (int) (mouseX - dragX);
+ y = (int) (mouseY - dragY);
+ }
+ }
+
+ public List<ModuleButton> getButtons() {
+ return buttons;
+ }
+
+ public void updateButtons() {
+ int offset = height;
+
+ for (ModuleButton button : buttons) {
+ button.offset = offset;
+ offset += height;
+
+ if (button.extended) {
+ for (Component component : button.components) {
+ if (component.setting != null) {
+ if (component.setting.isVisible()) {
+ offset += height;
+ }
+ } else {
+ // this is 99.99% the keybinding thing, just add offset anyway and hope it works i guess
+ offset += height;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java
new file mode 100644
index 0000000..796c65e
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java
@@ -0,0 +1,97 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui;
+
+import com.arslaancodes.arslaansmagichax.modules.Module;
+import com.arslaancodes.arslaansmagichax.modules.settings.BooleanSetting;
+import com.arslaancodes.arslaansmagichax.modules.settings.ModeSetting;
+import com.arslaancodes.arslaansmagichax.modules.settings.NumberSetting;
+import com.arslaancodes.arslaansmagichax.modules.settings.Setting;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.setting.*;
+import java.awt.Color;
+import java.util.ArrayList;
+import java.util.List;
+import net.minecraft.client.gui.GuiGraphics;
+
+public class ModuleButton {
+
+ public Module module;
+ public Frame parent;
+ public int offset;
+ public List<Component> components;
+ public boolean extended;
+
+ public ModuleButton(Module module, Frame parent, int offset) {
+ this.module = module;
+ this.parent = parent;
+ this.offset = offset;
+ this.extended = false;
+ this.components = new ArrayList<>();
+
+ int setOffset = parent.height;
+ components.add(new KeybindingSelector(this, setOffset));
+ setOffset += parent.height;
+ for (Setting setting : module.getSettings()) {
+ if (setting instanceof BooleanSetting) {
+ components.add(new CheckBox(setting, this, setOffset));
+ } else if (setting instanceof ModeSetting) {
+ components.add(new ModeBox(setting, this, setOffset));
+ } else if (setting instanceof NumberSetting) {
+ components.add(new Slider(setting, this, setOffset));
+ }
+ setOffset += parent.height;
+ }
+ }
+
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ int alpha = isHovered(mouseX, mouseY) ? 230 : 160;
+
+ context.fill(parent.x, parent.y + offset, parent.x + parent.width, parent.y + offset + parent.height, new Color(30, 30, 47, alpha).getRGB());
+
+ if (isHovered(mouseX, mouseY)) {
+ context.setTooltipForNextFrame(net.minecraft.network.chat.Component.literal(module.getDescription()), mouseX, mouseY);
+ }
+
+ String text = module.getName();
+
+ int textX = parent.x + 5;
+ int textY = parent.y + offset + (parent.height - parent.mc.font.lineHeight) / 2;
+
+ int textColor = module.isEnabled() ? new Color(252, 210, 77, 255).getRGB() : Color.white.getRGB();
+
+ context.drawString(parent.mc.font, net.minecraft.network.chat.Component.literal(text), textX, textY, textColor);
+
+ if (extended) {
+ for (Component component : components) {
+ component.render(context, mouseX, mouseY, deltaTicks);
+ }
+ }
+ }
+
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+ if (isHovered(mouseX, mouseY)) {
+ if (button == 0) {
+ module.toggle();
+ }
+ else if (button == 1) {
+ extended = !extended;
+ parent.updateButtons();
+ }
+ }
+
+ for (Component component : components) {
+ component.mouseClicked(mouseX, mouseY, button);
+ }
+ }
+
+ public void mouseReleased(double mouseX, double mouseY, int button) {
+ // luigi wins by doing absolutely nothing
+
+ // nevermind we did something
+ for (Component component : components) {
+ component.mouseReleased(mouseX, mouseY, button);
+ }
+ }
+
+ public boolean isHovered(double mouseX, double mouseY) {
+ return mouseX > parent.x && mouseX < parent.x + parent.width && mouseY > parent.y + offset && mouseY < parent.y + offset + parent.height;
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/CheckBox.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/CheckBox.java
new file mode 100644
index 0000000..2dacd2f
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/CheckBox.java
@@ -0,0 +1,50 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui.setting;
+
+import com.arslaancodes.arslaansmagichax.modules.settings.BooleanSetting;
+import com.arslaancodes.arslaansmagichax.modules.settings.Setting;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.ModuleButton;
+import java.awt.*;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.network.chat.Component;
+
+public class CheckBox extends Component {
+
+ private BooleanSetting booleanSetting = (BooleanSetting) setting;
+
+ public CheckBox(Setting setting, ModuleButton parent, int offset) {
+ super(setting, parent, offset);
+ this.booleanSetting = (BooleanSetting) setting;
+ }
+
+ @Override
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ String displayText = booleanSetting.getName() + ": " + booleanSetting.isEnabled();
+ int textWidth = mc.font.width(displayText);
+ int padding = 5;
+ int boxWidth = Math.max(parent.parent.width, textWidth + (padding * 2));
+
+ int alpha = isHovered(mouseX, mouseY) ? 230 : 160;
+ context.fill(
+ parent.parent.x,
+ parent.parent.y + parent.offset + offset,
+ parent.parent.x + boxWidth,
+ parent.parent.y + parent.offset + offset + parent.parent.height,
+ new Color(30, 30, 47, alpha).getRGB()
+ );
+
+ context.drawString(
+ mc.font,
+ Component.literal(displayText),
+ parent.parent.x + padding,
+ parent.parent.y + parent.offset + offset + (parent.parent.height - mc.font.lineHeight) / 2,
+ Color.white.getRGB()
+ );
+ }
+
+ @Override
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+ if (isHovered(mouseX, mouseY) && button == 0) {
+ booleanSetting.toggle();
+ }
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Component.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Component.java
new file mode 100644
index 0000000..96a3bbd
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Component.java
@@ -0,0 +1,37 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui.setting;
+
+import com.arslaancodes.arslaansmagichax.modules.settings.Setting;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.ModuleButton;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.GuiGraphics;
+
+public class Component {
+
+ public Setting setting;
+ public ModuleButton parent;
+ public int offset;
+
+ protected static Minecraft mc = Minecraft.getInstance();
+
+ public Component(Setting setting, ModuleButton parent, int offset) {
+ this.setting = setting;
+ this.parent = parent;
+ this.offset = offset;
+ }
+
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+
+ }
+
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+
+ }
+
+ public void mouseReleased(double mouseX, double mouseY, int button) {
+
+ }
+
+ public boolean isHovered(double mouseX, double mouseY) {
+ return mouseX > parent.parent.x && mouseX < parent.parent.x + parent.parent.width && mouseY > parent.parent.y + parent.offset + offset && mouseY < parent.parent.y + parent.offset + offset + parent.parent.height;
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/KeybindingSelector.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/KeybindingSelector.java
new file mode 100644
index 0000000..a29c3a2
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/KeybindingSelector.java
@@ -0,0 +1,74 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui.setting;
+
+import com.arslaancodes.arslaansmagichax.screens.clickgui.ModuleButton;
+import org.lwjgl.glfw.GLFW;
+
+import java.awt.*;
+import net.minecraft.client.gui.GuiGraphics;
+
+public class KeybindingSelector extends Component {
+
+ private boolean listening = false;
+
+ public KeybindingSelector(ModuleButton parent, int offset) {
+ super(null, parent, offset);
+ }
+
+ @Override
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ int alpha = isHovered(mouseX, mouseY) ? 230 : 160;
+ context.fill(parent.parent.x, parent.parent.y + parent.offset + offset, parent.parent.x + parent.parent.width, parent.parent.y + parent.offset + offset + parent.parent.height, new Color(30, 30, 47, alpha).getRGB());
+
+ if (listening) {
+ context.fill(parent.parent.x, parent.parent.y + parent.offset + offset, parent.parent.x + parent.parent.width, parent.parent.y + parent.offset + offset + parent.parent.height, new Color(252, 210, 77, 255).getRGB());
+ }
+
+ String displayText = listening ? "Press a key..." : "Keybind: " + getKeyName(parent.module.getGlfwKeybinding());
+ context.drawString(mc.font, displayText, parent.parent.x + 5, parent.parent.y + parent.offset + offset + (parent.parent.height - mc.font.lineHeight) / 2, Color.white.getRGB());
+ }
+
+ @Override
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+ if (isHovered(mouseX, mouseY) && button == 0) {
+ listening = !listening;
+ }
+ }
+
+ public void onKeyPressed(int keyCode) {
+ if (!listening) return;
+
+ listening = false;
+
+ if (keyCode == GLFW.GLFW_KEY_ESCAPE || keyCode == GLFW.GLFW_KEY_DELETE || keyCode == GLFW.GLFW_KEY_BACKSPACE) {
+ // remove bingdingd AHH I CANT SPELL
+ parent.module.setGlfwKeybinding(-1);
+ return;
+ }
+
+ parent.module.setGlfwKeybinding(keyCode);
+ }
+
+ private String getKeyName(int key) {
+ if (key == -1) return "NONE";
+ String name = GLFW.glfwGetKeyName(key, 0);
+
+ if (name != null) return name.toUpperCase();
+
+ return switch (key) {
+ case GLFW.GLFW_KEY_LEFT_SHIFT -> "LSHIFT";
+ case GLFW.GLFW_KEY_RIGHT_SHIFT -> "RSHIFT";
+ case GLFW.GLFW_KEY_LEFT_CONTROL -> "LCTRL";
+ case GLFW.GLFW_KEY_RIGHT_CONTROL -> "RCTRL";
+ case GLFW.GLFW_KEY_LEFT_ALT -> "LALT";
+ case GLFW.GLFW_KEY_RIGHT_ALT -> "RALT";
+ case GLFW.GLFW_KEY_SPACE -> "SPACE";
+ case GLFW.GLFW_KEY_TAB -> "TAB";
+ case GLFW.GLFW_KEY_ENTER -> "ENTER";
+ case GLFW.GLFW_KEY_UP -> "UP";
+ case GLFW.GLFW_KEY_DOWN -> "DOWN";
+ case GLFW.GLFW_KEY_LEFT -> "LEFT";
+ case GLFW.GLFW_KEY_RIGHT -> "RIGHT";
+ default -> "KEY_" + key;
+ };
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/ModeBox.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/ModeBox.java
new file mode 100644
index 0000000..1200fa0
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/ModeBox.java
@@ -0,0 +1,56 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui.setting;
+
+import com.arslaancodes.arslaansmagichax.modules.settings.ModeSetting;
+import com.arslaancodes.arslaansmagichax.modules.settings.Setting;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.ModuleButton;
+import java.awt.*;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.network.chat.Component;
+
+public class ModeBox extends Component {
+
+ private ModeSetting modeSetting = (ModeSetting) setting;
+
+ public ModeBox(Setting setting, ModuleButton parent, int offset) {
+ super(setting, parent, offset);
+ this.modeSetting = (ModeSetting) setting;
+ }
+
+ @Override
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ String displayText = modeSetting.getName() + ": " + modeSetting.getMode();
+ int textWidth = mc.font.width(displayText);
+
+ int padding = 5;
+ int boxWidth = Math.max(parent.parent.width, textWidth + padding * 2);
+
+ int alpha = isHovered(mouseX, mouseY) ? 230 : 160;
+ context.fill(
+ parent.parent.x,
+ parent.parent.y + parent.offset + offset,
+ parent.parent.x + boxWidth,
+ parent.parent.y + parent.offset + offset + parent.parent.height,
+ new Color(30, 30, 47, alpha).getRGB()
+ );
+
+ context.drawString(
+ mc.font,
+ Component.literal(displayText),
+ parent.parent.x + padding, // left padding
+ parent.parent.y + parent.offset + offset + (parent.parent.height - mc.font.lineHeight) / 2,
+ Color.white.getRGB()
+ );
+ }
+
+ @Override
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+ if (isHovered(mouseX, mouseY) && button == 0) {
+ modeSetting.cycle();
+ }
+ }
+
+ @Override
+ public void mouseReleased(double mouseX, double mouseY, int button) {
+ super.mouseReleased(mouseX, mouseY, button);
+ }
+}
diff --git a/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Slider.java b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Slider.java
new file mode 100644
index 0000000..bacefd6
--- /dev/null
+++ b/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/setting/Slider.java
@@ -0,0 +1,92 @@
+package com.arslaancodes.arslaansmagichax.screens.clickgui.setting;
+
+import com.arslaancodes.arslaansmagichax.modules.settings.NumberSetting;
+import com.arslaancodes.arslaansmagichax.modules.settings.Setting;
+import com.arslaancodes.arslaansmagichax.screens.clickgui.ModuleButton;
+import java.awt.*;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import net.minecraft.client.gui.GuiGraphics;
+import net.minecraft.network.chat.Component;
+
+public class Slider extends Component {
+
+ public NumberSetting numberSetting = (NumberSetting) setting;
+
+ private boolean sliding = false;
+
+ public Slider(Setting setting, ModuleButton parent, int offset) {
+ super(setting, parent, offset);
+ this.numberSetting = (NumberSetting) setting;
+ }
+
+ @Override
+ public void render(GuiGraphics context, int mouseX, int mouseY, float deltaTicks) {
+ String displayText = numberSetting.getName() + ": " + numberSetting.getValue();
+ int defaultPadding = 5;
+ int boxWidth = parent.parent.width;
+
+ int alpha = isHovered(mouseX, mouseY) ? 230 : 160;
+
+ context.fill(
+ parent.parent.x,
+ parent.parent.y + parent.offset + offset,
+ parent.parent.x + boxWidth,
+ parent.parent.y + parent.offset + offset + parent.parent.height,
+ new Color(30, 30, 47, alpha).getRGB()
+ );
+
+ double diff = Math.min(boxWidth, Math.max(0, mouseX - parent.parent.x));
+ int renderWidth = (int) (boxWidth * (numberSetting.getValue() - numberSetting.getMin()) / (numberSetting.getMax() - numberSetting.getMin()));
+
+ context.fill(
+ parent.parent.x,
+ parent.parent.y + parent.offset + offset,
+ parent.parent.x + renderWidth,
+ parent.parent.y + parent.offset + offset + parent.parent.height,
+ new Color(252, 210, 77, 255).getRGB()
+ );
+
+ if (sliding) {
+ if (diff == 0) {
+ numberSetting.setValue(numberSetting.getMin());
+ } else {
+ numberSetting.setValue(roundToPlace((diff / boxWidth) * (numberSetting.getMax() - numberSetting.getMin()) + numberSetting.getMin(), 1));
+ }
+ }
+
+ int textWidth = mc.font.width(displayText);
+ int leftPadding = defaultPadding;
+ if (textWidth + 2 * defaultPadding > boxWidth) {
+ leftPadding = Math.max(2, boxWidth - textWidth - 2);
+ }
+
+ context.drawString(
+ mc.font,
+ Component.literal(displayText),
+ parent.parent.x + leftPadding,
+ parent.parent.y + parent.offset + offset + (parent.parent.height - mc.font.lineHeight) / 2,
+ Color.white.getRGB()
+ );
+ }
+
+ @Override
+ public void mouseClicked(double mouseX, double mouseY, int button) {
+ if (isHovered(mouseX, mouseY)) sliding = true;
+ }
+
+ @Override
+ public void mouseReleased(double mouseX, double mouseY, int button) {
+ sliding = false;
+ }
+
+ private double roundToPlace(double value, int place) {
+ if (place < 0) {
+ return value;
+ }
+
+ BigDecimal bd = new BigDecimal(value);
+ bd = bd.setScale(place, RoundingMode.HALF_UP);
+ return bd.doubleValue();
+ }
+}