diff --git a/core/assets/maps/lake.msav b/core/assets/maps/lake.msav index da7acda1fa..ab97d14a8d 100644 Binary files a/core/assets/maps/lake.msav and b/core/assets/maps/lake.msav differ diff --git a/core/src/mindustry/core/World.java b/core/src/mindustry/core/World.java index ef8e6478d5..6872b5df95 100644 --- a/core/src/mindustry/core/World.java +++ b/core/src/mindustry/core/World.java @@ -174,7 +174,7 @@ public class World{ return x + y * tiles.width; } - private void clearTileEntities(){ + public void clearBuildings(){ for(Tile tile : tiles){ if(tile != null && tile.build != null){ tile.build.remove(); @@ -187,7 +187,7 @@ public class World{ * Only use for loading saves! */ public Tiles resize(int width, int height){ - clearTileEntities(); + clearBuildings(); if(tiles.width != width || tiles.height != height){ tiles = new Tiles(width, height); diff --git a/core/src/mindustry/editor/MapEditor.java b/core/src/mindustry/editor/MapEditor.java index c76a17818d..96418def2f 100644 --- a/core/src/mindustry/editor/MapEditor.java +++ b/core/src/mindustry/editor/MapEditor.java @@ -284,14 +284,17 @@ public class MapEditor{ } } - public void resize(int width, int height){ + public void resize(int width, int height, int shiftX, int shiftY){ clearOp(); Tiles previous = world.tiles; - int offsetX = (width() - width) / 2, offsetY = (height() - height) / 2; + int offsetX = (width() - width) / 2 - shiftX, offsetY = (height() - height) / 2 - shiftY; loading = true; - Tiles tiles = world.resize(width, height); + world.clearBuildings(); + + Tiles tiles = world.tiles = new Tiles(width, height); + for(int x = 0; x < width; x++){ for(int y = 0; y < height; y++){ int px = offsetX + x, py = offsetY + y; diff --git a/core/src/mindustry/editor/MapEditorDialog.java b/core/src/mindustry/editor/MapEditorDialog.java index e18af7f2a9..5f387c1d74 100644 --- a/core/src/mindustry/editor/MapEditorDialog.java +++ b/core/src/mindustry/editor/MapEditorDialog.java @@ -188,10 +188,10 @@ public class MapEditorDialog extends Dialog implements Disposable{ menu.hide(); }).padTop(!steam && !experimental ? -3 : 1).size(swidth * 2f + 10, 60f); - resizeDialog = new MapResizeDialog((x, y) -> { - if(!(editor.width() == x && editor.height() == y)){ + resizeDialog = new MapResizeDialog((width, height, shiftX, shiftY) -> { + if(!(editor.width() == width && editor.height() == height && shiftX == 0 && shiftY == 0)){ ui.loadAnd(() -> { - editor.resize(x, y); + editor.resize(width, height, shiftX, shiftY); }); } }); diff --git a/core/src/mindustry/editor/MapResizeDialog.java b/core/src/mindustry/editor/MapResizeDialog.java index f9cbfc8da8..f5ea504b33 100644 --- a/core/src/mindustry/editor/MapResizeDialog.java +++ b/core/src/mindustry/editor/MapResizeDialog.java @@ -1,19 +1,19 @@ package mindustry.editor; -import arc.func.*; import arc.math.*; import arc.scene.ui.TextField.*; import arc.scene.ui.layout.*; import arc.util.*; import mindustry.ui.dialogs.*; + import static mindustry.Vars.*; public class MapResizeDialog extends BaseDialog{ public static int minSize = 50, maxSize = 600, increment = 50; - int width, height; + int width, height, shiftX, shiftY; - public MapResizeDialog(Intc2 cons){ + public MapResizeDialog(ResizeListener cons){ super("@editor.resizemap"); closeOnBack(); @@ -35,6 +35,19 @@ public class MapResizeDialog extends BaseDialog{ table.row(); } + + for(boolean x : Mathf.booleans){ + table.add(x ? "@editor.shiftx" : "@editor.shifty").padRight(8f); + table.defaults().height(60f).padTop(8); + + table.field((x ? shiftX : shiftY) + "", value -> { + int val = Integer.parseInt(value); + if(x) shiftX = val; else shiftY = val; + }).valid(Strings::canParseInt).maxTextLength(3); + + table.row(); + } + cont.row(); cont.add(table); @@ -43,8 +56,12 @@ public class MapResizeDialog extends BaseDialog{ buttons.defaults().size(200f, 50f); buttons.button("@cancel", this::hide); buttons.button("@ok", () -> { - cons.get(width, height); + cons.get(width, height, shiftX, shiftY); hide(); }); } + + public interface ResizeListener{ + void get(int width, int height, int shiftX, int shiftY); + } }