1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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);
}
}
}
|