-
Notifications
You must be signed in to change notification settings - Fork 203
Fix lwjgl3ify 3.0 compatibility in the exit confirmation code #1545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 4 commits
a3634e4
2159f21
6da399e
a7524e9
a720ef4
f09a337
d59ca42
a537a23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| plugins { | ||
| id("com.gtnewhorizons.gtnhconvention") | ||
| } | ||
|
|
||
| tasks.test.configure { | ||
| useJUnitPlatform() | ||
| testLogging { | ||
| events ("passed", "skipped", "failed") | ||
| } | ||
| } | ||
|
|
||
| configurations { | ||
| testImplementation.get().extendsFrom(compileOnly.get()) | ||
| } | ||
|
|
||
| // Allow optional lwjgl3 usage, make sure to hide it behind the appropriate conditionals | ||
| // This can't be in dependencies.gradle due to need to freeze the lwjgl3 version property | ||
| val lwjgl3Version = project.minecraft.lwjgl3Version.get()!! | ||
| dependencies { | ||
| compileOnly("org.lwjgl:lwjgl-sdl:${lwjgl3Version}") { isTransitive = false } | ||
| compileOnly("org.lwjgl:lwjgl:${lwjgl3Version}") { isTransitive = false } | ||
| compileOnly("com.github.GTNewHorizons:lwjgl3ify:3.0.3:dev") { isTransitive = false } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package com.dreammaster.lwjgl3ify; | ||
|
|
||
| import static org.lwjgl.sdl.SDLMessageBox.*; | ||
|
|
||
| import java.nio.IntBuffer; | ||
|
|
||
| import net.minecraft.util.StatCollector; | ||
|
|
||
| import org.lwjgl.sdl.SDLError; | ||
| import org.lwjgl.sdl.SDL_MessageBoxButtonData; | ||
| import org.lwjgl.sdl.SDL_MessageBoxData; | ||
| import org.lwjgl.system.MemoryStack; | ||
| import org.lwjglx.opengl.Display; | ||
|
|
||
| import com.dreammaster.coremod.DreamCoreMod; | ||
| import com.dreammaster.lib.Refstrings; | ||
|
|
||
| import me.eigenraven.lwjgl3ify.api.Lwjgl3Aware; | ||
|
|
||
| @Lwjgl3Aware | ||
| public class ConfirmExitSdl { | ||
|
|
||
| // Keep as static final ints to avoid adding a classloading dependency when used | ||
| public static final int BUTTON_YES = 0; | ||
| public static final int BUTTON_NO = 1; | ||
| public static final int BUTTON_NEVER = 2; | ||
|
|
||
| private static String translateOrDefault(String key, String defaultValue) { | ||
| return StatCollector.canTranslate(key) ? StatCollector.translateToLocal(key) : defaultValue; | ||
| } | ||
|
|
||
| /** | ||
| * @return 0 for Yes, 1 for No, | ||
| */ | ||
| @SuppressWarnings("resource") | ||
| public static int showExitDialog() { | ||
| try (MemoryStack stack = MemoryStack.stackPush()) { | ||
| final IntBuffer selectedOption = stack.ints(1); | ||
| final SDL_MessageBoxData box = SDL_MessageBoxData.calloc(stack); | ||
|
|
||
eigenraven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| final String yesText = translateOrDefault("dreamcraft.gui.quitmessage.yes", "Yes"); | ||
| final String noText = translateOrDefault("dreamcraft.gui.quitmessage.no", "No"); | ||
| final String neverText = translateOrDefault("dreamcraft.gui.quitmessage.never", "Don't Show Again!"); | ||
| final String messageText = translateOrDefault( | ||
| "dreamcraft.gui.quitmessage", | ||
| "Are you sure you want to exit the game?"); | ||
|
|
||
| box.flags(SDL_MESSAGEBOX_WARNING); | ||
| box.window(Display.getWindow()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removing this line fixes my problem with MC window being missing in Mission Control |
||
| box.title(stack.UTF8(Refstrings.NAME)); | ||
| box.message(stack.UTF8(messageText)); | ||
|
|
||
| final SDL_MessageBoxButtonData.Buffer buttons = SDL_MessageBoxButtonData.calloc(3, stack); | ||
| buttons.get(BUTTON_YES).set(SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, BUTTON_YES, stack.UTF8(yesText)); | ||
| buttons.get(BUTTON_NO).set(SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, BUTTON_NO, stack.UTF8(noText)); | ||
| buttons.get(BUTTON_NEVER).set(0, BUTTON_NEVER, stack.UTF8(neverText)); | ||
| box.buttons(buttons); | ||
|
|
||
| if (!SDL_ShowMessageBox(box, selectedOption)) { | ||
| DreamCoreMod.logger | ||
| .error("Could not create exit confirmation message box: {}", SDLError.SDL_GetError()); | ||
| // Assume it's ok to quit in case the message box cannot be spawned | ||
| return BUTTON_YES; | ||
| } | ||
| return selectedOption.get(0); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import javax.swing.JOptionPane; | ||
|
|
||
| import net.minecraft.client.Minecraft; | ||
| import net.minecraft.launchwrapper.Launch; | ||
| import net.minecraft.util.StatCollector; | ||
|
|
||
| import org.spongepowered.asm.mixin.Mixin; | ||
|
|
@@ -19,6 +20,7 @@ | |
| import com.dreammaster.client.util.IconLoader; | ||
| import com.dreammaster.coremod.DreamCoreMod; | ||
| import com.dreammaster.lib.Refstrings; | ||
| import com.dreammaster.lwjgl3ify.ConfirmExitSdl; | ||
|
|
||
| @Mixin(Minecraft.class) | ||
| public abstract class MixinMinecraft_ConfirmExit { | ||
|
|
@@ -40,6 +42,22 @@ public abstract class MixinMinecraft_ConfirmExit { | |
| if (!this.dreamcraft$waitingDialogQuit) { | ||
| this.dreamcraft$waitingDialogQuit = true; | ||
| new Thread(() -> { | ||
| // Do not use Swing when lwjgl3ify 3.x is active | ||
| if ((Integer) Launch.blackboard.getOrDefault("lwjgl3ify:major-version", Integer.MIN_VALUE) >= 3) { | ||
| final int choice = ConfirmExitSdl.showExitDialog(); | ||
| if (choice == ConfirmExitSdl.BUTTON_YES) { | ||
| this.dreamcraft$isCloseRequested = true; | ||
| this.shutdown(); | ||
| } else if (choice == ConfirmExitSdl.BUTTON_NEVER) { | ||
| this.dreamcraft$isCloseRequested = true; | ||
| DreamCoreMod.disableShowConfirmExitWindow(); | ||
| this.shutdown(); | ||
| } | ||
| this.dreamcraft$waitingDialogQuit = false; | ||
|
|
||
| return; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code is inside the |
||
| } | ||
|
|
||
| final JFrame frame = new JFrame(); | ||
| frame.setAlwaysOnTop(true); | ||
| final URL resource = IconLoader.class.getClassLoader() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.