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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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.SettingComponent;
import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
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(GuiGraphicsExtractor 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.text(mc.font, net.minecraft.network.chat.Component.literal(text), x + 5, textY, new Color(30, 30, 47, 255).getRGB(), false);
context.text(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 (SettingComponent 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;
}
}
}
}
}
}
|