diff --git a/core/src/mindustry/editor/MapObjectivesDialog.java b/core/src/mindustry/editor/MapObjectivesDialog.java index 06bcd077e9..c8f021f214 100644 --- a/core/src/mindustry/editor/MapObjectivesDialog.java +++ b/core/src/mindustry/editor/MapObjectivesDialog.java @@ -1,5 +1,6 @@ package mindustry.editor; +import arc.*; import arc.func.*; import arc.graphics.*; import arc.math.geom.*; @@ -465,10 +466,42 @@ public class MapObjectivesDialog extends BaseDialog{ buttons.defaults().size(160f, 64f).pad(2f); buttons.button("@back", Icon.left, MapObjectivesDialog.this::hide); buttons.button("@add", Icon.add, () -> getProvider(MapObjective.class).get(new TypeInfo(MapObjective.class), canvas::query)); + buttons.button("@waves.edit", Icon.edit, () -> { + BaseDialog dialog = new BaseDialog("@waves.edit"); + dialog.addCloseButton(); + dialog.setFillParent(false); + dialog.cont.table(Tex.button, t -> { + var style = Styles.cleart; + t.defaults().size(280f, 64f).pad(2f); + + t.button("@waves.copy", Icon.copy, style, () -> { + ui.showInfoFade("@copied"); + Core.app.setClipboardText(JsonIO.write(new MapObjectives(canvas.objectives))); + dialog.hide(); + }).disabled(b -> canvas.objectives.isEmpty()).marginLeft(12f).row(); + + t.button("@waves.load", Icon.download, style, () -> { + try{ + rebuildObjectives(new Seq<>(JsonIO.read(MapObjectives.class, Core.app.getClipboardText()).all)); + }catch(Exception e){ + Log.err(e); + ui.showErrorMessage("@waves.invalid"); + } + dialog.hide(); + }).disabled(Core.app.getClipboardText() == null || !Core.app.getClipboardText().startsWith("[")).marginLeft(12f).row(); + + t.button("@clear", Icon.none, style, () -> ui.showConfirm("@confirm", "@settings.clear.confirm", () -> { + rebuildObjectives(new Seq<>()); + dialog.hide(); + })).marginLeft(12f).row(); + }); + + dialog.show(); + }); if(mobile){ - buttons.button("@cancel", Icon.cancel, canvas::stopQuery).disabled(b -> !canvas.isQuerying()); - buttons.button("@ok", Icon.ok, canvas::placeQuery).disabled(b -> !canvas.isQuerying()); + buttons.button("@cancel", Icon.cancel, canvas::stopQuery).visible(() -> canvas.isQuerying()); + buttons.button("@ok", Icon.ok, canvas::placeQuery).visible(() -> canvas.isQuerying()); } setFillParent(true); @@ -490,22 +523,27 @@ public class MapObjectivesDialog extends BaseDialog{ public void show(Seq objectives, Cons> out){ this.out = out; + rebuildObjectives(objectives); + show(); + } + + public void rebuildObjectives(Seq objectives){ canvas.clearObjectives(); if( - objectives.any() && ( - // If the objectives were previously programmatically made... - objectives.contains(obj -> obj.editorX == -1 || obj.editorY == -1) || - // ... or some idiot somehow made it not work... - objectives.contains(obj -> !canvas.tilemap.createTile(obj)) + objectives.any() && ( + // If the objectives were previously programmatically made... + objectives.contains(obj -> obj.editorX == -1 || obj.editorY == -1) || + // ... or some idiot somehow made it not work... + objectives.contains(obj -> !canvas.tilemap.createTile(obj)) )){ // ... then rebuild the structure. canvas.clearObjectives(); // This is definitely NOT a good way to do it, but only insane people or people from the distant past would actually encounter this anyway. int w = objWidth + 2, - len = objectives.size * w, - columns = objectives.size, - rows = 1; + len = objectives.size * w, + columns = objectives.size, + rows = 1; if(len > bounds){ rows = len / bounds; @@ -525,7 +563,6 @@ public class MapObjectivesDialog extends BaseDialog{ } canvas.objectives.set(objectives); - show(); } public static void showContentSelect(@Nullable ContentType type, Cons cons, Boolf check){ diff --git a/core/src/mindustry/game/MapObjectives.java b/core/src/mindustry/game/MapObjectives.java index fed1223bff..3a6f77e5ae 100644 --- a/core/src/mindustry/game/MapObjectives.java +++ b/core/src/mindustry/game/MapObjectives.java @@ -106,6 +106,13 @@ public class MapObjectives implements Iterable, Eachable all){ + this.all.addAll(all); + } + + public MapObjectives(){ + } + /** Adds all given objectives to the executor as root objectives. */ public void add(MapObjective... objectives){ for(var objective : objectives) flatten(objective);