Buttons for toggling buildings/terrain in editor

This commit is contained in:
Anuken
2025-09-19 18:26:06 -04:00
parent 6ab5776064
commit 71fbfffaec
7 changed files with 95 additions and 31 deletions

View File

@@ -85,7 +85,7 @@ public class EditorRenderer implements Disposable{
//don't process terrain updates every frame (helps with lag on low end devices)
boolean doUpdate = Core.graphics.getFrameId() % 2 == 0;
if(doUpdate) renderer.blocks.floor.checkChanges();
if(doUpdate) renderer.blocks.floor.checkChanges(!editor.showTerrain);
boolean prev = renderer.animateWater;
renderer.animateWater = false;
@@ -95,14 +95,16 @@ public class EditorRenderer implements Disposable{
Core.camera.width = 999999f;
Core.camera.height = 999999f;
Core.camera.mat.set(Draw.proj()).mul(Tmp.m3.setToTranslation(tx, ty).scale(tw / (width * tilesize), th / (height * tilesize)).translate(4f, 4f));
renderer.blocks.floor.drawFloor();
if(editor.showFloor){
renderer.blocks.floor.drawFloor();
}
Tmp.m2.set(Draw.proj());
//scissors are always enabled because this is drawn clipped in UI, make sure they don't interfere with drawing shadow events
Gl.disable(Gl.scissorTest);
if(doUpdate) renderer.blocks.processShadows();
if(doUpdate) renderer.blocks.processShadows(!editor.showBuildings, !editor.showTerrain);
Gl.enable(Gl.scissorTest);
@@ -115,7 +117,9 @@ public class EditorRenderer implements Disposable{
Draw.proj(Tmp.m2);
renderer.blocks.floor.beginDraw();
renderer.blocks.floor.drawLayer(CacheLayer.walls);
if(editor.showTerrain){
renderer.blocks.floor.drawLayer(CacheLayer.walls);
}
renderer.animateWater = prev;
if(chunks == null) return;
@@ -125,16 +129,18 @@ public class EditorRenderer implements Disposable{
recacheChunks.clear();
}
shader.bind();
shader.setUniformMatrix4("u_projTrans", Tmp.m1.set(Core.camera.mat).translate(-packPad, -packPad).scale(packWidth, packHeight));
if(editor.showBuildings){
shader.bind();
shader.setUniformMatrix4("u_projTrans", Tmp.m1.set(Core.camera.mat).translate(-packPad, -packPad).scale(packWidth, packHeight));
for(int x = 0; x < chunks.length; x++){
for(int y = 0; y < chunks[0].length; y++){
EditorSpriteCache mesh = chunks[x][y];
for(int x = 0; x < chunks.length; x++){
for(int y = 0; y < chunks[0].length; y++){
EditorSpriteCache mesh = chunks[x][y];
if(mesh == null) continue;
if(mesh == null) continue;
mesh.render(shader);
mesh.render(shader);
}
}
}
@@ -159,7 +165,7 @@ public class EditorRenderer implements Disposable{
}
void recache(){
renderer.blocks.floor.clearTiles();
renderer.blocks.floor.reload(!editor.showTerrain);
renderer.blocks.reload();
for(int x = 0; x < chunks.length; x++){
@@ -167,6 +173,20 @@ public class EditorRenderer implements Disposable{
recacheChunk(x, y);
}
}
//this causes 2 recaches, but it's necessary to fix the wrong shadows after a reload
if(!editor.showBuildings || !editor.showTerrain){
recacheShadows();
}
}
void recacheTerrain(){
renderer.blocks.floor.reload(!editor.showTerrain);
renderer.blocks.reload();
recacheShadows();
}
void recacheShadows(){
renderer.blocks.updateShadows(!editor.showBuildings, !editor.showTerrain);
}
void recacheChunk(int cx, int cy){

View File

@@ -81,6 +81,10 @@ public class EditorTile extends Tile{
}else{
renderer.blocks.updateShadowTile(this);
}
if(build != null){
build.wasVisible = true;
}
}
@Override

View File

@@ -32,6 +32,7 @@ public class MapEditor{
public int rotation;
public Block drawBlock = Blocks.stone;
public Team drawTeam = Team.sharded;
public boolean showTerrain = true, showFloor = true, showBuildings = true;
public boolean isLoading(){
return loading;

View File

@@ -650,10 +650,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
tools.row();
tools.table(Tex.underline, t -> t.add("@editor.teams"))
.colspan(3).height(40).width(size * 3f + 3f).padBottom(3);
tools.row();
tools.image(Tex.whiteui, Pal.gray).colspan(3).height(4f).width(size * 3f + 3f).row();
ButtonGroup<ImageButton> teamgroup = new ButtonGroup<>();
@@ -695,10 +692,18 @@ public class MapEditorDialog extends Dialog implements Disposable{
mid.row();
mid.check("@editor.showblocks", editor.showBuildings, b -> {
editor.showBuildings = b;
editor.renderer.recacheShadows();
}).pad(2f).growX().with(Table::left).row();
mid.check("@editor.showterrain", editor.showTerrain, b -> {
editor.showTerrain = b;
editor.renderer.recacheTerrain();
}).pad(2f).growX().with(Table::left).row();
mid.check("@editor.showfloor", editor.showFloor, b -> editor.showFloor = b).pad(2f).growX().with(Table::left).row();
if(!mobile){
mid.table(t -> {
t.button("@editor.center", Icon.move, Styles.flatt, view::center).growX().margin(9f);
}).growX().top();
mid.button("@editor.center", Icon.move, Styles.flatt, view::center).growX().margin(9f);
}
}).margin(0).left().growY();