From f0fa126e7b1c42ea59609a399a28f7c61f7e0467 Mon Sep 17 00:00:00 2001 From: Anuken Date: Tue, 22 May 2018 14:16:12 -0400 Subject: [PATCH] Changed map edit menu, added map info dialog --- core/assets-raw/sprites/ui/textarea.9.png | Bin 0 -> 216 bytes core/assets/bundles/bundle.properties | 5 + core/assets/sprites/sprites.atlas | 8 ++ core/assets/ui/uiskin.json | 2 + .../io/anuke/mindustry/editor/MapEditor.java | 14 ++- .../mindustry/editor/MapEditorDialog.java | 104 ++++++++++-------- .../anuke/mindustry/editor/MapInfoDialog.java | 67 +++++++++++ 7 files changed, 151 insertions(+), 49 deletions(-) create mode 100644 core/assets-raw/sprites/ui/textarea.9.png create mode 100644 core/src/io/anuke/mindustry/editor/MapInfoDialog.java diff --git a/core/assets-raw/sprites/ui/textarea.9.png b/core/assets-raw/sprites/ui/textarea.9.png new file mode 100644 index 0000000000000000000000000000000000000000..87ccdd2e7c62684b5076f13f4e9aeec86ed63adc GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0y~yV31;9V9?@VV_;xdYv7&Cz`($k|H*Y zfq{Xuz$3Dlfq`2Xgc%uT&5>YWU|=ut^mS!_#40Als3K5cI)#COA=T5xF(l&f+v$#6 z2Mjn^%Dw+T%C1?v{-f!)IF2os*k--E<7B|Rn%()%V!!k_T@{8M)el{jnxxef183Kk zOq{uv{j85|Ra{7ypHipFB#%Y*ohx4K+v(6J=IFZphe1g_->ZvJi!x;v-r@ tags = new ObjectMap<>(); private TileDataMarker multiWriter; private MapRenderer renderer = new MapRenderer(this); @@ -31,11 +33,17 @@ public class MapEditor{ public MapTileData getMap(){ return map; } - - public void beginEdit(MapTileData map){ - drawBlock = Blocks.stone; + + public ObjectMap getTags() { + return tags; + } + + public void beginEdit(MapTileData map, ObjectMap tags){ this.map = map; this.brushSize = 1; + this.tags = tags; + + drawBlock = Blocks.stone; multiWriter = map.new TileDataMarker(); renderer.resize(map.width(), map.height()); } diff --git a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java index f0a4893844..49867518a2 100644 --- a/core/src/io/anuke/mindustry/editor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/editor/MapEditorDialog.java @@ -9,6 +9,7 @@ import com.badlogic.gdx.utils.ObjectMap; import io.anuke.mindustry.content.blocks.Blocks; import io.anuke.mindustry.game.Team; import io.anuke.mindustry.io.MapIO; +import io.anuke.mindustry.io.MapMeta; import io.anuke.mindustry.io.MapTileData; import io.anuke.mindustry.io.Platform; import io.anuke.mindustry.ui.dialogs.FileChooser; @@ -43,7 +44,7 @@ import static io.anuke.mindustry.Vars.*; public class MapEditorDialog extends Dialog{ private MapEditor editor; private MapView view; - private MapGenerateDialog dialog; + private MapInfoDialog infoDialog; private MapLoadDialog loadDialog; private MapSaveDialog saveDialog; private MapResizeDialog resizeDialog; @@ -60,9 +61,10 @@ public class MapEditorDialog extends Dialog{ if(gwt) return; editor = new MapEditor(); - dialog = new MapGenerateDialog(editor); view = new MapView(editor); + infoDialog = new MapInfoDialog(editor); + saveFile = new FileChooser("$text.saveimage", false, file -> { file = file.parent().child(file.nameWithoutExtension() + "." + mapExtension); FileHandle result = file; @@ -70,8 +72,10 @@ public class MapEditorDialog extends Dialog{ Timers.run(3f, () -> { try{ - tags.put("name", result.nameWithoutExtension()); - MapIO.writeMap(result, tags, editor.getMap()); + if(!editor.getTags().containsKey("name")){ + tags.put("name", result.nameWithoutExtension()); + } + MapIO.writeMap(result, editor.getTags(), editor.getMap()); }catch (Exception e){ ui.showError(Bundles.format("text.editor.errorimagesave", Strings.parseException(e, false))); Log.err(e); @@ -84,9 +88,12 @@ public class MapEditorDialog extends Dialog{ ui.loadfrag.show(); Timers.run(3f, () -> { try{ - MapTileData data = MapIO.readTileData(new DataInputStream(file.read()), false); + DataInputStream stream = new DataInputStream(file.read()); - editor.beginEdit(data); + MapMeta meta = MapIO.readMapMeta(stream); + MapTileData data = MapIO.readTileData(stream, meta, false); + + editor.beginEdit(data, meta.tags); view.clearStack(); }catch (Exception e){ ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false))); @@ -117,7 +124,7 @@ public class MapEditorDialog extends Dialog{ try{ MapTileData data = MapIO.readPixmap(new Pixmap(file)); - editor.beginEdit(data); + editor.beginEdit(data, new ObjectMap<>()); view.clearStack(); }catch (Exception e){ ui.showError(Bundles.format("text.editor.errorimageload", Strings.parseException(e, false))); @@ -130,10 +137,50 @@ public class MapEditorDialog extends Dialog{ menu = new FloatingDialog("$text.menu"); menu.addCloseButton(); - menu.content().defaults().size(280f, 60f).padBottom(5); - float isize = 16*2f; + menu.content().table(t -> { + t.defaults().size(230f, 60f).padBottom(5).padRight(5).padLeft(5); + + t.addImageTextButton("$text.editor.mapinfo", "icon-pencil", isize, () -> { + infoDialog.show(); + menu.hide(); + }); + + t.addImageTextButton("$text.editor.resize", "icon-resize", isize, () -> { + resizeDialog.show(); + menu.hide(); + }); + + t.row(); + + t.addImageTextButton("$text.editor.savemap", "icon-save-map", isize, () -> { + saveFile.show(); + menu.hide(); + }); + + t.addImageTextButton("$text.editor.loadmap", "icon-load-map", isize, () -> { + openFile.show(); + menu.hide(); + }); + + t.row(); + + t.addImageTextButton("$text.editor.saveimage", "icon-save-map", isize, () -> { + saveImage.show(); + menu.hide(); + }); + + t.addImageTextButton("$text.editor.loadimage", "icon-load-map", isize, () -> { + openImage.show(); + menu.hide(); + }); + + t.row(); + }); + + menu.content().row(); + menu.content().addImageTextButton("$text.quit", "icon-back", isize, () -> { if(!saved){ ui.showConfirm("$text.confirm", "$text.editor.unsaved", this::hide); @@ -141,42 +188,7 @@ public class MapEditorDialog extends Dialog{ hide(); } menu.hide(); - }); - - menu.content().row(); - - menu.content().addImageTextButton("$text.editor.resize", "icon-resize", isize, () -> { - resizeDialog.show(); - menu.hide(); - }); - - menu.content().row(); - - menu.content().addImageTextButton("$text.editor.savemap", "icon-save-map", isize, () -> { - saveFile.show(); - menu.hide(); - }); - - menu.content().row(); - - menu.content().addImageTextButton("$text.editor.loadmap", "icon-load-map", isize, () -> { - openFile.show(); - menu.hide(); - }); - - menu.content().row(); - - menu.content().addImageTextButton("$text.editor.saveimage", "icon-save-map", isize, () -> { - saveImage.show(); - menu.hide(); - }); - - menu.content().row(); - - menu.content().addImageTextButton("$text.editor.loadimage", "icon-load-map", isize, () -> { - openImage.show(); - menu.hide(); - }); + }).size(470f, 60f); /* @@ -258,7 +270,7 @@ public class MapEditorDialog extends Dialog{ shown(() -> { saved = true; - editor.beginEdit(new MapTileData(256, 256)); + editor.beginEdit(new MapTileData(256, 256), new ObjectMap<>()); blockgroup.getButtons().get(2).setChecked(true); Core.scene.setScrollFocus(view); view.clearStack(); diff --git a/core/src/io/anuke/mindustry/editor/MapInfoDialog.java b/core/src/io/anuke/mindustry/editor/MapInfoDialog.java new file mode 100644 index 0000000000..fc0723dbe5 --- /dev/null +++ b/core/src/io/anuke/mindustry/editor/MapInfoDialog.java @@ -0,0 +1,67 @@ +package io.anuke.mindustry.editor; + +import com.badlogic.gdx.utils.ObjectMap; +import io.anuke.mindustry.io.Platform; +import io.anuke.mindustry.ui.dialogs.FloatingDialog; +import io.anuke.ucore.core.Settings; +import io.anuke.ucore.scene.ui.TextArea; +import io.anuke.ucore.scene.ui.TextField; + +public class MapInfoDialog extends FloatingDialog{ + private final MapEditor editor; + + private TextArea description; + private TextField author; + private TextField name; + + public MapInfoDialog(MapEditor editor){ + super("$text.editor.mapinfo"); + this.editor = editor; + + addCloseButton(); + + shown(this::setup); + + hidden(() -> { + + }); + } + + private void setup(){ + content().clear(); + + ObjectMap tags = editor.getTags(); + + content().add("$text.editor.name").padRight(8).left(); + + content().defaults().padTop(15); + + name = content().addField(tags.get("name", ""), text -> { + tags.put("name", text); + }).size(400, 55f).get(); + name.setMessageText("$text.unknown"); + + content().row(); + + content().add("$text.editor.description").padRight(8).left(); + + description = content().addArea(tags.get("description", ""), "textarea", text -> { + tags.put("description", text); + }).size(400f, 130f).get(); + + content().row(); + + content().add("$text.editor.author").padRight(8).left(); + + author = content().addField(tags.get("author", Settings.getString("mapAuthor", "")), text -> { + tags.put("author", text); + Settings.putString("mapAuthor", text); + Settings.save(); + }).size(400, 55f).get(); + author.setMessageText("$text.unknown"); + + Platform.instance.addDialog(name, 50); + Platform.instance.addDialog(author, 50); + Platform.instance.addDialog(description, 1000); + } +}