From 5ffff9c151b522c374e0992f7719ff7dc6ca6bb7 Mon Sep 17 00:00:00 2001 From: summetdev Date: Sat, 3 Oct 2020 22:43:52 +0300 Subject: [PATCH] description for schematics --- core/src/mindustry/game/Schematic.java | 6 ++- core/src/mindustry/input/InputHandler.java | 34 ++++++++++++++- .../ui/dialogs/SchematicsDialog.java | 41 ++++++++++++++----- 3 files changed, 67 insertions(+), 14 deletions(-) diff --git a/core/src/mindustry/game/Schematic.java b/core/src/mindustry/game/Schematic.java index 5ad51382f2..9eaf0d99fe 100644 --- a/core/src/mindustry/game/Schematic.java +++ b/core/src/mindustry/game/Schematic.java @@ -62,6 +62,10 @@ public class Schematic implements Publishable, Comparable{ return tags.get("name", "unknown"); } + public String description(){ + return tags.get("description", ""); + } + public void save(){ schematics.saveChanges(this); } @@ -90,7 +94,7 @@ public class Schematic implements Publishable, Comparable{ @Override public String steamDescription(){ - return null; + return description(); } @Override diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index 9034bcdd07..e27a3f15b2 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -10,6 +10,7 @@ import arc.math.*; import arc.math.geom.*; import arc.scene.*; import arc.scene.event.*; +import arc.scene.ui.*; import arc.scene.ui.layout.*; import arc.struct.*; import arc.util.ArcAnnotate.*; @@ -489,7 +490,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ protected void showSchematicSave(){ if(lastSchematic == null) return; - ui.showTextInput("@schematic.add", "@name", "", text -> { + Cons2 saveSchematic = (text, description) -> { Schematic replacement = schematics.all().find(s -> s.name().equals(text)); if(replacement != null){ ui.showConfirm("@confirm", "@schematic.replace", () -> { @@ -499,11 +500,40 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ }); }else{ lastSchematic.tags.put("name", text); + lastSchematic.tags.put("description", description); schematics.add(lastSchematic); ui.showInfoFade("@schematic.saved"); ui.schematics.showInfo(lastSchematic); } - }); + }; + + new Dialog("@schematic.add"){{ + cont.margin(30).add("@name").padRight(6f); + TextField nameField = cont.field("", t -> {}).size(330f, 50f).addInputDialog().get(); + + cont.row(); + + cont.margin(30).add("@editor.description").padRight(6f); + TextField descripionField = cont.field("", t -> {}).size(330f, 50f).addInputDialog().get(); + + buttons.defaults().size(120, 54).pad(4); + buttons.button("@ok", () -> { + saveSchematic.get(nameField.getText(), descripionField.getText()); + hide(); + }).disabled(b -> nameField.getText().isEmpty()); + buttons.button("@cancel", this::hide); + + keyDown(KeyCode.enter, () -> { + String text = nameField.getText(); + if(!text.isEmpty()){ + saveSchematic.get(text, descripionField.getText()); + hide(); + } + }); + keyDown(KeyCode.escape, this::hide); + keyDown(KeyCode.back, this::hide); + show(); + }}; } public void rotateRequests(Seq requests, int direction){ diff --git a/core/src/mindustry/ui/dialogs/SchematicsDialog.java b/core/src/mindustry/ui/dialogs/SchematicsDialog.java index 7a2afbbd1e..929ab0653f 100644 --- a/core/src/mindustry/ui/dialogs/SchematicsDialog.java +++ b/core/src/mindustry/ui/dialogs/SchematicsDialog.java @@ -4,6 +4,7 @@ import arc.*; import arc.graphics.*; import arc.graphics.Texture.*; import arc.graphics.g2d.*; +import arc.input.*; import arc.math.*; import arc.scene.style.*; import arc.scene.ui.*; @@ -106,18 +107,36 @@ public class SchematicsDialog extends BaseDialog{ }); buttons.button(Icon.pencil, style, () -> { - ui.showTextInput("@schematic.rename", "@name", s.name(), res -> { - Schematic replacement = schematics.all().find(other -> other.name().equals(res) && other != s); - if(replacement != null){ - //renaming to an existing schematic is not allowed, as it is not clear how the tags would be merged, and which one should be removed - ui.showErrorMessage("@schematic.exists"); - return; - } + new Dialog("@schematic.rename"){{ + cont.margin(30).add("@name").padRight(6f); + TextField nameField = cont.field(s.name(), null).size(330f, 50f).addInputDialog().get(); - s.tags.put("name", res); - s.save(); - rebuildPane[0].run(); - }); + cont.row(); + + cont.margin(30).add("@editor.description").padRight(6f); + TextField descripionField = cont.field(s.description(), null).size(330f, 50f).addInputDialog().get(); + + Runnable accept = () -> { + s.tags.put("name", nameField.getText()); + s.tags.put("description", descripionField.getText()); + s.save(); + hide(); + rebuildPane[0].run(); + }; + + buttons.defaults().size(120, 54).pad(4); + buttons.button("@ok", accept).disabled(b -> nameField.getText().isEmpty()); + buttons.button("@cancel", this::hide); + + keyDown(KeyCode.enter, () -> { + if(!nameField.getText().isEmpty()){ + accept.run(); + } + }); + keyDown(KeyCode.escape, this::hide); + keyDown(KeyCode.back, this::hide); + show(); + }}; }); if(s.hasSteamID()){