@@ -244,6 +244,8 @@ project(":desktop"){
|
|||||||
implementation project(":core")
|
implementation project(":core")
|
||||||
implementation arcModule("extensions:profiling")
|
implementation arcModule("extensions:profiling")
|
||||||
implementation arcModule("extensions:discord")
|
implementation arcModule("extensions:discord")
|
||||||
|
implementation arcModule("natives:natives-filedialogs")
|
||||||
|
implementation arcModule("extensions:filedialogs")
|
||||||
implementation arcModule("natives:natives-desktop")
|
implementation arcModule("natives:natives-desktop")
|
||||||
implementation arcModule("natives:natives-freetype-desktop")
|
implementation arcModule("natives:natives-freetype-desktop")
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ package mindustry.desktop;
|
|||||||
import arc.*;
|
import arc.*;
|
||||||
import arc.Files.*;
|
import arc.Files.*;
|
||||||
import arc.backend.sdl.*;
|
import arc.backend.sdl.*;
|
||||||
|
import arc.backend.sdl.jni.*;
|
||||||
import arc.discord.*;
|
import arc.discord.*;
|
||||||
import arc.discord.DiscordRPC.*;
|
import arc.discord.DiscordRPC.*;
|
||||||
|
import arc.filedialogs.*;
|
||||||
import arc.files.*;
|
import arc.files.*;
|
||||||
import arc.func.*;
|
import arc.func.*;
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
@@ -15,7 +17,7 @@ import arc.util.Log.*;
|
|||||||
import arc.util.serialization.*;
|
import arc.util.serialization.*;
|
||||||
import com.codedisaster.steamworks.*;
|
import com.codedisaster.steamworks.*;
|
||||||
import mindustry.*;
|
import mindustry.*;
|
||||||
import mindustry.core.Version;
|
import mindustry.core.*;
|
||||||
import mindustry.desktop.steam.*;
|
import mindustry.desktop.steam.*;
|
||||||
import mindustry.game.EventType.*;
|
import mindustry.game.EventType.*;
|
||||||
import mindustry.gen.*;
|
import mindustry.gen.*;
|
||||||
@@ -26,9 +28,6 @@ import mindustry.net.Net.*;
|
|||||||
import mindustry.service.*;
|
import mindustry.service.*;
|
||||||
import mindustry.type.*;
|
import mindustry.type.*;
|
||||||
import mindustry.ui.dialogs.*;
|
import mindustry.ui.dialogs.*;
|
||||||
import org.lwjgl.*;
|
|
||||||
import org.lwjgl.sdl.*;
|
|
||||||
import org.lwjgl.system.*;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@@ -338,39 +337,52 @@ public class DesktopLauncher extends ClientLauncher{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showFileChooser(boolean open, String title, String extension, Cons<Fi> cons){
|
public void showFileChooser(boolean open, String title, String extension, Cons<Fi> cons){
|
||||||
showNativeFileChooser(open, cons, extension);
|
showNativeFileChooser(title, open, cons, extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showMultiFileChooser(Cons<Fi> cons, String... extensions){
|
public void showMultiFileChooser(Cons<Fi> cons, String... extensions){
|
||||||
showNativeFileChooser(true, cons, extensions);
|
showNativeFileChooser("@open", true, cons, extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
void showNativeFileChooser(boolean open, Cons<Fi> cons, String... shownExtensions){
|
void showNativeFileChooser(String title, boolean open, Cons<Fi> cons, String... shownExtensions){
|
||||||
|
String formatted = (title.startsWith("@") ? Core.bundle.get(title.substring(1)) : title).replaceAll("\"", "'");
|
||||||
|
|
||||||
|
//this should never happen unless someone is being dumb with the parameters
|
||||||
String[] ext = shownExtensions == null || shownExtensions.length == 0 ? new String[]{""} : shownExtensions;
|
String[] ext = shownExtensions == null || shownExtensions.length == 0 ? new String[]{""} : shownExtensions;
|
||||||
|
|
||||||
SDL_DialogFileFilter.Buffer filters = SDL_DialogFileFilter.calloc(ext.length);
|
//native file dialog
|
||||||
try(MemoryStack stack = MemoryStack.stackPush()){
|
Threads.daemon(() -> {
|
||||||
|
try{
|
||||||
|
FileDialogs.loadNatives();
|
||||||
|
|
||||||
|
String result;
|
||||||
|
String[] patterns = new String[ext.length];
|
||||||
for(int i = 0; i < ext.length; i++){
|
for(int i = 0; i < ext.length; i++){
|
||||||
String extName = ext[i];
|
patterns[i] = "*." + ext[i];
|
||||||
|
|
||||||
var filter = SDL_DialogFileFilter.calloc(stack)
|
|
||||||
.name(MemoryUtil.memUTF8(extName.isEmpty() ? "All Files" : "." + extName + " files"))
|
|
||||||
.pattern(MemoryUtil.memUTF8(extName.isEmpty() ? "*" : extName));
|
|
||||||
|
|
||||||
filters.put(i, filter);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
SDL_DialogFileCallbackI callback = (userData, files, filter) -> {
|
|
||||||
if(files != 0){
|
|
||||||
PointerBuffer pointerBuffer = MemoryUtil.memPointerBuffer(files, 1);
|
|
||||||
long firstFile = pointerBuffer.get();
|
|
||||||
if(firstFile != 0){
|
|
||||||
String result = MemoryUtil.memUTF8(firstFile);
|
|
||||||
|
|
||||||
|
//on MacOS, .msav is not properly recognized until I put garbage into the array?
|
||||||
|
if(patterns.length == 1 && OS.isMac && open){
|
||||||
|
patterns = new String[]{"", "*." + ext[0]};
|
||||||
|
}
|
||||||
|
|
||||||
|
if(open){
|
||||||
|
result = FileDialogs.openFileDialog(formatted, FileChooser.getLastDirectory().absolutePath(), patterns, "." + ext[0] + " files", false);
|
||||||
|
}else{
|
||||||
|
result = FileDialogs.saveFileDialog(formatted, FileChooser.getLastDirectory().child("file." + ext[0]).absolutePath(), patterns, "." + ext[0] + " 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.isEmpty() || result.equals("\n")) return;
|
||||||
if(result.endsWith("\n")) result = result.substring(0, result.length() - 1);
|
if(result.endsWith("\n")) result = result.substring(0, result.length() - 1);
|
||||||
if(result.contains("\n")) return;
|
if(result.contains("\n")) throw new IOException("invalid input: \"" + result + "\"");
|
||||||
|
|
||||||
Fi file = Core.files.absolute(result);
|
Fi file = Core.files.absolute(result);
|
||||||
Core.app.post(() -> {
|
Core.app.post(() -> {
|
||||||
@@ -382,17 +394,17 @@ public class DesktopLauncher extends ClientLauncher{
|
|||||||
cons.get(file);
|
cons.get(file);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}catch(Throwable error){
|
||||||
}
|
Log.err("Failure to execute native file chooser", error);
|
||||||
};
|
Core.app.post(() -> {
|
||||||
|
if(ext.length > 1){
|
||||||
if(open){
|
showMultiFileChooser(cons, ext);
|
||||||
SDLDialog.SDL_ShowOpenFileDialog(callback, 0, ((SdlApplication)Core.app).getWindow(), filters, FileChooser.getLastDirectory().absolutePath(), false);
|
|
||||||
}else{
|
}else{
|
||||||
SDLDialog.SDL_ShowSaveFileDialog(callback, 0, ((SdlApplication)Core.app).getWindow(), filters, FileChooser.getLastDirectory().absolutePath() + "/" + "export." + ext[0]);
|
Platform.defaultFileDialog(open, formatted, ext[0], cons);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
filters.free();
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -517,6 +529,6 @@ public class DesktopLauncher extends ClientLauncher{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void message(String message){
|
private static void message(String message){
|
||||||
SDLMessageBox.SDL_ShowSimpleMessageBox(SDLMessageBox.SDL_MESSAGEBOX_ERROR, "oh no", message, 0);
|
SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MESSAGEBOX_ERROR, "oh no", message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mindustry.desktop;
|
package mindustry.desktop;
|
||||||
|
|
||||||
|
import arc.backend.sdl.jni.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import org.lwjgl.sdl.*;
|
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
@@ -12,7 +12,7 @@ public class ErrorDialog{
|
|||||||
Log.err(text);
|
Log.err(text);
|
||||||
try{
|
try{
|
||||||
//will fail in the future on 32-bit platforms as no natives will be loaded
|
//will fail in the future on 32-bit platforms as no natives will be loaded
|
||||||
SDLMessageBox.SDL_ShowSimpleMessageBox(SDLMessageBox.SDL_MESSAGEBOX_ERROR, "it's over", text, 0);
|
SDL.SDL_ShowSimpleMessageBox(SDL.SDL_MESSAGEBOX_ERROR, "it's over", text);
|
||||||
}catch(Throwable error){
|
}catch(Throwable error){
|
||||||
try{
|
try{
|
||||||
//usually won't work on packaged JVMs, but I won't be distributing those with 32 bit windows anyway
|
//usually won't work on packaged JVMs, but I won't be distributing those with 32 bit windows anyway
|
||||||
|
|||||||
@@ -26,4 +26,4 @@ org.gradle.caching=true
|
|||||||
org.gradle.internal.http.socketTimeout=100000
|
org.gradle.internal.http.socketTimeout=100000
|
||||||
org.gradle.internal.http.connectionTimeout=100000
|
org.gradle.internal.http.connectionTimeout=100000
|
||||||
android.enableR8.fullMode=false
|
android.enableR8.fullMode=false
|
||||||
archash=5a2b279912
|
archash=a3c7d2cbf3
|
||||||
|
|||||||
Reference in New Issue
Block a user