Skip to content

Commit 94035a9

Browse files
committed
fix #13
1 parent 8e1f781 commit 94035a9

File tree

4 files changed

+56
-21
lines changed

4 files changed

+56
-21
lines changed

src/main/java/com/cleanroommc/neverenoughanimations/NEA.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ public void onGuiOpen(GuiOpenEvent event) {
8888
ItemHoverAnimation.onGuiOpen(event);
8989
ItemMoveAnimation.onGuiOpen(event);
9090
ItemPickupThrowAnimation.onGuiOpen(event);
91-
if (event.getGui() != null) {
92-
LOGGER.info("Opening screen {}", event.getGui().getClass());
93-
} else {
94-
LOGGER.info("Closing screen");
95-
}
9691
}
9792

9893
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
@@ -131,10 +126,17 @@ public void onGuiBackgroundDrawn(GuiScreenEvent.BackgroundDrawnEvent event) {
131126
}
132127
}
133128

134-
@SubscribeEvent
129+
@SubscribeEvent(priority = EventPriority.HIGHEST)
135130
public void mouseInput(GuiScreenEvent.MouseInputEvent.Pre event) {
136-
if (Mouse.getEventButton() >= 0) {
137-
LOGGER.info("Mouse Input: button {}, pressed {}, ", Mouse.getEventButton(), Mouse.getEventButtonState());
131+
if (OpeningAnimation.isAnimatingClose(event.getGui())) {
132+
event.setCanceled(true);
133+
}
134+
}
135+
136+
@SubscribeEvent(priority = EventPriority.HIGHEST)
137+
public void mouseInput(GuiScreenEvent.KeyboardInputEvent.Pre event) {
138+
if (OpeningAnimation.isAnimatingClose(event.getGui())) {
139+
event.setCanceled(true);
138140
}
139141
}
140142

@@ -151,10 +153,12 @@ public static int getMouseY() {
151153
}
152154

153155
public static float getCurrentOpenAnimationValue() {
156+
// only works while rendering gui
154157
return openAnimationValue;
155158
}
156159

157160
public static boolean isCurrentGuiAnimating() {
161+
// only works while rendering gui
158162
return currentDrawnScreen != null && openAnimationValue < 1f;
159163
}
160164

src/main/java/com/cleanroommc/neverenoughanimations/NEAConfig.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.cleanroommc.neverenoughanimations;
22

3-
import com.cleanroommc.neverenoughanimations.api.IAnimatedScreen;
43
import com.cleanroommc.neverenoughanimations.util.Interpolation;
54
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
6-
import net.minecraft.client.gui.GuiScreen;
75
import net.minecraftforge.common.config.Config;
86

97
@Config(modid = Tags.MODID)
@@ -48,11 +46,17 @@ public class NEAConfig {
4846
@Config.Name("Opening/Closing animation time")
4947
@Config.SlidingOption
5048
@Config.RangeInt(min = 0, max = 1000)
51-
@Config.Comment("How many millieseconds it takes until the gui is fully opened. 0 to disable.")
52-
public static int openingAnimationTime = 60;
49+
@Config.Comment("How many millieseconds it takes until the gui is fully opened. 0 to disable. 200 and lower is recommended.")
50+
public static int openingAnimationTime = 90;
5351
@Config.Name("Opening/Closing animation easing curve")
5452
public static Interpolation openingAnimationCurve = Interpolation.SINE_OUT;
5553

54+
@Config.Name("Opening/Closing start/end scale")
55+
@Config.SlidingOption
56+
@Config.RangeDouble(min = 0.0, max = 1.0)
57+
@Config.Comment("The scale at which the opening animation starts. What looks good depends on the animation time. Rule of thumb is the shorter the animation time, the larger the start scale.")
58+
public static float openingStartScale = 0.9f;
59+
5660
@Config.Name("Gui class animation blacklist")
5761
@Config.Comment({"Add class names (works with * at the end) which should be blacklisted from any animations.",
5862
"This is used to prevent visual issues with certain mods."})

src/main/java/com/cleanroommc/neverenoughanimations/animations/OpeningAnimation.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.cleanroommc.neverenoughanimations.util.Interpolations;
77
import net.minecraft.client.Minecraft;
88
import net.minecraft.client.gui.GuiScreen;
9-
import net.minecraft.client.gui.inventory.GuiContainer;
109
import net.minecraft.client.renderer.GlStateManager;
1110
import net.minecraftforge.client.event.GuiOpenEvent;
1211

@@ -32,6 +31,7 @@ public static boolean onGuiOpen(GuiOpenEvent event) {
3231

3332
private static IAnimatedScreen lastGui;
3433
private static IAnimatedScreen animatedGui;
34+
//private static boolean oldAllowAllInteractions = false;
3535
private static long startTime = 0;
3636
private static boolean shouldCloseLast = false;
3737

@@ -43,6 +43,8 @@ public static void animate(IAnimatedScreen container, boolean open) {
4343
if (!open) {
4444
startTime = -startTime;
4545
Minecraft.getMinecraft().setIngameFocus();
46+
//oldAllowAllInteractions = ((GuiScreen) container).allowUserInput;
47+
//((GuiScreen) container).allowUserInput = true;
4648
}
4749
}
4850

@@ -51,7 +53,7 @@ public static float getScale(GuiScreen screen) {
5153
}
5254

5355
public static float getScale(IAnimatedScreen container) {
54-
float min = 0.75f, max = 1f;
56+
float min = NEAConfig.openingStartScale, max = 1f;
5557
return Interpolations.lerp(min, max, getValue(container));
5658
}
5759

@@ -82,20 +84,37 @@ public static boolean handleScale(GuiScreen screen, boolean translateToPanel) {
8284
return screen instanceof IAnimatedScreen animatedScreen && handleScale(animatedScreen, translateToPanel);
8385
}
8486

85-
public static boolean handleScale(IAnimatedScreen container, boolean translateToPanel) {
86-
float scale = getScale(container);
87+
public static boolean handleScale(IAnimatedScreen screen, boolean translateToPanel) {
88+
float scale = getScale(screen);
8789
if (scale == 1 || NEAConfig.moveAnimationTime == 0) return false;
88-
if (translateToPanel) GlStateManager.translate(container.nea$getX(), container.nea$getY(), 0);
89-
GlStateManager.translate(container.nea$getWidth() / 2f, container.nea$getHeight() / 2f, 0);
90+
if (translateToPanel) GlStateManager.translate(screen.nea$getX(), screen.nea$getY(), 0);
91+
GlStateManager.translate(screen.nea$getWidth() / 2f, screen.nea$getHeight() / 2f, 0);
9092
GlStateManager.scale(scale, scale, 1f);
91-
GlStateManager.translate(-container.nea$getWidth() / 2f, -container.nea$getHeight() / 2f, 0);
92-
if (translateToPanel) GlStateManager.translate(-container.nea$getX(), -container.nea$getY(), 0);
93-
// GlStateManager.color(1f, 1f, 1f, scale);
93+
GlStateManager.translate(-screen.nea$getWidth() / 2f, -screen.nea$getHeight() / 2f, 0);
94+
if (translateToPanel) GlStateManager.translate(-screen.nea$getX(), -screen.nea$getY(), 0);
9495
return true;
9596
}
9697

98+
public static boolean isAnimating(GuiScreen screen) {
99+
return screen instanceof IAnimatedScreen animatedScreen && isAnimating(animatedScreen);
100+
}
101+
102+
public static boolean isAnimating(IAnimatedScreen screen) {
103+
return getValue(screen) < 1f;
104+
}
105+
106+
public static boolean isAnimatingClose(GuiScreen screen) {
107+
return screen instanceof IAnimatedScreen animatedScreen && isAnimatingClose(animatedScreen);
108+
}
109+
110+
public static boolean isAnimatingClose(IAnimatedScreen screen) {
111+
return isAnimating(screen) && startTime < 0;
112+
}
113+
97114
public static void checkGuiToClose() {
98115
if (shouldCloseLast && lastGui != null) {
116+
//((GuiScreen) lastGui).allowUserInput = oldAllowAllInteractions;
117+
//oldAllowAllInteractions = false;
99118
Minecraft.getMinecraft().displayGuiScreen(null);
100119
shouldCloseLast = false;
101120
lastGui = null;

src/main/java/com/cleanroommc/neverenoughanimations/core/mixin/MinecraftMixin.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,12 @@ public void timer(CallbackInfo ci) {
2323
NEA.onFrameTick();
2424
}
2525
}
26+
27+
// TODO maybe allow opening other uis while the current one is closing
28+
/*@WrapOperation(method = "runTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;handleInput()V"))
29+
public void cancelInteraction(GuiScreen instance, Operation<Void> original) {
30+
if (!OpeningAnimation.isAnimatingClose(instance)) {
31+
original.call(instance);
32+
}
33+
}*/
2634
}

0 commit comments

Comments
 (0)