fix native dialog for MC 26

This commit is contained in:
James Seibel
2026-04-12 13:53:52 -05:00
parent 8e45358aad
commit d1d642a7bb
4 changed files with 41 additions and 3 deletions
@@ -0,0 +1,38 @@
package com.seibel.distanthorizons.common.wrappers.gui;
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. <br><br>
*
* source:
* https://sourceforge.net/projects/tinyfiledialogs/
*
* @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 void 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, "");
#if MC_VER <= MC_1_21_11
TinyFileDialogs.tinyfd_messageBox(title, message, dialogType, iconType, false);
#else
// https://mfbridge.github.io/tinyfiledialogs/reference/messageBox.html
TinyFileDialogs.tinyfd_messageBox(title, message, dialogType, iconType, 1 /* ok/yes */);
#endif
}
}
@@ -25,7 +25,7 @@ import com.seibel.distanthorizons.core.config.Config;
import com.seibel.distanthorizons.core.dependencyInjection.ModAccessorInjector;
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
import com.seibel.distanthorizons.core.logging.DhLoggerBuilder;
import com.seibel.distanthorizons.core.util.NativeDialogUtil;
import com.seibel.distanthorizons.common.wrappers.gui.NativeDialogUtil;
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IPluginPacketSender;
import com.seibel.distanthorizons.core.wrapperInterfaces.modAccessor.*;
+1 -1
View File
@@ -11,7 +11,7 @@ builds_for=fabric,neoforge
netty_version=4.1.97.Final
# LWJGL
lwjgl_version=3.3.3
lwjgl_version=3.4.1
# Fabric loader
fabric_loader_version=0.18.5