Move native dialog to common

Native dialog was changed with LWJGL 3.4.1
This commit is contained in:
James Seibel
2026-04-12 13:53:31 -05:00
parent 1d9bffe64e
commit a44c5d562d
4 changed files with 17 additions and 43 deletions
@@ -31,7 +31,7 @@ import com.seibel.distanthorizons.core.config.types.enums.*;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.pos.DhSectionPos;
import com.seibel.distanthorizons.core.util.NativeDialogUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftSharedWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.core.logging.DhLogger;
@@ -1210,9 +1210,11 @@ public class Config
});
public static void onButtonPressed()
{
IMinecraftClientWrapper mcClient = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
LOGGER.info("Attempting to show tinyfd message box...");
boolean buttonPress = NativeDialogUtil.showDialog("Button pressed!", "UITester dialog", "ok", "info");
LOGGER.info("dialog returned with ["+(buttonPress ? "TRUE" : "FALSE")+"]");
mcClient.showDialog("Button pressed!", "UITester dialog", "ok", "info");
LOGGER.info("dialog closed");
}
public static ConfigCategory categoryTest = new ConfigCategory.Builder().set(CategoryTest.class).build();
@@ -28,16 +28,13 @@ import com.seibel.distanthorizons.core.jar.installer.GitlabGetter;
import com.seibel.distanthorizons.core.jar.installer.ModrinthGetter;
import com.seibel.distanthorizons.core.jar.installer.WebDownloader;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.logging.f3.F3Screen;
import com.seibel.distanthorizons.core.util.NativeDialogUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.IVersionConstants;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.coreapi.ModInfo;
import com.seibel.distanthorizons.coreapi.util.StringUtil;
import com.seibel.distanthorizons.coreapi.util.jar.DeleteOnUnlock;
import com.seibel.distanthorizons.core.logging.DhLogger;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.URLEncoder;
import java.nio.file.Files;
@@ -59,6 +56,8 @@ public class SelfUpdater
{
private static final DhLogger LOGGER = new DhLoggerBuilder().build();
private static final IMinecraftClientWrapper MC_CLIENT = SingletonInjector.INSTANCE.get(IMinecraftClientWrapper.class);
/** As we cannot delete(or replace) the jar while the mod is running, we just have this to delete it once the game closes */
public static boolean deleteOldJarOnJvmShutdown = false;
@@ -264,7 +263,7 @@ public class SelfUpdater
{
try
{
NativeDialogUtil.showDialog(ModInfo.READABLE_NAME, successMessage, "ok", "info");
MC_CLIENT.showDialog(ModInfo.READABLE_NAME, successMessage, "ok", "info");
}
catch (Exception ignore) { }
}).start();
@@ -287,7 +286,7 @@ public class SelfUpdater
LOGGER.error(failMessage, e);
try
{
NativeDialogUtil.showDialog(ModInfo.READABLE_NAME, failMessage, "ok", "error");
MC_CLIENT.showDialog(ModInfo.READABLE_NAME, failMessage, "ok", "error");
}
catch (Exception ignore) { }
@@ -386,7 +385,7 @@ public class SelfUpdater
{
try
{
NativeDialogUtil.showDialog(ModInfo.READABLE_NAME, successMessage, "ok", "info");
MC_CLIENT.showDialog(ModInfo.READABLE_NAME, successMessage, "ok", "info");
}
catch (Exception ignore) { }
}).start();
@@ -424,7 +423,7 @@ public class SelfUpdater
LOGGER.error(failMessage, e);
try
{
NativeDialogUtil.showDialog(ModInfo.READABLE_NAME, failMessage, "ok", "error");
MC_CLIENT.showDialog(ModInfo.READABLE_NAME, failMessage, "ok", "error");
}
catch (Exception ignore) { }
@@ -1,30 +0,0 @@
package com.seibel.distanthorizons.core.util;
import org.lwjgl.util.tinyfd.TinyFileDialogs;
/**
* Should be used instead of the direct call to {@link TinyFileDialogs}
* so we can run additional validation and/or string cleanup.
* Otherwise, we may get error messages back.
*
* @see TinyFileDialogs
*/
public class NativeDialogUtil
{
/**
* @param dialogType the dialog type. One of:<br><table><tr><td>"ok"</td><td>"okcancel"</td><td>"yesno"</td><td>"yesnocancel"</td></tr></table>
* @param iconType the icon type. One of:<br><table><tr><td>"info"</td><td>"warning"</td><td>"error"</td><td>"question"</td></tr></table>
*/
public static boolean showDialog(String title, String message, String dialogType, String iconType)
{
// Tinyfd doesn't support the following characters, attempting to display them will cause the message
// to be replaced with an error message
String unsafeCharsRegex = "['\"`]";
title = title.replaceAll(unsafeCharsRegex, "`");
message = message.replaceAll(unsafeCharsRegex, "`");
return TinyFileDialogs.tinyfd_messageBox(title, message, dialogType, iconType, false);
}
}
@@ -21,6 +21,7 @@ package com.seibel.distanthorizons.core.wrapperInterfaces.minecraft;
import com.seibel.distanthorizons.core.pos.blockPos.DhBlockPos;
import com.seibel.distanthorizons.core.pos.DhChunkPos;
import com.seibel.distanthorizons.core.render.RenderThreadTaskHandler;
import com.seibel.distanthorizons.core.wrapperInterfaces.world.IClientLevelWrapper;
import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable;
@@ -113,17 +114,19 @@ public interface IMinecraftClientWrapper extends IBindable
void crashMinecraft(String errorMessage, Throwable exception);
/**
* This is only designed to be used internally by {@link GLProxy}
* This is only designed to be used internally by {@link RenderThreadTaskHandler}
* since it handles task frame limiting (reducing/preventing stuttering)
* whereas this method causes the task to be run whenever MC decides to
* (likely all at once the next frame). <br><br>
*
* Any tasks submitted here will be run on the render thread.
*
* @see GLProxy#queueRunningOnRenderThread(Runnable)
* @see RenderThreadTaskHandler
*/
void executeOnRenderThread(Runnable runnable);
void showDialog(String title, String message, String dialogType, String iconType);
//=============//