From 6e44ff1de182d0c2f738181b396401e9f73fb6cd Mon Sep 17 00:00:00 2001 From: Anuken Date: Sun, 20 Jul 2025 19:33:37 -0400 Subject: [PATCH] Misc map editor fixes --- core/src/mindustry/editor/DrawOperation.java | 21 +++++-- core/src/mindustry/editor/EditorTile.java | 15 ++--- core/src/mindustry/editor/MapEditor.java | 5 ++ .../src/mindustry/editor/MapEditorDialog.java | 21 ++++--- core/src/mindustry/editor/MapRenderer.java | 59 +++++++++++++++---- core/src/mindustry/editor/MapView.java | 2 +- 6 files changed, 84 insertions(+), 39 deletions(-) diff --git a/core/src/mindustry/editor/DrawOperation.java b/core/src/mindustry/editor/DrawOperation.java index 903b38a588..a67253ce80 100755 --- a/core/src/mindustry/editor/DrawOperation.java +++ b/core/src/mindustry/editor/DrawOperation.java @@ -57,6 +57,15 @@ public class DrawOperation{ } void setTile(Tile tile, byte type, short to){ + if(type == opBlock || type == opTeam || type == opRotation){ + tile.getLinkedTiles(t -> { + editor.renderer.updateBlock(t); + editor.renderer.updateStatic(t.x, t.y); + }); + }else{ + editor.renderer.updateStatic(tile.x, tile.y); + } + editor.load(() -> { switch(type){ case opFloor -> { @@ -70,15 +79,11 @@ public class DrawOperation{ } } case opBlock -> { - tile.getLinkedTiles(t -> editor.renderer.updateStatic(t.x, t.y)); - Block block = content.block(to); tile.setBlock(block, tile.team(), tile.build == null ? 0 : tile.build.rotation); if(tile.build != null){ tile.build.enabled = true; } - - tile.getLinkedTiles(t -> editor.renderer.updateStatic(t.x, t.y)); } case opRotation -> { if(tile.build != null) tile.build.rotation = to; @@ -86,7 +91,13 @@ public class DrawOperation{ case opTeam -> tile.setTeam(Team.get(to)); } }); - editor.renderer.updateStatic(tile.x, tile.y); + + if(type == opBlock || type == opTeam || type == opRotation){ + tile.getLinkedTiles(t -> { + editor.renderer.updateBlock(t); + editor.renderer.updateStatic(t.x, t.y); + }); + } } @Struct diff --git a/core/src/mindustry/editor/EditorTile.java b/core/src/mindustry/editor/EditorTile.java index 47a5aee534..3aec80c678 100644 --- a/core/src/mindustry/editor/EditorTile.java +++ b/core/src/mindustry/editor/EditorTile.java @@ -56,7 +56,6 @@ public class EditorTile extends Tile{ } if(this.block == type && (build == null || build.rotation == rotation)){ - updateStatic(); return; } @@ -76,15 +75,9 @@ public class EditorTile extends Tile{ if(requiresBlockUpdate(type) || requiresBlockUpdate(prev)){ if(prev.size > 1){ - prevCenter.getLinkedTilesAs(prev, tile -> { - editor.renderer.updateBlock(tile.x, tile.y); - renderer.blocks.updateShadowTile(tile); - }); + prevCenter.getLinkedTilesAs(prev, tile -> editor.renderer.updateBlock(tile)); } - getLinkedTiles(tile -> { - editor.renderer.updateBlock(tile.x, tile.y); - renderer.blocks.updateShadowTile(tile); - }); + getLinkedTiles(tile -> editor.renderer.updateBlock(tile)); }else{ renderer.blocks.updateShadowTile(this); } @@ -97,11 +90,11 @@ public class EditorTile extends Tile{ return; } - if(getTeamID() == team.id) return; + if(getTeamID() == team.id || !synthetic()) return; op(DrawOperation.opTeam, (byte)getTeamID()); super.setTeam(team); - getLinkedTiles(t -> editor.renderer.updateStatic(t.x, t.y)); + getLinkedTiles(t -> editor.renderer.updateBlock(t.x, t.y)); } @Override diff --git a/core/src/mindustry/editor/MapEditor.java b/core/src/mindustry/editor/MapEditor.java index e663e7d8cc..2562a6a8df 100644 --- a/core/src/mindustry/editor/MapEditor.java +++ b/core/src/mindustry/editor/MapEditor.java @@ -148,6 +148,7 @@ public class MapEditor{ y = Mathf.clamp(y, (drawBlock.size - 1) / 2, height() - drawBlock.size / 2 - 1); if(!hasOverlap(x, y)){ tile(x, y).setBlock(drawBlock, drawTeam, rotation); + addTileOp(TileOp.get((short)x, (short)y, (byte)DrawOperation.opTeam, (byte)drawTeam.id)); } }else{ boolean isFloor = drawBlock.isFloor() && drawBlock != Blocks.air; @@ -169,6 +170,10 @@ public class MapEditor{ } tile.setBlock(drawBlock, drawTeam, rotation); + + if(drawBlock.synthetic()){ + addTileOp(TileOp.get(tile.x, tile.y, (byte)DrawOperation.opTeam, (byte)drawTeam.id)); + } } }; diff --git a/core/src/mindustry/editor/MapEditorDialog.java b/core/src/mindustry/editor/MapEditorDialog.java index f1755db39d..47e1a979c8 100644 --- a/core/src/mindustry/editor/MapEditorDialog.java +++ b/core/src/mindustry/editor/MapEditorDialog.java @@ -29,6 +29,7 @@ import mindustry.ui.dialogs.*; import mindustry.world.*; import mindustry.world.blocks.environment.*; import mindustry.world.blocks.storage.*; +import mindustry.world.blocks.storage.CoreBlock.*; import mindustry.world.meta.*; import static mindustry.Vars.*; @@ -323,9 +324,8 @@ public class MapEditorDialog extends Dialog implements Disposable{ "width", editor.width(), "height", editor.height() )); + state.set(State.playing); world.endMapLoad(); - player.set(world.width() * tilesize/2f, world.height() * tilesize/2f); - Core.camera.position.set(player); player.clearUnit(); for(var unit : Groups.unit){ @@ -338,14 +338,17 @@ public class MapEditorDialog extends Dialog implements Disposable{ Groups.weather.clear(); logic.play(); - if(player.team().core() == null){ - player.set(world.width() * tilesize/2f, world.height() * tilesize/2f); - var unit = (state.rules.hasEnv(Env.scorching) ? UnitTypes.evoke : UnitTypes.alpha).spawn(player.team(), player.x, player.y); - unit.spawnedByCore = true; - player.unit(unit); - } + Point2 center = view.project(Core.graphics.getWidth()/2f, Core.graphics.getHeight()/2f); - player.checkSpawn(); + CoreBuild best = player.bestCore(); + + player.set(center.x * tilesize, center.y * tilesize); + var unit = (best != null ? ((CoreBlock)best.block).unitType : (state.rules.hasEnv(Env.scorching) ? UnitTypes.evoke : UnitTypes.alpha)).spawn(editor.drawTeam, player.x, player.y); + unit.spawnedByCore = true; + player.unit(unit); + player.set(unit); + + Core.camera.position.set(unit.x, unit.y); }); } diff --git a/core/src/mindustry/editor/MapRenderer.java b/core/src/mindustry/editor/MapRenderer.java index 9e3938fedc..a4b32967ab 100644 --- a/core/src/mindustry/editor/MapRenderer.java +++ b/core/src/mindustry/editor/MapRenderer.java @@ -15,6 +15,8 @@ import static mindustry.Vars.*; public class MapRenderer implements Disposable{ private static final int chunkSize = 60; + private static final Seq tmpTiles = new Seq<>(); + private EditorSpriteCache[][] chunks; private IntSet recacheChunks = new IntSet(); private int width, height; @@ -70,6 +72,7 @@ public class MapRenderer implements Disposable{ boolean prev = renderer.animateWater; renderer.animateWater = false; + Tmp.v3.set(Core.camera.position); Core.camera.position.set(world.width()/2f * tilesize, world.height()/2f * tilesize); Core.camera.width = 999999f; Core.camera.height = 999999f; @@ -114,12 +117,19 @@ public class MapRenderer implements Disposable{ mesh.render(shader); } } + + Core.camera.position.set(Tmp.v3); } void updateStatic(int x, int y){ renderer.blocks.floor.recacheTile(x, y); } + void updateBlock(Tile tile){ + updateBlock(tile.x, tile.y); + renderer.blocks.updateShadowTile(tile); + } + void updateBlock(int x, int y){ recacheChunks.add(Point2.pack(x / chunkSize, y / chunkSize)); } @@ -143,28 +153,51 @@ public class MapRenderer implements Disposable{ EditorSpriteCache cache = new EditorSpriteCache(renderer.blocks.floor.getVertexBuffer()); + TextureRegion teamRegion = Core.atlas.find("block-border"); + + tmpTiles.clear(); + for(int x = cx * chunkSize; x < (cx + 1) * chunkSize; x++){ for(int y = cy * chunkSize; y < (cy + 1) * chunkSize; y++){ Tile tile = world.tile(x, y); if(tile != null && tile.block() != Blocks.air && tile.block().cacheLayer == CacheLayer.normal && tile.isCenter()){ - Block block = tile.block(); - - TextureRegion region = block.fullIcon; - - float width = region.width * region.scl(), height = region.height * region.scl(); - - cache.draw(block.fullIcon, - x * tilesize + block.offset - width / 2f, - y * tilesize + block.offset - height / 2f, - width/2f, height/2f, - width, height, - tile.build == null || !block.rotate ? 0 : tile.build.rotdeg(), - Color.whiteFloatBits); + tmpTiles.add(tile); } } } + tmpTiles.sort(Structs.comparingBool(b -> !b.block().synthetic())); + + for(Tile tile : tmpTiles){ + int x = tile.x, y = tile.y; + Block block = tile.block(); + + TextureRegion region = block.fullIcon; + + float width = region.width * region.scl(), height = region.height * region.scl(); + + cache.draw(block.fullIcon, + x * tilesize + block.offset - width / 2f, + y * tilesize + block.offset - height / 2f, + width/2f, height/2f, + width, height, + tile.build == null || !block.rotate ? 0 : tile.build.rotdeg(), + Color.whiteFloatBits); + + if(tile.build != null){ + cache.draw(teamRegion, + x * tilesize + block.offset - width / 2f, + y * tilesize + block.offset - height / 2f, + 0f, 0f, + teamRegion.width * teamRegion.scl(), teamRegion.height * teamRegion.scl(), + 0f, + tile.build.team.color.toFloatBits()); + } + } + + tmpTiles.clear(); + if(!cache.isEmpty()){ cache.build(renderer.blocks.floor.getIndexData()); chunks[cx][cy] = cache; diff --git a/core/src/mindustry/editor/MapView.java b/core/src/mindustry/editor/MapView.java index e4f571bfb0..55c40faee4 100644 --- a/core/src/mindustry/editor/MapView.java +++ b/core/src/mindustry/editor/MapView.java @@ -204,7 +204,7 @@ public class MapView extends Element implements GestureListener{ zoom = Mathf.clamp(zoom, 0.2f, 20f); } - Point2 project(float x, float y){ + public Point2 project(float x, float y){ float ratio = 1f / ((float)editor.width() / editor.height()); float size = Math.min(width, height); float sclwidth = size * zoom;