diff options
Diffstat (limited to 'src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens')
3 files changed, 201 insertions, 0 deletions
diff --git a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIFrame.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIFrame.java new file mode 100644 index 0000000..0958162 --- /dev/null +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIFrame.java @@ -0,0 +1,97 @@ +package net.justlearning.arslaan3102.arslaansmagichax.screens; + +import net.justlearning.arslaan3102.arslaansmagichax.modules.Category; +import net.justlearning.arslaan3102.arslaansmagichax.modules.Module; +import net.justlearning.arslaan3102.arslaansmagichax.modules.ModuleManager; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class ClickGUIFrame { + public int x, y, width, height, dragX, dragY; + public Category category; + + public boolean dragging; + + public boolean isOpen = false; + + private List<ClickGUIModuleButton> buttons; + + protected MinecraftClient mc = MinecraftClient.getInstance(); + + public ClickGUIFrame(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)) { + if (!Objects.equals(module.getName(), "ClickGUI")) { + buttons.add(new ClickGUIModuleButton(module, this, offset)); + offset += height; + } + } + } + + public void render(DrawContext 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 textWidth = mc.textRenderer.getWidth(text); + int textX = x + (width - textWidth) / 2; + int textY = y + (height - mc.textRenderer.fontHeight) / 2; + + context.drawText(mc.textRenderer, Text.literal(text), textX, textY, new Color(30, 30, 47, 255).getRGB(), false); + + if (isOpen) { + for (ClickGUIModuleButton 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 (ClickGUIModuleButton moduleButton : buttons) { + moduleButton.mouseClicked(mouseX, mouseY, button); + } + } + } + + public void mouseReleased(double mouseX, double mouseY, int button) { + if (button == 0 && dragging) { + dragging = false; + } + } + + 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); + } + } +} diff --git a/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIModuleButton.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIModuleButton.java new file mode 100644 index 0000000..a1090a5 --- /dev/null +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIModuleButton.java @@ -0,0 +1,45 @@ +package net.justlearning.arslaan3102.arslaansmagichax.screens; + +import net.justlearning.arslaan3102.arslaansmagichax.modules.Module; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.text.Text; + +import java.awt.Color; + +public class ClickGUIModuleButton { + + public Module module; + public ClickGUIFrame parent; + public int offset; + + public ClickGUIModuleButton(Module module, ClickGUIFrame parent, int offset) { + this.module = module; + this.parent = parent; + this.offset = offset; + } + + public void render(DrawContext 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()); + + String text = module.getName(); + + int textX = parent.x + 5; + int textY = parent.y + offset + (parent.height - parent.mc.textRenderer.fontHeight) / 2; + + int textColor = module.isEnabled() ? new Color(252, 210, 77, 255).getRGB() : Color.white.getRGB(); + + context.drawTextWithShadow(parent.mc.textRenderer, Text.literal(text), textX, textY, textColor); + } + + public void mouseClicked(double mouseX, double mouseY, int button) { + if (isHovered(mouseX, mouseY) && button == 0) { + module.toggle(); + } + } + + 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/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIScreen.java b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIScreen.java new file mode 100644 index 0000000..0e33107 --- /dev/null +++ b/src/main/java/net/justlearning/arslaan3102/arslaansmagichax/screens/ClickGUIScreen.java @@ -0,0 +1,59 @@ +package net.justlearning.arslaan3102.arslaansmagichax.screens; + +import net.justlearning.arslaan3102.arslaansmagichax.ArslaansMagicHaxClient; +import net.justlearning.arslaan3102.arslaansmagichax.modules.Category; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.List; + +public class ClickGUIScreen extends Screen { + public static final ClickGUIScreen INSTANCE = new ClickGUIScreen(); + + private List<ClickGUIFrame> frames; + + private ClickGUIScreen() { + super(Text.literal("ClickGUI")); + + frames = new ArrayList<>(); + + int offset = 20; + for (Category category : Category.values()) { + frames.add(new ClickGUIFrame(category, offset, 30, 100, 30)); + offset += 120; + } + } + + @Override + public void render(DrawContext context, int mouseX, int mouseY, float deltaTicks) { + for (ClickGUIFrame 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 (ClickGUIFrame frame : frames) { + frame.mouseClicked(mouseX, mouseY, button); + } + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseReleased(double mouseX, double mouseY, int button) { + for (ClickGUIFrame frame : frames) { + frame.mouseReleased(mouseX, mouseY, button); + } + return super.mouseReleased(mouseX, mouseY, button); + } + + @Override + public void close() { + super.close(); + ArslaansMagicHaxClient.clickGUI.setEnabled(false); + } +} |
