forked from FPSMasterTeam/FPSMaster-Edge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPanel.java
More file actions
379 lines (318 loc) · 11.8 KB
/
MainPanel.java
File metadata and controls
379 lines (318 loc) · 11.8 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
package top.fpsmaster.ui.click;
import top.fpsmaster.utils.render.gui.UiScale;
import top.fpsmaster.utils.render.state.Alpha;
import top.fpsmaster.utils.render.draw.Images;
import top.fpsmaster.utils.render.draw.Hover;
import top.fpsmaster.utils.render.draw.Colors;
import top.fpsmaster.utils.render.draw.Rects;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import top.fpsmaster.FPSMaster;
import top.fpsmaster.exception.FileException;
import top.fpsmaster.features.manager.Category;
import top.fpsmaster.features.manager.Module;
import top.fpsmaster.modules.logger.ClientLogger;
import top.fpsmaster.ui.click.component.ScrollContainer;
import top.fpsmaster.ui.click.modules.ModuleRenderer;
import top.fpsmaster.utils.math.anim.AnimMath;
import top.fpsmaster.utils.math.anim.AnimClock;
import top.fpsmaster.utils.math.anim.Animator;
import top.fpsmaster.utils.math.anim.BezierEasing;
import top.fpsmaster.utils.math.anim.Easings;
import top.fpsmaster.utils.render.gui.ScaledGuiScreen;
import top.fpsmaster.utils.render.gui.Scissor;
import java.awt.*;
import java.io.IOException;
import java.util.LinkedList;
public class MainPanel extends ScaledGuiScreen {
boolean drag = false;
float dragX = 0f;
float dragY = 0f;
Category curType = Category.OPTIMIZE;
LinkedList<CategoryComponent> categories = new LinkedList<>();
float modsWheel = 0f;
float wheelTemp = 0f;
private final Animator scaleAnimation = new Animator();
private final Animator alphaAnimation = new Animator();
private final Animator maskAlpha = new Animator();
private final AnimClock animClock = new AnimClock();
private static final BezierEasing CLICKGUI_EASE = BezierEasing.of(0.25, 0.1, 0.25, 1.0);
private static final int MASK_MAX_ALPHA = 110;
float selection = 0f;
float categoryAnimation = 30;
boolean close = false;
private boolean configSavedOnClose;
float moduleListAlpha = 0f;
float modHeight = 0f;
ScrollContainer modsContainer = new ScrollContainer();
public LinkedList<ModuleRenderer> mods = new LinkedList<>();
static int x = -1;
static int y = -1;
static float width = 430f;
static float height = 245.5f;
public static final float leftWidth = 50f;
public static String bindLock = "";
public static Module curModule = null;
public MainPanel() {
super();
}
private float getCategoryItemSpacing() {
return 27f;
}
private float getCategoryListHeight() {
return categories.size() * getCategoryItemSpacing();
}
private float getCategoryBgHeight() {
return Math.max(40f, getCategoryListHeight() + 8f);
}
private float getCategoryBgY() {
return y + (height - getCategoryBgHeight()) / 2f;
}
private float getCategoryStartY() {
return getCategoryBgY() + 10f;
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
//aiChatPanel.render(mouseX, mouseY, scaleFactor);
x = (int) ( guiWidth - width) / 2;
y = (int) (guiHeight - height) / 2;
if (!isMouseDown(0)) {
drag = false;
}
// if (drag) {
// mouseY -= (int) dragY;
// x = (int) (mouseX - dragX);
// y = mouseY;
// }
x = (int) Math.max(0, Math.min(guiWidth - (int) width, x));
y = (int) Math.max(0, Math.min(guiHeight - (int) height, y));
if (close) {
if (scaleAnimation.get() <= 0.7) {
mc.displayGuiScreen(null);
if (mc.currentScreen == null) {
mc.setIngameFocus();
}
}
}
double dt = animClock.tick();
scaleAnimation.update(dt);
alphaAnimation.update(dt);
maskAlpha.update(dt);
Alpha.set(1f);
Rects.fill(0f, 0f, guiWidth, guiHeight, new Color(0, 0, 0, (int) maskAlpha.get()));
Alpha.set((float) alphaAnimation.get() / 255f);
GlStateManager.translate(guiWidth / 2.0, guiHeight / 2.0, 0.0);
GL11.glScaled(scaleAnimation.get(), scaleAnimation.get(), 0.0);
GlStateManager.translate(-guiWidth / 2.0, -guiHeight / 2.0, 0.0);
Images.draw(new ResourceLocation("client/gui/settings/window/panel.png"),
x + leftWidth - 8,
y - 2,
width - leftWidth + 16,
height + 12,
-1
);
moduleListAlpha = (float) AnimMath.base(moduleListAlpha, 255.0, 0.1f);
float scale = (float) scaleAnimation.get();
float centerX = guiWidth / 2f;
float centerY = guiHeight / 2f;
float scissorX = centerX + (x - centerX) * scale;
float scissorY = centerY + (y - centerY + 10) * scale;
float scissorW = width * scale;
float scissorH = (height - 12) * scale;
GL11.glEnable(GL11.GL_SCISSOR_TEST);
Scissor.apply(
scissorX, scissorY, scissorW,
scissorH
);
modHeight = 20f;
float containerWidth = width - leftWidth - 10;
int finalMouseY = mouseY;
modsContainer.draw(this, x + leftWidth, y + 25f, containerWidth, height - 20f, mouseX, mouseY, () -> {
float modsY = y + 22f;
for (ModuleRenderer m : mods) {
if (m.mod.category == curType) {
float moduleY = modsY + modsContainer.getScroll();
if (moduleY + 40 + m.height > y && moduleY < y + height) {
m.render(
this,
x + leftWidth + 10,
moduleY,
containerWidth - 10,
40f,
mouseX,
finalMouseY,
curModule == m.mod
);
}
modsY += 45 + m.height;
modHeight += 45 + m.height;
}
}
modsContainer.setHeight(modHeight);
});
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_SCISSOR_TEST);
float categoryBgHeight = getCategoryBgHeight();
float categoryBgY = getCategoryBgY();
float categoryStartY = getCategoryStartY();
if (Hover.is(x, (int) categoryBgY, categoryAnimation, categoryBgHeight, mouseX, mouseY)) {
categoryAnimation = (float) AnimMath.base(categoryAnimation, 100f, 0.15f);
} else {
categoryAnimation = (float) AnimMath.base(categoryAnimation, 30f, 0.15f);
}
Rects.roundedImage(
Math.round(x + categoryAnimation / 50f),
Math.round(categoryBgY),
Math.round(categoryAnimation),
Math.round(categoryBgHeight),
10,
new Color(0, 0, 0, 200)
);
float my = categoryStartY;
Rects.roundedImage(
Math.round(x + 4 + categoryAnimation / 50f),
Math.round(selection - 6),
Math.round(categoryAnimation - 8),
22,
10,
new Color(255, 255, 255)
);
GL11.glEnable(GL11.GL_SCISSOR_TEST);
float categoryScissorX = centerX + (x - centerX) * scale;
float categoryScissorY = centerY + (categoryBgY - centerY) * scale;
float categoryScissorW = categoryAnimation * scale;
float categoryScissorH = categoryBgHeight * scale;
Scissor.apply(
categoryScissorX, categoryScissorY, categoryScissorW,
categoryScissorH
);
for (CategoryComponent m : categories) {
if (Hover.is(x, my - 6, leftWidth - 10, 20f, mouseX, mouseY)) {
m.categorySelectionColor.animateTo(new Color(70, 70, 70), 0.15f, Easings.QUAD_OUT);
} else {
m.categorySelectionColor.animateTo(Colors.alpha(new Color(70, 70, 70), 0), 0.15f, Easings.QUAD_OUT);
}
m.categorySelectionColor.update(dt);
if (m.category == curType) {
selection = drag
? my
: (float) AnimMath.base(selection, my, 0.2);
}
m.render(
x + categoryAnimation / 50f,
my,
leftWidth - 10,
20f,
mouseX,
mouseY,
curType == m.category,
dt
);
my += 27f;
}
GL11.glDisable(GL11.GL_SCISSOR_TEST);
Alpha.set(1f);
handlePointerPress();
}
@Override
public void updateScreen() {
super.updateScreen();
}
@Override
public void initGui() {
super.initGui();
// aiChatPanel.init();
animClock.reset();
scaleAnimation.start(0.8, 1.0, 0.2f, CLICKGUI_EASE);
alphaAnimation.start(0.0, 255.0, 0.2f, CLICKGUI_EASE);
maskAlpha.start(0.0, MASK_MAX_ALPHA, 0.2f, CLICKGUI_EASE);
close = false;
configSavedOnClose = false;
// if (width == 0f || height == 0f) {
// width = scaledWidth / 2f;
// height = scaledHeight / 2f;
// }
categories.clear();
for (Category c : Category.values()) {
categories.add(new CategoryComponent(c));
}
selection = y + height / 2f;
}
@Override
public void onResize(Minecraft mcIn, int w, int h) {
super.onResize(mcIn, w, h);
}
@Override
public void onGuiClosed() {
super.onGuiClosed();
saveConfigOnClose();
}
@Override
public void keyTyped(char typedChar, int keyCode) throws IOException {
// aiChatPanel.keyTyped(typedChar, keyCode);
if (keyCode == 1) {
if (scaleAnimation.isRunning() || scaleAnimation.get() != 0.7) {
requestClose();
}
return;
}
for (ModuleRenderer m : mods) {
if (m.mod.category == curType) {
m.keyTyped(typedChar, keyCode);
}
}
super.keyTyped(typedChar, keyCode);
}
private void handlePointerPress() {
ScaledGuiScreen.PointerEvent press = peekAnyPress();
if (press == null) {
return;
}
int mouseX = (int) press.x;
int mouseY = (int) press.y;
int mouseButton = press.button;
if (!Hover.is(x, y, width, height, mouseX, mouseY)) {
return;
}
if (hasPointerCapture()) {
return;
}
float my = getCategoryStartY();
for (Category c : Category.values()) {
if (Hover.is(x, my - 8, leftWidth, 24f, mouseX, mouseY)) {
wheelTemp = 0f;
modsWheel = 0f;
if (curType != c) {
moduleListAlpha = 0f;
}
curType = c;
}
my += 27f;
}
if (mouseButton == 0) {
consumePressInBounds(x, y, width, height, mouseButton);
}
}
private void requestClose() {
saveConfigOnClose();
close = true;
scaleAnimation.animateTo(0.7, 0.1f, CLICKGUI_EASE);
alphaAnimation.animateTo(0.0, 0.1f, CLICKGUI_EASE);
maskAlpha.animateTo(0.0, 0.1f, CLICKGUI_EASE);
}
private void saveConfigOnClose() {
if (configSavedOnClose) {
return;
}
try {
FPSMaster.configManager.saveConfig("default");
configSavedOnClose = true;
} catch (FileException e) {
ClientLogger.error("Failed to save config when closing MainPanel: " + e.getMessage());
e.printStackTrace();
}
}
}