mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-11 08:15:35 +03:00
Native file chooser, untested
This commit is contained in:
parent
ba2191a186
commit
bf1b4f9af5
@ -234,6 +234,8 @@ project(":desktop"){
|
||||
dependencies{
|
||||
implementation project(":core")
|
||||
implementation arcModule("extensions:discord")
|
||||
implementation arcModule("extensions:filedialogs")
|
||||
implementation arcModule("natives:natives-filedialogs")
|
||||
implementation arcModule("natives:natives-desktop")
|
||||
implementation arcModule("natives:natives-freetype-desktop")
|
||||
|
||||
|
@ -6,6 +6,7 @@ import arc.backend.sdl.*;
|
||||
import arc.backend.sdl.jni.*;
|
||||
import arc.discord.*;
|
||||
import arc.discord.DiscordRPC.*;
|
||||
import arc.filedialogs.*;
|
||||
import arc.files.*;
|
||||
import arc.func.*;
|
||||
import arc.math.*;
|
||||
@ -23,6 +24,7 @@ import mindustry.net.*;
|
||||
import mindustry.net.Net.*;
|
||||
import mindustry.service.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.ui.dialogs.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@ -36,6 +38,55 @@ public class DesktopLauncher extends ClientLauncher{
|
||||
public static void main(String[] arg){
|
||||
try{
|
||||
Vars.loadLogger();
|
||||
Vars.platform = new Platform(){
|
||||
@Override
|
||||
public void showFileChooser(boolean open, String title, String extension, Cons<Fi> cons){
|
||||
if(OS.isWindows || OS.isMac){
|
||||
Threads.daemon(() -> {
|
||||
try{
|
||||
FileDialogs.loadNatives();
|
||||
|
||||
String result;
|
||||
|
||||
if(open){
|
||||
result = FileDialogs.openFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files", false);
|
||||
}else{
|
||||
result = FileDialogs.saveFileDialog(title, FileChooser.getLastDirectory().absolutePath(), new String[]{"*." + extension}, "." + extension + " files");
|
||||
}
|
||||
|
||||
if(result == null) return;
|
||||
|
||||
if(result.length() > 1 && result.contains("\n")){
|
||||
result = result.split("\n")[0];
|
||||
}
|
||||
|
||||
//cancelled selection, ignore result
|
||||
if(result.isEmpty() || result.equals("\n")) return;
|
||||
if(result.endsWith("\n")) result = result.substring(0, result.length() - 1);
|
||||
if(result.contains("\n")) throw new IOException("invalid input: \"" + result + "\"");
|
||||
|
||||
Fi file = Core.files.absolute(result);
|
||||
Core.app.post(() -> {
|
||||
FileChooser.setLastDirectory(file.isDirectory() ? file : file.parent());
|
||||
|
||||
if(!open){
|
||||
cons.get(file.parent().child(file.nameWithoutExtension() + "." + extension));
|
||||
}else{
|
||||
cons.get(file);
|
||||
}
|
||||
});
|
||||
}catch(Throwable error){
|
||||
Log.err("Failure to execute native file chooser", error);
|
||||
Core.app.post(() -> {
|
||||
Platform.super.showFileChooser(open, title, extension, cons);
|
||||
});
|
||||
}
|
||||
});
|
||||
}else{
|
||||
Platform.super.showFileChooser(open, title, extension, cons);
|
||||
}
|
||||
}
|
||||
};
|
||||
new SdlApplication(new DesktopLauncher(arg), new SdlConfig(){{
|
||||
title = "Mindustry";
|
||||
maximized = true;
|
||||
|
@ -25,4 +25,4 @@ org.gradle.caching=true
|
||||
#used for slow jitpack builds; TODO see if this actually works
|
||||
org.gradle.internal.http.socketTimeout=100000
|
||||
org.gradle.internal.http.connectionTimeout=100000
|
||||
archash=eac3d7211c
|
||||
archash=30a01a48a1
|
||||
|
Loading…
Reference in New Issue
Block a user