Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions addon.gradle

This file was deleted.

5 changes: 0 additions & 5 deletions build.gradle

This file was deleted.

23 changes: 23 additions & 0 deletions build.gradle.kts
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 }
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pluginManagement {
}

plugins {
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.7'
id 'com.gtnewhorizons.gtnhsettingsconvention' version '2.0.10'
}


68 changes: 68 additions & 0 deletions src/main/java/com/dreammaster/lwjgl3ify/ConfirmExitSdl.java
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);

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());
Copy link
Member

Choose a reason for hiding this comment

The 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.ASCII(Refstrings.NAME));
box.message(stack.ASCII(messageText));

final SDL_MessageBoxButtonData.Buffer buttons = SDL_MessageBoxButtonData.calloc(3, stack);
buttons.get(BUTTON_YES).set(SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, BUTTON_YES, stack.ASCII(yesText));
buttons.get(BUTTON_NO).set(SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, BUTTON_NO, stack.ASCII(noText));
buttons.get(BUTTON_NEVER).set(0, BUTTON_NEVER, stack.ASCII(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
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a ci.cancel(); call before the other return, is that not necessary here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is inside the new Thread(() -> ...) so ci.cancel(); will still be called

}

final JFrame frame = new JFrame();
frame.setAlwaysOnTop(true);
final URL resource = IconLoader.class.getClassLoader()
Expand Down