From a39fe2cb37bce3bd0a1759e5edc9040f757aaced Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 23 Jun 2022 16:32:37 -0400 Subject: [PATCH] WIP map info dialog changes --- core/src/mindustry/editor/MapInfoDialog.java | 65 +++++++++-------- .../mindustry/editor/MapObjectivesDialog.java | 70 +++++++++++++++++++ core/src/mindustry/io/JsonIO.java | 18 +++++ 3 files changed, 125 insertions(+), 28 deletions(-) create mode 100644 core/src/mindustry/editor/MapObjectivesDialog.java diff --git a/core/src/mindustry/editor/MapInfoDialog.java b/core/src/mindustry/editor/MapInfoDialog.java index 379b292f08..83c606db1e 100644 --- a/core/src/mindustry/editor/MapInfoDialog.java +++ b/core/src/mindustry/editor/MapInfoDialog.java @@ -1,10 +1,10 @@ package mindustry.editor; -import arc.*; import arc.scene.ui.*; import arc.struct.*; import mindustry.*; import mindustry.game.*; +import mindustry.gen.*; import mindustry.io.*; import mindustry.maps.filters.*; import mindustry.ui.*; @@ -16,6 +16,7 @@ public class MapInfoDialog extends BaseDialog{ private final WaveInfoDialog waveInfo; private final MapGenerateDialog generate; private final CustomRulesDialog ruleInfo = new CustomRulesDialog(); + private final MapObjectivesDialog objectives = new MapObjectivesDialog(); public MapInfoDialog(){ super("@editor.mapinfo"); @@ -51,41 +52,49 @@ public class MapInfoDialog extends BaseDialog{ t.row(); t.add("@editor.author").padRight(8).left(); - TextField author = t.field(tags.get("author", Core.settings.getString("mapAuthor", "")), text -> { + TextField author = t.field(tags.get("author", ""), text -> { tags.put("author", text); - Core.settings.put("mapAuthor", text); }).size(400, 55f).maxTextLength(50).get(); author.setMessageText("@unknown"); t.row(); - t.add("@editor.rules").padRight(8).left(); - t.button("@edit", () -> { - ruleInfo.show(Vars.state.rules, () -> Vars.state.rules = new Rules()); - hide(); - }).left().width(200f); - t.row(); - t.add("@editor.waves").padRight(8).left(); - t.button("@edit", () -> { - waveInfo.show(); - hide(); - }).left().width(200f); + t.table(Tex.button, r -> { + r.defaults().width(230f).height(60f); - t.row(); - t.add("@editor.generation").padRight(8).left(); - t.button("@edit", () -> { - //randomize so they're not all the same seed - var res = maps.readFilters(editor.tags.get("genfilters", "")); - res.each(GenerateFilter::randomize); + var style = Styles.flatt; - generate.show(res, - filters -> { - //reset seed to 0 so it is not written - filters.each(f -> f.seed = 0); - editor.tags.put("genfilters", JsonIO.write(filters)); - }); - hide(); - }).left().width(200f); + r.button("@editor.rules", Icon.list, style, () -> { + ruleInfo.show(Vars.state.rules, () -> Vars.state.rules = new Rules()); + hide(); + }).marginLeft(10f); + + r.button("@editor.waves", Icon.units, style, () -> { + waveInfo.show(); + hide(); + }).marginLeft(10f); + + r.row(); + + r.button("@editor.objectives", Icon.info, style, () -> { + objectives.show(state.rules.objectives); + hide(); + }).marginLeft(10f); + + r.button("@editor.generation", Icon.terrain, style, () -> { + //randomize so they're not all the same seed + var res = maps.readFilters(editor.tags.get("genfilters", "")); + res.each(GenerateFilter::randomize); + + generate.show(res, + filters -> { + //reset seed to 0 so it is not written + filters.each(f -> f.seed = 0); + editor.tags.put("genfilters", JsonIO.write(filters)); + }); + hide(); + }).marginLeft(10f); + }).colspan(2).center(); name.change(); description.change(); diff --git a/core/src/mindustry/editor/MapObjectivesDialog.java b/core/src/mindustry/editor/MapObjectivesDialog.java new file mode 100644 index 0000000000..52554a5fae --- /dev/null +++ b/core/src/mindustry/editor/MapObjectivesDialog.java @@ -0,0 +1,70 @@ +package mindustry.editor; + +import arc.*; +import arc.struct.*; +import mindustry.game.MapObjectives.*; +import mindustry.gen.*; +import mindustry.io.*; +import mindustry.ui.*; +import mindustry.ui.dialogs.*; + +import static mindustry.Vars.*; + +public class MapObjectivesDialog extends BaseDialog{ + private Seq objectives = new Seq<>(); + + public MapObjectivesDialog(){ + super("@editor.objectives"); + + buttons.defaults().size(180f, 64f).pad(2f); + buttons.button("@back", Icon.left, this::hide); + + buttons.button("@edit", Icon.edit, () -> { + BaseDialog dialog = new BaseDialog("@editor.export"); + dialog.cont.pane(p -> { + p.margin(10f); + p.table(Tex.button, in -> { + var style = Styles.flatt; + + in.defaults().size(280f, 60f).left(); + + in.button("@waves.copy", Icon.copy, style, () -> { + dialog.hide(); + + Core.app.setClipboardText(JsonIO.write(objectives)); + }).marginLeft(12f).row(); + in.button("@waves.load", Icon.download, style, () -> { + dialog.hide(); + try{ + objectives.set(JsonIO.read(Seq.class, Core.app.getClipboardText())); + + setup(); + }catch(Throwable e){ + ui.showException(e); + } + }).marginLeft(12f).disabled(b -> Core.app.getClipboardText() == null).row(); + in.button("@clear", Icon.none, style, () -> { + dialog.hide(); + objectives.clear(); + setup(); + }).marginLeft(12f).row(); + }); + }); + + dialog.addCloseButton(); + dialog.show(); + }); + } + + public void show(Seq objectives){ + super.show(); + + this.objectives = objectives; + setup(); + } + + void setup(){ + cont.clear(); + cont.add("This editor doesn't work yet. Come back later."); + } +} diff --git a/core/src/mindustry/io/JsonIO.java b/core/src/mindustry/io/JsonIO.java index 2a3bb0c219..784dfbc583 100644 --- a/core/src/mindustry/io/JsonIO.java +++ b/core/src/mindustry/io/JsonIO.java @@ -1,5 +1,6 @@ package mindustry.io; +import arc.graphics.*; import arc.util.*; import arc.util.serialization.*; import arc.util.serialization.Json.*; @@ -72,6 +73,23 @@ public class JsonIO{ json.setElementType(Rules.class, "spawns", SpawnGroup.class); json.setElementType(Rules.class, "loadout", ItemStack.class); + json.setSerializer(Color.class, new Serializer<>(){ + @Override + public void write(Json json, Color object, Class knownType){ + json.writeValue(object.toString()); + } + + @Override + public Color read(Json json, JsonValue jsonData, Class type){ + if(jsonData.isString()){ + return Color.valueOf(jsonData.asString()); + } + Color out = new Color(); + json.readFields(out, jsonData); + return out; + } + }); + json.setSerializer(Sector.class, new Serializer<>(){ @Override public void write(Json json, Sector object, Class knownType){