Buttons for toggling buildings/terrain in editor
This commit is contained in:
@@ -451,10 +451,12 @@ publish.confirm = Are you sure you want to publish this?\n\n[lightgray]Make sure
|
|||||||
publish.error = Error publishing item: {0}
|
publish.error = Error publishing item: {0}
|
||||||
steam.error = Failed to initialize Steam services.\nError: {0}
|
steam.error = Failed to initialize Steam services.\nError: {0}
|
||||||
|
|
||||||
|
editor.showblocks = Show Blocks
|
||||||
|
editor.showterrain = Show Terrain
|
||||||
|
editor.showfloor = Show Floor
|
||||||
editor.planet = Planet:
|
editor.planet = Planet:
|
||||||
editor.sector = Sector:
|
editor.sector = Sector:
|
||||||
editor.seed = Seed:
|
editor.seed = Seed:
|
||||||
editor.cliffs = Walls To Cliffs
|
|
||||||
editor.brush = Brush
|
editor.brush = Brush
|
||||||
editor.openin = Open In Editor
|
editor.openin = Open In Editor
|
||||||
editor.oregen = Ore Generation
|
editor.oregen = Ore Generation
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class EditorRenderer implements Disposable{
|
|||||||
//don't process terrain updates every frame (helps with lag on low end devices)
|
//don't process terrain updates every frame (helps with lag on low end devices)
|
||||||
boolean doUpdate = Core.graphics.getFrameId() % 2 == 0;
|
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;
|
boolean prev = renderer.animateWater;
|
||||||
renderer.animateWater = false;
|
renderer.animateWater = false;
|
||||||
@@ -95,14 +95,16 @@ public class EditorRenderer implements Disposable{
|
|||||||
Core.camera.width = 999999f;
|
Core.camera.width = 999999f;
|
||||||
Core.camera.height = 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));
|
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());
|
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
|
//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);
|
Gl.disable(Gl.scissorTest);
|
||||||
|
|
||||||
if(doUpdate) renderer.blocks.processShadows();
|
if(doUpdate) renderer.blocks.processShadows(!editor.showBuildings, !editor.showTerrain);
|
||||||
|
|
||||||
Gl.enable(Gl.scissorTest);
|
Gl.enable(Gl.scissorTest);
|
||||||
|
|
||||||
@@ -115,7 +117,9 @@ public class EditorRenderer implements Disposable{
|
|||||||
Draw.proj(Tmp.m2);
|
Draw.proj(Tmp.m2);
|
||||||
|
|
||||||
renderer.blocks.floor.beginDraw();
|
renderer.blocks.floor.beginDraw();
|
||||||
renderer.blocks.floor.drawLayer(CacheLayer.walls);
|
if(editor.showTerrain){
|
||||||
|
renderer.blocks.floor.drawLayer(CacheLayer.walls);
|
||||||
|
}
|
||||||
renderer.animateWater = prev;
|
renderer.animateWater = prev;
|
||||||
|
|
||||||
if(chunks == null) return;
|
if(chunks == null) return;
|
||||||
@@ -125,16 +129,18 @@ public class EditorRenderer implements Disposable{
|
|||||||
recacheChunks.clear();
|
recacheChunks.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
shader.bind();
|
if(editor.showBuildings){
|
||||||
shader.setUniformMatrix4("u_projTrans", Tmp.m1.set(Core.camera.mat).translate(-packPad, -packPad).scale(packWidth, packHeight));
|
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 x = 0; x < chunks.length; x++){
|
||||||
for(int y = 0; y < chunks[0].length; y++){
|
for(int y = 0; y < chunks[0].length; y++){
|
||||||
EditorSpriteCache mesh = chunks[x][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(){
|
void recache(){
|
||||||
renderer.blocks.floor.clearTiles();
|
renderer.blocks.floor.reload(!editor.showTerrain);
|
||||||
renderer.blocks.reload();
|
renderer.blocks.reload();
|
||||||
|
|
||||||
for(int x = 0; x < chunks.length; x++){
|
for(int x = 0; x < chunks.length; x++){
|
||||||
@@ -167,6 +173,20 @@ public class EditorRenderer implements Disposable{
|
|||||||
recacheChunk(x, y);
|
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){
|
void recacheChunk(int cx, int cy){
|
||||||
|
|||||||
@@ -81,6 +81,10 @@ public class EditorTile extends Tile{
|
|||||||
}else{
|
}else{
|
||||||
renderer.blocks.updateShadowTile(this);
|
renderer.blocks.updateShadowTile(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(build != null){
|
||||||
|
build.wasVisible = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ public class MapEditor{
|
|||||||
public int rotation;
|
public int rotation;
|
||||||
public Block drawBlock = Blocks.stone;
|
public Block drawBlock = Blocks.stone;
|
||||||
public Team drawTeam = Team.sharded;
|
public Team drawTeam = Team.sharded;
|
||||||
|
public boolean showTerrain = true, showFloor = true, showBuildings = true;
|
||||||
|
|
||||||
public boolean isLoading(){
|
public boolean isLoading(){
|
||||||
return loading;
|
return loading;
|
||||||
|
|||||||
@@ -650,10 +650,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
|
|
||||||
tools.row();
|
tools.row();
|
||||||
|
|
||||||
tools.table(Tex.underline, t -> t.add("@editor.teams"))
|
tools.image(Tex.whiteui, Pal.gray).colspan(3).height(4f).width(size * 3f + 3f).row();
|
||||||
.colspan(3).height(40).width(size * 3f + 3f).padBottom(3);
|
|
||||||
|
|
||||||
tools.row();
|
|
||||||
|
|
||||||
ButtonGroup<ImageButton> teamgroup = new ButtonGroup<>();
|
ButtonGroup<ImageButton> teamgroup = new ButtonGroup<>();
|
||||||
|
|
||||||
@@ -695,10 +692,18 @@ public class MapEditorDialog extends Dialog implements Disposable{
|
|||||||
|
|
||||||
mid.row();
|
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){
|
if(!mobile){
|
||||||
mid.table(t -> {
|
mid.button("@editor.center", Icon.move, Styles.flatt, view::center).growX().margin(9f);
|
||||||
t.button("@editor.center", Icon.move, Styles.flatt, view::center).growX().margin(9f);
|
|
||||||
}).growX().top();
|
|
||||||
}
|
}
|
||||||
}).margin(0).left().growY();
|
}).margin(0).left().growY();
|
||||||
|
|
||||||
|
|||||||
@@ -154,6 +154,26 @@ public class BlockRenderer{
|
|||||||
updateDarkness();
|
updateDarkness();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateShadows(boolean ignoreBuildings, boolean ignoreTerrain){
|
||||||
|
shadows.getTexture().setFilter(TextureFilter.linear, TextureFilter.linear);
|
||||||
|
shadows.resize(world.width(), world.height());
|
||||||
|
shadows.begin();
|
||||||
|
Core.graphics.clear(Color.white);
|
||||||
|
Draw.proj().setOrtho(0, 0, shadows.getWidth(), shadows.getHeight());
|
||||||
|
|
||||||
|
Draw.color(blendShadowColor);
|
||||||
|
|
||||||
|
for(Tile tile : world.tiles){
|
||||||
|
if(tile.block().displayShadow(tile) && (tile.build == null || tile.build.wasVisible) && !(ignoreBuildings && !tile.block().isStatic()) && !(ignoreTerrain && tile.block().isStatic())){
|
||||||
|
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Draw.flush();
|
||||||
|
Draw.color();
|
||||||
|
shadows.end();
|
||||||
|
}
|
||||||
|
|
||||||
public void updateDarkness(){
|
public void updateDarkness(){
|
||||||
darkEvents.clear();
|
darkEvents.clear();
|
||||||
dark.getTexture().setFilter(TextureFilter.linear);
|
dark.getTexture().setFilter(TextureFilter.linear);
|
||||||
@@ -303,6 +323,10 @@ public class BlockRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processShadows(){
|
public void processShadows(){
|
||||||
|
processShadows(false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processShadows(boolean ignoreBuildings, boolean ignoreTerrain){
|
||||||
if(!shadowEvents.isEmpty()){
|
if(!shadowEvents.isEmpty()){
|
||||||
Draw.flush();
|
Draw.flush();
|
||||||
|
|
||||||
@@ -312,7 +336,7 @@ public class BlockRenderer{
|
|||||||
for(Tile tile : shadowEvents){
|
for(Tile tile : shadowEvents){
|
||||||
if(tile == null) continue;
|
if(tile == null) continue;
|
||||||
//draw white/shadow color depending on blend
|
//draw white/shadow color depending on blend
|
||||||
Draw.color((!tile.block().displayShadow(tile) || (state.rules.fog && tile.build != null && !tile.build.wasVisible)) ? Color.white : blendShadowColor);
|
Draw.color((!tile.block().displayShadow(tile) || (state.rules.fog && tile.build != null && !tile.build.wasVisible) || (ignoreBuildings && !tile.block().isStatic()) || (ignoreTerrain && tile.block().isStatic())) ? Color.white : blendShadowColor);
|
||||||
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
|
Fill.rect(tile.x + 0.5f, tile.y + 0.5f, 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ public class FloorRenderer{
|
|||||||
}
|
}
|
||||||
""");
|
""");
|
||||||
|
|
||||||
Events.on(WorldLoadEvent.class, event -> clearTiles());
|
Events.on(WorldLoadEvent.class, event -> reload());
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexData getIndexData(){
|
public IndexData getIndexData(){
|
||||||
@@ -162,7 +162,7 @@ public class FloorRenderer{
|
|||||||
if(!Structs.inBounds(x, y, cache)) continue;
|
if(!Structs.inBounds(x, y, cache)) continue;
|
||||||
|
|
||||||
if(cache[x][y].length == 0){
|
if(cache[x][y].length == 0){
|
||||||
cacheChunk(x, y);
|
cacheChunk(x, y, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunkMesh[] chunk = cache[x][y];
|
ChunkMesh[] chunk = cache[x][y];
|
||||||
@@ -193,12 +193,16 @@ public class FloorRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void checkChanges(){
|
public void checkChanges(){
|
||||||
|
checkChanges(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkChanges(boolean ignoreWalls){
|
||||||
if(recacheSet.size > 0){
|
if(recacheSet.size > 0){
|
||||||
//recache one chunk at a time
|
//recache one chunk at a time
|
||||||
IntSetIterator iterator = recacheSet.iterator();
|
IntSetIterator iterator = recacheSet.iterator();
|
||||||
while(iterator.hasNext){
|
while(iterator.hasNext){
|
||||||
int chunk = iterator.next();
|
int chunk = iterator.next();
|
||||||
cacheChunk(Point2.x(chunk), Point2.y(chunk));
|
cacheChunk(Point2.x(chunk), Point2.y(chunk), ignoreWalls);
|
||||||
}
|
}
|
||||||
|
|
||||||
recacheSet.clear();
|
recacheSet.clear();
|
||||||
@@ -278,13 +282,13 @@ public class FloorRenderer{
|
|||||||
layer.end();
|
layer.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cacheChunk(int cx, int cy){
|
private void cacheChunk(int cx, int cy, boolean ignoreWalls){
|
||||||
used.clear();
|
used.clear();
|
||||||
|
|
||||||
for(int tilex = Math.max(cx * chunksize - 1, 0); tilex < (cx + 1) * chunksize + 1 && tilex < world.width(); tilex++){
|
for(int tilex = Math.max(cx * chunksize - 1, 0); tilex < (cx + 1) * chunksize + 1 && tilex < world.width(); tilex++){
|
||||||
for(int tiley = Math.max(cy * chunksize - 1, 0); tiley < (cy + 1) * chunksize + 1 && tiley < world.height(); tiley++){
|
for(int tiley = Math.max(cy * chunksize - 1, 0); tiley < (cy + 1) * chunksize + 1 && tiley < world.height(); tiley++){
|
||||||
Tile tile = world.rawTile(tilex, tiley);
|
Tile tile = world.rawTile(tilex, tiley);
|
||||||
boolean wall = tile.block().cacheLayer != CacheLayer.normal;
|
boolean wall = !ignoreWalls && tile.block().cacheLayer != CacheLayer.normal;
|
||||||
|
|
||||||
if(wall){
|
if(wall){
|
||||||
used.add(tile.block().cacheLayer);
|
used.add(tile.block().cacheLayer);
|
||||||
@@ -310,11 +314,11 @@ public class FloorRenderer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(CacheLayer layer : used){
|
for(CacheLayer layer : used){
|
||||||
meshes[layer.id] = cacheChunkLayer(cx, cy, layer);
|
meshes[layer.id] = cacheChunkLayer(cx, cy, layer, ignoreWalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ChunkMesh cacheChunkLayer(int cx, int cy, CacheLayer layer){
|
private ChunkMesh cacheChunkLayer(int cx, int cy, CacheLayer layer, boolean ignoreWalls){
|
||||||
vidx = 0;
|
vidx = 0;
|
||||||
|
|
||||||
Batch current = Core.batch;
|
Batch current = Core.batch;
|
||||||
@@ -333,7 +337,7 @@ public class FloorRenderer{
|
|||||||
|
|
||||||
if(tile.block().cacheLayer == layer && layer == CacheLayer.walls && !(tile.isDarkened() && tile.data >= 5)){
|
if(tile.block().cacheLayer == layer && layer == CacheLayer.walls && !(tile.isDarkened() && tile.data >= 5)){
|
||||||
tile.block().drawBase(tile);
|
tile.block().drawBase(tile);
|
||||||
}else if(floor.cacheLayer == layer && (world.isAccessible(tile.x, tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
|
}else if(floor.cacheLayer == layer && (ignoreWalls || world.isAccessible(tile.x, tile.y) || tile.block().cacheLayer != CacheLayer.walls || !tile.block().fillsTile)){
|
||||||
floor.drawBase(tile);
|
floor.drawBase(tile);
|
||||||
}else if(floor.cacheLayer != layer && layer != CacheLayer.walls){
|
}else if(floor.cacheLayer != layer && layer != CacheLayer.walls){
|
||||||
floor.drawNonLayer(tile, layer);
|
floor.drawNonLayer(tile, layer);
|
||||||
@@ -355,7 +359,11 @@ public class FloorRenderer{
|
|||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearTiles(){
|
public void reload(){
|
||||||
|
reload(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reload(boolean ignoreWalls){
|
||||||
//dispose all old meshes
|
//dispose all old meshes
|
||||||
if(cache != null){
|
if(cache != null){
|
||||||
for(var x : cache){
|
for(var x : cache){
|
||||||
@@ -385,7 +393,7 @@ public class FloorRenderer{
|
|||||||
|
|
||||||
for(int x = 0; x < chunksx; x++){
|
for(int x = 0; x < chunksx; x++){
|
||||||
for(int y = 0; y < chunksy; y++){
|
for(int y = 0; y < chunksy; y++){
|
||||||
cacheChunk(x, y);
|
cacheChunk(x, y, ignoreWalls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user