Skip to content

Commit ac90724

Browse files
cattyngmdMineGame159
authored andcommitted
feat: added screen closing animation
1 parent 16a09d4 commit ac90724

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/main/java/meteordevelopment/meteorclient/gui/WidgetScreen.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public abstract class WidgetScreen extends Screen {
5555
private boolean onClose;
5656
private boolean debug;
5757

58+
private boolean closing;
59+
5860
private double lastMouseX, lastMouseY;
5961

6062
public double animProgress;
@@ -255,9 +257,13 @@ public void renderCustom(DrawContext context, int mouseX, int mouseY, float delt
255257
mouseX *= s;
256258
mouseY *= s;
257259

258-
animProgress += delta / 20 * 14;
260+
animProgress += (delta / 20 * 14) * (closing ? -1 : 1);
259261
animProgress = MathHelper.clamp(animProgress, 0, 1);
260262

263+
if (closing && (animProgress == 0 || parent != null)) {
264+
closeInternal();
265+
}
266+
261267
GuiKeyEvents.canUseKeys = true;
262268

263269
// Apply projection without scaling
@@ -304,12 +310,7 @@ public void resize(MinecraftClient client, int width, int height) {
304310
@Override
305311
public void close() {
306312
if (!locked || lockedAllowClose) {
307-
boolean preOnClose = onClose;
308-
onClose = true;
309-
310-
removed();
311-
312-
onClose = preOnClose;
313+
closing = true;
313314
}
314315
}
315316

@@ -341,6 +342,16 @@ public void removed() {
341342
}
342343
}
343344

345+
private void closeInternal() {
346+
boolean preOnClose = onClose;
347+
onClose = true;
348+
349+
super.close();
350+
removed();
351+
352+
onClose = preOnClose;
353+
}
354+
344355
private void loopWidgets(WWidget widget, Consumer<WWidget> action) {
345356
action.accept(widget);
346357

0 commit comments

Comments
 (0)