Skip to content

Commit

Permalink
open small window to confirm closing the game when clicking the [X] o…
Browse files Browse the repository at this point in the history
…n main game window
  • Loading branch information
Alexdoru committed Sep 21, 2023
1 parent 9cb3f42 commit 7b805b3
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.dreammaster.mixin.mixins.early;

import java.net.URL;

import javax.swing.*;

import net.minecraft.client.Minecraft;
import net.minecraft.util.Util;

Expand Down Expand Up @@ -36,4 +40,37 @@ public class MixinMinecraft_PackIcon {
return this.dreamcraft$loadedGTNHIcon ? Util.EnumOS.OSX : osType;
}

@Unique
private boolean dreamcraft$isCloseRequested;

@ModifyExpressionValue(
method = "runGameLoop",
at = @At(value = "INVOKE", target = "Lorg/lwjgl/opengl/Display;isCloseRequested()Z", remap = false))
private boolean dreamcraft$confirmGameShutdown(boolean isCloseRequested) {
if (this.dreamcraft$isCloseRequested) {
return true;
}
if (isCloseRequested) {
new Thread(() -> {
final JFrame frame = new JFrame();
frame.setAlwaysOnTop(true);
final URL resource = IconLoader.class.getClassLoader()
.getResource("assets/dreamcraft/textures/icon/GTNH_42x42.png");
final ImageIcon imageIcon = resource == null ? null : new ImageIcon(resource);
final int result = JOptionPane.showConfirmDialog(
frame,
"Are you sure you want to exit the game ?",
Refstrings.NAME,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
imageIcon);
if (result == JOptionPane.YES_OPTION) {
this.dreamcraft$isCloseRequested = true;
}
}).start();
return false;
}
return false;
}

}

0 comments on commit 7b805b3

Please sign in to comment.