Added native file choosers for importing/exporting save
This commit is contained in:
@@ -64,7 +64,15 @@ public abstract class Platform {
|
||||
}
|
||||
/**Only used for iOS or android: open the share menu for a map or save.*/
|
||||
public void shareFile(FileHandle file){}
|
||||
/**Show a file chooser. Desktop only.*/
|
||||
|
||||
/**Show a file chooser. Desktop only.
|
||||
*
|
||||
* @param text File chooser title text
|
||||
* @param content Type of files to be loaded
|
||||
* @param cons Selection listener
|
||||
* @param open Whether to open or save files.
|
||||
* @param filetypes List of file extensions to filter.
|
||||
*/
|
||||
public void showFileChooser(String text, String content, Consumer<FileHandle> cons, boolean open, String... filetypes){}
|
||||
/**Use the default thread provider from the kryonet module for this.*/
|
||||
public ThreadProvider getThreadProvider(){
|
||||
|
||||
@@ -87,14 +87,14 @@ public class LoadDialog extends FloatingDialog{
|
||||
if(!gwt) {
|
||||
t.addImageButton("icon-save", "empty", 14 * 3, () -> {
|
||||
if(!ios) {
|
||||
new FileChooser("$text.save.export", false, file -> {
|
||||
try {
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
} catch (IOException e) {
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}).show();
|
||||
Platform.instance.showFileChooser(Bundles.get("text.save.export"), "Mindustry Save", file -> {
|
||||
try {
|
||||
slot.exportFile(file);
|
||||
setup();
|
||||
} catch (IOException e) {
|
||||
ui.showError(Bundles.format("text.save.export.fail", Strings.parseException(e, false)));
|
||||
}
|
||||
}, false, "mins");
|
||||
}else{
|
||||
try {
|
||||
FileHandle file = Gdx.files.local("save-" + slot.getName() + ".mins");
|
||||
@@ -150,7 +150,7 @@ public class LoadDialog extends FloatingDialog{
|
||||
if(gwt || ios) return;
|
||||
|
||||
slots.addImageTextButton("$text.save.import", "icon-add", "clear", 14*3, () -> {
|
||||
new FileChooser("$text.save.import", f -> f.extension().equals("mins"), true, file -> {
|
||||
Platform.instance.showFileChooser(Bundles.get("text.save.import"), "Mindustry Save", file -> {
|
||||
if(SaveIO.isSaveValid(file)){
|
||||
try{
|
||||
control.getSaves().importSave(file);
|
||||
@@ -161,7 +161,7 @@ public class LoadDialog extends FloatingDialog{
|
||||
}else{
|
||||
ui.showError("$text.save.import.invalid");
|
||||
}
|
||||
}).show();
|
||||
}, true, "mins");
|
||||
}).fillX().margin(10f).minWidth(300f).height(70f).pad(4f).padRight(-4);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ public class DesktopLauncher {
|
||||
config.setMaximized(true);
|
||||
config.setWindowedMode(960, 540);
|
||||
config.setWindowIcon("sprites/icon.png");
|
||||
|
||||
if(OS.isMac) {
|
||||
config.setPreferencesConfig(UCore.getProperty("user.home") + "/Library/Application Support/", FileType.Absolute);
|
||||
config.setPreferencesConfig(UCore.getProperty("user.home") + "/Library/Application Support/Mindustry", FileType.Absolute);
|
||||
}
|
||||
|
||||
Platform.instance = new DesktopPlatform(arg);
|
||||
|
||||
@@ -55,6 +55,7 @@ public class DesktopPlatform extends Platform {
|
||||
FxApp.cons = cons;
|
||||
FxApp.filter = filter;
|
||||
FxApp.open = open;
|
||||
FxApp.content = content;
|
||||
FxApp.open();
|
||||
}){{
|
||||
setDaemon(true);
|
||||
@@ -208,7 +209,7 @@ public class DesktopPlatform extends Platform {
|
||||
file = chooser.showSaveDialog(null);
|
||||
}
|
||||
if (file != null) {
|
||||
cons.accept(Gdx.files.absolute(file.getAbsolutePath()));
|
||||
Gdx.app.postRunnable(() -> cons.accept(Gdx.files.absolute(file.getAbsolutePath())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user