diff options
| author | Arslaan Pathan <[email protected]> | 2026-09-26 17:05:36 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-09-26 17:05:36 +1200 |
| commit | 14c68eb5ba16774f581d95a39e64a7b303954ffc (patch) | |
| tree | 2888ef11f47c6a639d440300ef580c247ad1bcb1 /src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java | |
| parent | 766ba1c1d977442332cadaaeca93d795baa559df (diff) | |
| download | arslaansmagichax-14c68eb5ba16774f581d95a39e64a7b303954ffc.tar.xz arslaansmagichax-14c68eb5ba16774f581d95a39e64a7b303954ffc.zip | |
migration to 26.2 - run migrateMappings with old loom then bring it back to new
Diffstat (limited to 'src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java')
| -rw-r--r-- | src/main/java/com/arslaancodes/arslaansmagichax/screens/clickgui/Frame.java | 124 |
1 files changed, 124 insertions, 0 deletions
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; + } + } + } + } + } +} |
