diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index 5b508cd1d8..e040723b89 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -28,7 +28,10 @@ load.mod = Mods schematic = Schematic schematic.add = Save Schematic... schematics = Schematics +schematic.import = Import Schematic... schematic.exportfile = Export File +schematic.importfile = Import File +schematic.browseworkshop = Browse Workshop schematic.copy = Copy to Clipboard schematic.shareworkshop = Share on Workshop schematic.flip = [accent][[{0}][]/[accent][[{1}][]: Flip Schematic diff --git a/core/src/io/anuke/mindustry/Vars.java b/core/src/io/anuke/mindustry/Vars.java index 34b91182cd..d5c4a980f5 100644 --- a/core/src/io/anuke/mindustry/Vars.java +++ b/core/src/io/anuke/mindustry/Vars.java @@ -35,6 +35,8 @@ public class Vars implements Loadable{ public static final int maxBrokenBlocks = 256; /** Maximum schematic size.*/ public static final int maxSchematicSize = 32; + /** All schematic base64 starts with this string.*/ + public static final String schematicBaseStart ="bXNjaAB"; /** IO buffer size. */ public static final int bufferSize = 8192; /** global charset, since Android doesn't support the Charsets class */ diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index d96fda1e1c..f76a3e199a 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -71,7 +71,7 @@ public class DesktopInput extends InputHandler{ lastSchematic.tags.put("name", text); schematics.add(lastSchematic); ui.showInfoFade("$schematic.saved"); - //ui.schematics.showInfo(lastSchematic); + ui.schematics.showInfo(lastSchematic); }); }).colspan(2).size(250f, 50f); }); diff --git a/core/src/io/anuke/mindustry/ui/dialogs/FloatingDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/FloatingDialog.java index de9f1ad85e..09924218d0 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/FloatingDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/FloatingDialog.java @@ -55,6 +55,7 @@ public class FloatingDialog extends Dialog{ @Override public void addCloseButton(){ + buttons.defaults().size(210f, 64f); buttons.addImageTextButton("$back", Icon.arrowLeft, this::hide).size(210f, 64f); keyDown(key -> { diff --git a/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java index 8d0afd5fd9..d124cc54fa 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/SchematicsDialog.java @@ -31,6 +31,7 @@ public class SchematicsDialog extends FloatingDialog{ shouldPause = true; addCloseButton(); + buttons.addImageTextButton("$schematic.import", Icon.loadMapSmall, this::showImport); shown(this::setup); } @@ -80,11 +81,9 @@ public class SchematicsDialog extends FloatingDialog{ showInfo(s); }); - //if(s.isWorkshop()){ buttons.addImageButton(Icon.loadMapSmall, style, () -> { showExport(s); }); - //} buttons.addImageButton(Icon.pencilSmall, style, () -> { ui.showTextInput("$schematic.rename", "$name", s.name(), res -> { @@ -131,6 +130,49 @@ public class SchematicsDialog extends FloatingDialog{ info.show(schematic); } + public void showImport(){ + FloatingDialog dialog = new FloatingDialog("$editor.export"); + dialog.cont.pane(p -> { + p.margin(10f); + p.table(Tex.button, t -> { + TextButtonStyle style = Styles.cleart; + t.defaults().size(280f, 60f).left(); + t.row(); + t.addImageTextButton("$schematic.copy", Icon.copySmall, style, () -> { + dialog.hide(); + try{ + schematics.add(schematics.readBase64(Core.app.getClipboardText())); + ui.showInfoFade("$schematic.saved"); + }catch(Exception e){ + ui.showException(e); + } + }).marginLeft(12f).disabled(b -> Core.app.getClipboardText() == null || !Core.app.getClipboardText().startsWith("schematicBaseStart")); + t.row(); + t.addImageTextButton("$schematic.importfile", Icon.saveMapSmall, style, () -> platform.showFileChooser(true, schematicExtension, file -> { + dialog.hide(); + + try{ + Schematic s = Schematics.read(file); + schematics.add(s); + showInfo(s); + }catch(Exception e){ + ui.showException(e); + } + })).marginLeft(12f); + t.row(); + if(steam){ + t.addImageTextButton("$schematic.browseworkshop", Icon.wikiSmall, style, () -> { + dialog.hide(); + platform.openWorkshop(); + }).marginLeft(12f); + } + }); + }); + + dialog.addCloseButton(); + dialog.show(); + } + public void showExport(Schematic s){ FloatingDialog dialog = new FloatingDialog("$editor.export"); dialog.cont.pane(p -> { @@ -138,10 +180,12 @@ public class SchematicsDialog extends FloatingDialog{ p.table(Tex.button, t -> { TextButtonStyle style = Styles.cleart; t.defaults().size(280f, 60f).left(); - t.addImageTextButton("$schematic.shareworkshop", Icon.wikiSmall, style, () -> { + if(steam){ + t.addImageTextButton("$schematic.shareworkshop", Icon.wikiSmall, style, () -> { - }).marginLeft(12f); - t.row(); + }).marginLeft(12f); + t.row(); + } t.addImageTextButton("$schematic.copy", Icon.copySmall, style, () -> { dialog.hide(); ui.showInfoFade("$copied"); diff --git a/desktop/src/io/anuke/mindustry/desktop/steam/SWorkshop.java b/desktop/src/io/anuke/mindustry/desktop/steam/SWorkshop.java index 76f802911d..99487fed5d 100644 --- a/desktop/src/io/anuke/mindustry/desktop/steam/SWorkshop.java +++ b/desktop/src/io/anuke/mindustry/desktop/steam/SWorkshop.java @@ -92,6 +92,10 @@ public class SWorkshop implements SteamUGCCallback{ dialog.show(); } + public void publishSchematic(Schematic schematic){ + + } + public void viewMapListingInfo(Map map){ String id = map.tags.get("steamid"); long handle = Strings.parseLong(id, -1);