v0.8.0: improved desktop dialog boxes, now use tinyFD instead of swing
This commit is contained in:
parent
bc3aa927a5
commit
777dc8933a
|
@ -56,6 +56,12 @@ dependencies {
|
|||
implementation "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||
implementation "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
|
||||
|
||||
//we use LWJGL tinyFD directly to display crash messages and (for now) single-line text input
|
||||
implementation "org.lwjgl:lwjgl-tinyfd:3.2.1"
|
||||
implementation "org.lwjgl:lwjgl-tinyfd:3.2.1:natives-windows"
|
||||
implementation "org.lwjgl:lwjgl-tinyfd:3.2.1:natives-macos"
|
||||
implementation "org.lwjgl:lwjgl-tinyfd:3.2.1:natives-linux"
|
||||
|
||||
//Need these at compile time to prevent errors there.
|
||||
// The actual dependency used at runtime will vary based on source set.
|
||||
compileOnly project(':services:updates:debugUpdates')
|
||||
|
|
|
@ -35,12 +35,11 @@ import com.watabou.noosa.Game;
|
|||
import com.watabou.utils.FileUtils;
|
||||
import com.watabou.utils.Point;
|
||||
|
||||
import org.lwjgl.util.tinyfd.TinyFileDialogs;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
|
||||
|
@ -51,12 +50,6 @@ public class DesktopLauncher {
|
|||
title = DesktopLauncher.class.getPackage().getSpecificationTitle();
|
||||
}
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName() );
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
|
||||
@Override
|
||||
public void uncaughtException(Thread thread, Throwable throwable) {
|
||||
|
@ -65,9 +58,20 @@ public class DesktopLauncher {
|
|||
PrintWriter pw = new PrintWriter(sw);
|
||||
throwable.printStackTrace(pw);
|
||||
pw.flush();
|
||||
JOptionPane.showMessageDialog(null, title + " has run into an error it can't recover from and has crashed, sorry about that!\n\n" +
|
||||
String exceptionMsg = sw.toString();
|
||||
|
||||
//shorten/simplify exception message to make it easier to fit into a message box
|
||||
exceptionMsg = exceptionMsg.replaceAll("\\(.*:([0-9]*)\\)", "($1)");
|
||||
exceptionMsg = exceptionMsg.replace("com.shatteredpixel.shatteredpixeldungeon.", "");
|
||||
exceptionMsg = exceptionMsg.replace("com.watabou.", "");
|
||||
exceptionMsg = exceptionMsg.replace("com.badlogic.gdx.", "");
|
||||
exceptionMsg = exceptionMsg.replace("\t", " ");
|
||||
|
||||
TinyFileDialogs.tinyfd_messageBox(title + " Has Crashed!",
|
||||
title + " has run into an error it can't recover from and has crashed, sorry about that!\n\n" +
|
||||
"If you could, please email this error message to the developer (Evan@ShatteredPixel.com):\n\n" +
|
||||
sw.toString(), title + " Has Crashed!", JOptionPane.ERROR_MESSAGE);
|
||||
exceptionMsg,
|
||||
"ok", "error", false );
|
||||
Gdx.app.exit();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -31,6 +31,8 @@ import com.watabou.noosa.Game;
|
|||
import com.watabou.utils.PlatformSupport;
|
||||
import com.watabou.utils.Point;
|
||||
|
||||
import org.lwjgl.util.tinyfd.TinyFileDialogs;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -64,8 +66,17 @@ public class DesktopPlatformSupport extends PlatformSupport {
|
|||
}
|
||||
|
||||
@Override
|
||||
//FIXME tinyfd_inputBox isn't a full solution for this. No support for multiline, looks ugly. Ideally we'd have an opengl-based input box
|
||||
public void promptTextInput(String title, String hintText, int maxLen, boolean multiLine, String posTxt, String negTxt, TextCallback callback) {
|
||||
|
||||
String result = TinyFileDialogs.tinyfd_inputBox(title, title, hintText);
|
||||
if (result == null){
|
||||
callback.onSelect(false, "");
|
||||
} else {
|
||||
if (result.contains("\r\n")) result = result.substring(0, result.indexOf("\r\n"));
|
||||
if (result.contains("\n")) result = result.substring(0, result.indexOf("\n"));
|
||||
if (result.length() > maxLen) result = result.substring(0, maxLen);
|
||||
callback.onSelect(true, result.replace("\r\n", "").replace("\n", ""));
|
||||
}
|
||||
}
|
||||
|
||||
private int pageSize;
|
||||
|
|
Loading…
Reference in New Issue
Block a user