diff --git a/core/src/io/anuke/mindustry/io/Maps.java b/core/src/io/anuke/mindustry/io/Maps.java index fbc56678a4..26eec2fbe1 100644 --- a/core/src/io/anuke/mindustry/io/Maps.java +++ b/core/src/io/anuke/mindustry/io/Maps.java @@ -22,6 +22,7 @@ public class Maps implements Disposable{ private Map networkMap; private int lastID; private Json json = new Json(); + private Array array = new Array<>(); public Maps() { json.setOutputType(OutputType.json); @@ -37,6 +38,14 @@ public class Maps implements Disposable{ return defaultMaps; } + public Array getAllMaps(){ + array.clear(); + for(Map map : list()){ + array.add(map); + } + return array; + } + public void setNetworkMap(Map map){ if(networkMap != null){ networkMap.pixmap.dispose(); diff --git a/core/src/io/anuke/mindustry/mapeditor/MapEditor.java b/core/src/io/anuke/mindustry/mapeditor/MapEditor.java index 3e50e435cd..7ef8f97a47 100644 --- a/core/src/io/anuke/mindustry/mapeditor/MapEditor.java +++ b/core/src/io/anuke/mindustry/mapeditor/MapEditor.java @@ -5,13 +5,11 @@ import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Pixmap; import com.badlogic.gdx.graphics.Pixmap.Format; import com.badlogic.gdx.graphics.Texture; - import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.ColorMapper; import io.anuke.mindustry.world.Map; import io.anuke.mindustry.world.blocks.Blocks; import io.anuke.ucore.graphics.Pixmaps; -import io.anuke.ucore.util.Log; public class MapEditor{ public static final int[] validMapSizes = {128, 256, 512}; @@ -104,7 +102,6 @@ public class MapEditor{ } public void setDrawBlock(Block block){ - Log.info("Setting draw block {0}", block); this.drawBlock = block; pixmap.setColor(ColorMapper.getColor(block)); } diff --git a/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java b/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java index 97dbcfebf9..79ce0e18f8 100644 --- a/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java +++ b/core/src/io/anuke/mindustry/mapeditor/MapEditorDialog.java @@ -124,13 +124,25 @@ public class MapEditorDialog extends Dialog{ ui.loadfrag.show(); if(verifyMap()){ saved = true; + String before = editor.getMap().name; editor.getMap().name = name; Timers.run(10f, () -> { world.maps().saveAndReload(editor.getMap(), editor.pixmap()); loadDialog.rebuild(); ui.loadfrag.hide(); view.clearStack(); + + if(!name.equals(before)) { + Map map = new Map(); + map.name = editor.getMap().name; + map.oreGen = editor.getMap().oreGen; + map.pixmap = Pixmaps.copy(editor.getMap().pixmap); + map.texture = new Texture(map.pixmap); + map.custom = true; + editor.beginEdit(map); + } }); + }else{ ui.loadfrag.hide(); } diff --git a/core/src/io/anuke/mindustry/mapeditor/MapLoadDialog.java b/core/src/io/anuke/mindustry/mapeditor/MapLoadDialog.java index b4f2e7197f..aa71160cfe 100644 --- a/core/src/io/anuke/mindustry/mapeditor/MapLoadDialog.java +++ b/core/src/io/anuke/mindustry/mapeditor/MapLoadDialog.java @@ -1,6 +1,5 @@ package io.anuke.mindustry.mapeditor; -import static io.anuke.mindustry.Vars.*; import io.anuke.mindustry.ui.BorderImage; import io.anuke.mindustry.ui.dialogs.FloatingDialog; import io.anuke.mindustry.world.Map; @@ -10,12 +9,15 @@ import io.anuke.ucore.scene.ui.ScrollPane; import io.anuke.ucore.scene.ui.TextButton; import io.anuke.ucore.scene.ui.layout.Table; +import static io.anuke.mindustry.Vars.world; + public class MapLoadDialog extends FloatingDialog{ private Map selected = world.maps().getMap(0); public MapLoadDialog(Consumer loader) { super("$text.editor.loadmap"); + shown(this::rebuild); rebuild(); TextButton button = new TextButton("$text.load"); diff --git a/core/src/io/anuke/mindustry/mapeditor/MapView.java b/core/src/io/anuke/mindustry/mapeditor/MapView.java index 9fc8c9b274..a4acd5970a 100644 --- a/core/src/io/anuke/mindustry/mapeditor/MapView.java +++ b/core/src/io/anuke/mindustry/mapeditor/MapView.java @@ -1,5 +1,6 @@ package io.anuke.mindustry.mapeditor; +import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Colors; import com.badlogic.gdx.graphics.Pixmap; @@ -177,7 +178,8 @@ public class MapView extends Element implements GestureListener{ public void act(float delta){ super.act(delta); - if(Core.scene.getKeyboardFocus() == null || !(Core.scene.getKeyboardFocus() instanceof TextField)) { + if(Core.scene.getKeyboardFocus() == null || !(Core.scene.getKeyboardFocus() instanceof TextField) && + !Inputs.keyDown(Keys.CONTROL_LEFT)) { float ax = Inputs.getAxis("move_x"); float ay = Inputs.getAxis("move_y"); offsetx -= ax * 15f / zoom; diff --git a/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java index 67aa616e1b..63dff4f4b0 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/LevelDialog.java @@ -95,16 +95,18 @@ public class LevelDialog extends FloatingDialog{ if(i % maxwidth == 0){ maps.row(); } - - //TODO this is a hack - if(!Settings.has("hiscore" + map.name)){ - Settings.defaults("hiscore" + map.name, 1); - } Table inset = new Table("pane-button"); inset.add("[accent]" + Bundles.get("map."+map.name+".name", map.name)).pad(3f); inset.row(); - inset.label((() -> Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name)))) + inset.label((() ->{ + try{ + return Bundles.format("text.level.highscore", Settings.getInt("hiscore" + map.name)); + }catch (Exception e){ + Settings.defaults("hiscore" + map.name, 1); + return Bundles.format("text.level.highscore", 0); + } + })) .pad(3f); inset.pack(); diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index d2f77af4a6..fb9407b9ab 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.server; import com.badlogic.gdx.ApplicationLogger; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.game.Difficulty; @@ -37,6 +38,7 @@ import static io.anuke.ucore.util.Log.*; public class ServerControl extends Module { private final CommandHandler handler = new CommandHandler(""); private boolean shuffle = true; + private boolean shuffleCustom = false; public ServerControl(){ Effects.setScreenShakeProvider((a, b) -> {}); @@ -48,7 +50,7 @@ public class ServerControl extends Module { info("&y" + (packet.name == null ? "" : packet.name) + ": &lb{0}", packet.text); }); - //don't do anything at all for GDX logging + //don't do anything at all for GDX logging: don't want controller info and such Gdx.app.setApplicationLogger(new ApplicationLogger() { @Override public void log(String tag, String message) { } @Override public void log(String tag, String message, Throwable exception) { } @@ -71,9 +73,10 @@ public class ServerControl extends Module { Net.closeServer(); if(shuffle) { + Array maps = shuffleCustom ? world.maps().getAllMaps() : world.maps().getDefaultMaps(); Map previous = world.getMap(); Map map = previous; - while(map == previous || !map.visible) map = world.maps().getDefaultMaps().random(); + while(map == previous || !map.visible) map = maps.random(); info("Selected next map to be {0}.", map.name); state.set(State.playing); @@ -144,6 +147,13 @@ public class ServerControl extends Module { host(); }); + handler.register("maps", "Display all available maps.", arg -> { + Log.info("Maps:"); + for(Map map : world.maps().getAllMaps()){ + Log.info(" &ly{0}: &fi{1} / {2}x{3} {4}", map.name, map.custom ? "Custom" : "Default", ); + } + }); + handler.register("status", "Display server status.", arg -> { if(state.is(State.menu)){ info("&lyStatus: &rserver closed"); @@ -203,8 +213,9 @@ public class ServerControl extends Module { } }); - handler.register("shuffle", "", "Enable or disable automatic random map shuffling after gameovers.", arg -> { + handler.register("shuffle", " ", "Enable or disable automatic random map shuffling after gameovers.", arg -> { String s = arg[0]; + String custom = arg[1]; if(s.equalsIgnoreCase("on")){ shuffle = true; info("Map shuffling enabled."); @@ -212,7 +223,17 @@ public class ServerControl extends Module { shuffle = false; info("Map shuffling disabled."); }else{ - err("Incorrect command usage."); + err("Incorrect enable/disable usage."); + } + + if(custom.equalsIgnoreCase("on")){ + shuffleCustom = true; + info("Custom map shuffling enabled."); + }else if(custom.equalsIgnoreCase("off")){ + shuffleCustom = false; + info("Custom map shuffling disabled."); + }else{ + err("Incorrect enable/disable custom map usage."); } });