Skip to content

Commit

Permalink
fix ScreenshotScreen not closing when pressing escape
Browse files Browse the repository at this point in the history
  • Loading branch information
camnwalter committed Sep 6, 2023
1 parent 5cbcfdf commit c9f274b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/com/squagward/screenshots/mixin/KeyboardMixin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.squagward.screenshots.mixin;

import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.squagward.screenshots.Screenshots;
Expand All @@ -14,6 +15,7 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;

import java.io.File;
import java.util.function.Consumer;
Expand Down Expand Up @@ -42,7 +44,18 @@ public class KeyboardMixin {
ScreenshotHud.INSTANCE.reset();

if (client.currentScreen == null) {
client.send(() -> client.setScreen(new ScreenshotScreen()));
client.send(() -> {
client.setScreen(new ScreenshotScreen());
Screenshots.INSTANCE.setDisplayScreenshotScreen(true);
});
}
}

@WrapWithCondition(method = "onKey", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;openPauseMenu(Z)V"))
private boolean screenshots$dontOpenPauseMenu(MinecraftClient client, boolean pause) {
boolean shouldOpenPauseMenu = !Screenshots.INSTANCE.getDisplayScreenshotScreen();
Screenshots.INSTANCE.setDisplayScreenshotScreen(false);

return shouldOpenPauseMenu;
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/com/squagward/screenshots/Screenshots.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import javax.imageio.ImageIO

object Screenshots : ClientModInitializer {
var displayScreenshotHud = false
var displayScreenshotScreen = false
private val LOGGER: Logger = LogManager.getLogger("Screenshots")

override fun onInitializeClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,20 @@ object ScreenshotHud {

if (screen is ScreenshotScreen) {
screen.close()
Screenshots.displayScreenshotScreen = false
}
Screenshots.displayScreenshotHud = false
}

ScreenKeyboardEvents.afterKeyPress(screen).register { _, key, _, _ ->
if (Screenshots.displayScreenshotHud && key == GLFW.GLFW_KEY_ESCAPE) {
if (screen is ScreenshotScreen) {
screen.close()
// can't set Screenshots.displayScreenshotScreen to false,
// we need to keep the value as true so our mixin knows the ScreenshotScreen
// was just closed. Otherwise, the pause menu will display as the current
// screen would be null.
}
Screenshots.displayScreenshotHud = false
}
}
Expand Down

0 comments on commit c9f274b

Please sign in to comment.