From 8d9d6385f93158d5b2f3094a27229f5732a21498 Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 10 Jun 2021 15:52:33 -0400 Subject: [PATCH] Editor variant regions for wall blocks --- core/src/mindustry/editor/MapRenderer.java | 13 ++++++++++--- core/src/mindustry/world/Block.java | 7 +++++++ core/src/mindustry/world/blocks/defense/Wall.java | 6 +----- .../mindustry/world/blocks/environment/Floor.java | 10 +--------- tools/src/mindustry/tools/Generators.java | 2 +- 5 files changed, 20 insertions(+), 18 deletions(-) diff --git a/core/src/mindustry/editor/MapRenderer.java b/core/src/mindustry/editor/MapRenderer.java index abbd4baa1a..e5a0ce1c01 100644 --- a/core/src/mindustry/editor/MapRenderer.java +++ b/core/src/mindustry/editor/MapRenderer.java @@ -18,6 +18,7 @@ public class MapRenderer implements Disposable{ private IndexedRenderer[][] chunks; private IntSet updates = new IntSet(); private IntSet delayedUpdates = new IntSet(); + private TextureRegion clearEditor; private int width, height; public void resize(int width, int height){ @@ -45,6 +46,7 @@ public class MapRenderer implements Disposable{ public void draw(float tx, float ty, float tw, float th){ Draw.flush(); + clearEditor = Core.atlas.find("clear-editor"); updates.each(i -> render(i % width, i / width)); updates.clear(); @@ -80,6 +82,7 @@ public class MapRenderer implements Disposable{ } public void updateAll(){ + clearEditor = Core.atlas.find("clear-editor"); for(int x = 0; x < width; x++){ for(int y = 0; y < height; y++){ render(x, y); @@ -103,7 +106,7 @@ public class MapRenderer implements Disposable{ boolean center = tile.isCenter(); if(wall != Blocks.air && wall.synthetic()){ - region = !Core.atlas.isFound(wall.editorIcon()) || !center ? Core.atlas.find("clear-editor") : wall.editorIcon(); + region = !wall.editorIcon().found() || !center ? clearEditor : wall.editorIcon(); float width = region.width * Draw.scl, height = region.height * Draw.scl; @@ -124,13 +127,17 @@ public class MapRenderer implements Disposable{ mesh.setColor(team.color); region = Core.atlas.find("block-border-editor"); }else if(!wall.synthetic() && wall != Blocks.air && center){ - region = !Core.atlas.isFound(wall.editorIcon()) ? Core.atlas.find("clear-editor") : wall.editorIcon(); + region = !wall.editorIcon().found() ? + clearEditor : wall.variants > 0 ? + wall.editorVariantRegions()[Mathf.randomSeed(idxWall, 0, wall.editorVariantRegions().length - 1)] : + wall.editorIcon(); + offsetX = tilesize / 2f - region.width / 2f * Draw.scl; offsetY = tilesize / 2f - region.height / 2f * Draw.scl; }else if(wall == Blocks.air && !tile.overlay().isAir()){ region = tile.overlay().editorVariantRegions()[Mathf.randomSeed(idxWall, 0, tile.overlay().editorVariantRegions().length - 1)]; }else{ - region = Core.atlas.find("clear-editor"); + region = clearEditor; } float width = region.width * Draw.scl, height = region.height * Draw.scl; diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index b854d6bbab..11eb6b3bef 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -863,6 +863,13 @@ public class Block extends UnlockableContent{ mapColor.set(image.get(image.width/2, image.height/2)); } + if(variants > 0){ + for(int i = 0; i < variants; i++){ + String rname = name + (i + 1); + packer.add(PageType.editor, "editor-" + rname, Core.atlas.getPixmap(rname)); + } + } + Pixmap last = null; var gen = icons(); diff --git a/core/src/mindustry/world/blocks/defense/Wall.java b/core/src/mindustry/world/blocks/defense/Wall.java index 10c5a7e5a9..d8d1c620b4 100644 --- a/core/src/mindustry/world/blocks/defense/Wall.java +++ b/core/src/mindustry/world/blocks/defense/Wall.java @@ -59,11 +59,7 @@ public class Wall extends Block{ @Override public void draw(){ - if(variants == 0){ - Draw.rect(region, x, y); - }else{ - Draw.rect(variantRegions[Mathf.randomSeed(tile.pos(), 0, Math.max(0, variantRegions.length - 1))], x, y); - } + super.draw(); //draw flashing white overlay if enabled if(flashHit){ diff --git a/core/src/mindustry/world/blocks/environment/Floor.java b/core/src/mindustry/world/blocks/environment/Floor.java index 8dcc228d4e..762a5e4f9d 100644 --- a/core/src/mindustry/world/blocks/environment/Floor.java +++ b/core/src/mindustry/world/blocks/environment/Floor.java @@ -74,7 +74,6 @@ public class Floor extends Block{ public Floor(String name){ super(name); - variants = 3; } @@ -133,19 +132,12 @@ public class Floor extends Block{ @Override public void createIcons(MultiPacker packer){ super.createIcons(packer); - packer.add(PageType.editor, "editor-" + name, Core.atlas.getPixmap(fullIcon).crop()); + packer.add(PageType.editor, "editor-" + name, Core.atlas.getPixmap(fullIcon)); if(blendGroup != this){ return; } - if(variants > 0){ - for(int i = 0; i < variants; i++){ - String rname = name + (i + 1); - packer.add(PageType.editor, "editor-" + rname, Core.atlas.getPixmap(rname).crop()); - } - } - PixmapRegion image = Core.atlas.getPixmap(icons()[0]); PixmapRegion edge = Core.atlas.getPixmap("edge-stencil"); Pixmap result = new Pixmap(edge.width, edge.height); diff --git a/tools/src/mindustry/tools/Generators.java b/tools/src/mindustry/tools/Generators.java index 6f7ba3f5c5..626986b5ce 100644 --- a/tools/src/mindustry/tools/Generators.java +++ b/tools/src/mindustry/tools/Generators.java @@ -220,7 +220,7 @@ public class Generators{ TextureRegion[] regions = block.getGeneratedIcons(); - if(block instanceof Floor){ + if(block.variants > 0){ for(TextureRegion region : block.variantRegions()){ GenRegion gen = (GenRegion)region; if(gen.path == null) continue;