summaryrefslogtreecommitdiff
path: root/src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java')
-rw-r--r--src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/ModuleButton.java97
1 files changed, 97 insertions, 0 deletions
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;
+ }
+}