mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-25 22:17:59 +07:00
Many editor bugfixes, server additions
This commit is contained in:
parent
ed34bbff5a
commit
4dee8ba150
@ -22,6 +22,7 @@ public class Maps implements Disposable{
|
||||
private Map networkMap;
|
||||
private int lastID;
|
||||
private Json json = new Json();
|
||||
private Array<Map> array = new Array<>();
|
||||
|
||||
public Maps() {
|
||||
json.setOutputType(OutputType.json);
|
||||
@ -37,6 +38,14 @@ public class Maps implements Disposable{
|
||||
return defaultMaps;
|
||||
}
|
||||
|
||||
public Array<Map> getAllMaps(){
|
||||
array.clear();
|
||||
for(Map map : list()){
|
||||
array.add(map);
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public void setNetworkMap(Map map){
|
||||
if(networkMap != null){
|
||||
networkMap.pixmap.dispose();
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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<Map> loader) {
|
||||
super("$text.editor.loadmap");
|
||||
|
||||
shown(this::rebuild);
|
||||
rebuild();
|
||||
|
||||
TextButton button = new TextButton("$text.load");
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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<Map> 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", "<on/off>", "Enable or disable automatic random map shuffling after gameovers.", arg -> {
|
||||
handler.register("shuffle", "<on/off> <custom maps on/off>", "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.");
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user