1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-10-06 21:07:25 +03:00

Map resize dialog shift options

This commit is contained in:
Anuken 2022-06-23 17:10:44 -04:00
parent d4a33c6d51
commit ac47d22ea1
5 changed files with 32 additions and 12 deletions

Binary file not shown.

View File

@ -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);

View File

@ -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;

View File

@ -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);
});
}
});

View File

@ -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);
}
}