Map resize dialog shift options
This commit is contained in:
Binary file not shown.
@@ -174,7 +174,7 @@ public class World{
|
|||||||
return x + y * tiles.width;
|
return x + y * tiles.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearTileEntities(){
|
public void clearBuildings(){
|
||||||
for(Tile tile : tiles){
|
for(Tile tile : tiles){
|
||||||
if(tile != null && tile.build != null){
|
if(tile != null && tile.build != null){
|
||||||
tile.build.remove();
|
tile.build.remove();
|
||||||
@@ -187,7 +187,7 @@ public class World{
|
|||||||
* Only use for loading saves!
|
* Only use for loading saves!
|
||||||
*/
|
*/
|
||||||
public Tiles resize(int width, int height){
|
public Tiles resize(int width, int height){
|
||||||
clearTileEntities();
|
clearBuildings();
|
||||||
|
|
||||||
if(tiles.width != width || tiles.height != height){
|
if(tiles.width != width || tiles.height != height){
|
||||||
tiles = new Tiles(width, height);
|
tiles = new Tiles(width, height);
|
||||||
|
|||||||
@@ -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();
|
clearOp();
|
||||||
|
|
||||||
Tiles previous = world.tiles;
|
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;
|
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 x = 0; x < width; x++){
|
||||||
for(int y = 0; y < height; y++){
|
for(int y = 0; y < height; y++){
|
||||||
int px = offsetX + x, py = offsetY + y;
|
int px = offsetX + x, py = offsetY + y;
|
||||||
|
|||||||
@@ -188,10 +188,10 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
menu.hide();
|
menu.hide();
|
||||||
}).padTop(!steam && !experimental ? -3 : 1).size(swidth * 2f + 10, 60f);
|
}).padTop(!steam && !experimental ? -3 : 1).size(swidth * 2f + 10, 60f);
|
||||||
|
|
||||||
resizeDialog = new MapResizeDialog((x, y) -> {
|
resizeDialog = new MapResizeDialog((width, height, shiftX, shiftY) -> {
|
||||||
if(!(editor.width() == x && editor.height() == y)){
|
if(!(editor.width() == width && editor.height() == height && shiftX == 0 && shiftY == 0)){
|
||||||
ui.loadAnd(() -> {
|
ui.loadAnd(() -> {
|
||||||
editor.resize(x, y);
|
editor.resize(width, height, shiftX, shiftY);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
package mindustry.editor;
|
package mindustry.editor;
|
||||||
|
|
||||||
import arc.func.*;
|
|
||||||
import arc.math.*;
|
import arc.math.*;
|
||||||
import arc.scene.ui.TextField.*;
|
import arc.scene.ui.TextField.*;
|
||||||
import arc.scene.ui.layout.*;
|
import arc.scene.ui.layout.*;
|
||||||
import arc.util.*;
|
import arc.util.*;
|
||||||
import mindustry.ui.dialogs.*;
|
import mindustry.ui.dialogs.*;
|
||||||
|
|
||||||
import static mindustry.Vars.*;
|
import static mindustry.Vars.*;
|
||||||
|
|
||||||
public class MapResizeDialog extends BaseDialog{
|
public class MapResizeDialog extends BaseDialog{
|
||||||
public static int minSize = 50, maxSize = 600, increment = 50;
|
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");
|
super("@editor.resizemap");
|
||||||
|
|
||||||
closeOnBack();
|
closeOnBack();
|
||||||
@@ -35,6 +35,19 @@ public class MapResizeDialog extends BaseDialog{
|
|||||||
|
|
||||||
table.row();
|
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.row();
|
||||||
cont.add(table);
|
cont.add(table);
|
||||||
|
|
||||||
@@ -43,8 +56,12 @@ public class MapResizeDialog extends BaseDialog{
|
|||||||
buttons.defaults().size(200f, 50f);
|
buttons.defaults().size(200f, 50f);
|
||||||
buttons.button("@cancel", this::hide);
|
buttons.button("@cancel", this::hide);
|
||||||
buttons.button("@ok", () -> {
|
buttons.button("@ok", () -> {
|
||||||
cons.get(width, height);
|
cons.get(width, height, shiftX, shiftY);
|
||||||
hide();
|
hide();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface ResizeListener{
|
||||||
|
void get(int width, int height, int shiftX, int shiftY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user