diff --git a/core/assets-raw/sprites/blocks/environment/colored-wall-autotile.png b/core/assets-raw/sprites/blocks/environment/colored-wall-autotile.png new file mode 100644 index 0000000000..8af8c96283 Binary files /dev/null and b/core/assets-raw/sprites/blocks/environment/colored-wall-autotile.png differ diff --git a/core/assets/icons/icons.properties b/core/assets/icons/icons.properties index 0904a6a2a9..4d5a8d6afb 100755 --- a/core/assets/icons/icons.properties +++ b/core/assets/icons/icons.properties @@ -611,3 +611,4 @@ 63071=crux-floor-8|block-crux-floor-8-ui 63070=crux-floor-9|block-crux-floor-9-ui 63069=crux-floor-10|block-crux-floor-10-ui +63068=colored-wall|block-colored-wall-ui diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index a327d60fd7..12390fe663 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -58,8 +58,14 @@ public class Blocks{ //boulders shaleBoulder, sandBoulder, daciteBoulder, boulder, snowBoulder, basaltBoulder, carbonBoulder, ferricBoulder, beryllicBoulder, yellowStoneBoulder, arkyicBoulder, crystalCluster, vibrantCrystalCluster, crystalBlocks, crystalOrbs, crystallineBoulder, redIceBoulder, rhyoliteBoulder, redStoneBoulder, + metalFloor, metalFloorDamaged, metalFloor2, metalFloor3, metalFloor4, metalFloor5, basalt, magmarock, hotrock, snowWall, saltWall, - darkPanel1, darkPanel2, darkPanel3, darkPanel4, darkPanel5, darkPanel6, darkMetal, cruxFloor1, cruxFloor2, cruxFloor3, cruxFloor4, cruxFloor5, cruxFloor6, cruxFloor7, cruxFloor8, cruxFloor9, cruxFloor10, coloredFloor, + //new metal floors + darkPanel1, darkPanel2, darkPanel3, darkPanel4, darkPanel5, darkPanel6, darkMetal, cruxFloor1, cruxFloor2, cruxFloor3, cruxFloor4, cruxFloor5, cruxFloor6, cruxFloor7, cruxFloor8, cruxFloor9, cruxFloor10, + + //colored + coloredFloor, coloredWall, + pebbles, tendrils, //ores @@ -883,6 +889,14 @@ public class Blocks{ inEditor = false; }}; + coloredWall = new ColoredWall("colored-wall"){{ + autotile = true; + //there is no proper support for displaying colors or placing with colors + inEditor = false; + //TODO: should this apply darkness? + //fillsTile = false; + }}; + Seq.with(metalFloor, metalFloorDamaged, metalFloor2, metalFloor3, metalFloor4, metalFloor5, darkPanel1, darkPanel2, darkPanel3, darkPanel4, darkPanel5, darkPanel6) .each(b -> b.asFloor().wall = darkMetal); diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index c4989411b4..3884ad8041 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -566,6 +566,11 @@ public class Block extends UnlockableContent implements Senseable{ return forceDark; } + /** If true, the 'map edge' darkness will be applied to this block. */ + public boolean isDarkened(Tile tile){ + return solid && ((!synthetic() && fillsTile) || checkForceDark(tile)); + } + @Override public void setStats(){ super.setStats(); @@ -940,6 +945,9 @@ public class Block extends UnlockableContent implements Senseable{ return (envEnabled & env) != 0 && (envDisabled & env) == 0 && (envRequired == 0 || (envRequired & env) == envRequired); } + /** Called when this block is set on the specified tile. */ + public void blockChanged(Tile tile){} + /** Called when building of this block begins. */ public void placeBegan(Tile tile, Block previous){ @@ -951,7 +959,7 @@ public class Block extends UnlockableContent implements Senseable{ } /** Called when building of this block ends. */ - public void placeEnded(Tile tile, @Nullable Unit builder){ + public void placeEnded(Tile tile, @Nullable Unit builder, @Nullable Object config){ } diff --git a/core/src/mindustry/world/Tile.java b/core/src/mindustry/world/Tile.java index b4bd9d3a97..0a14cc438e 100644 --- a/core/src/mindustry/world/Tile.java +++ b/core/src/mindustry/world/Tile.java @@ -172,7 +172,7 @@ public class Tile implements Position, QuadTreeObject, Displayable{ } public boolean isDarkened(){ - return block.solid && ((!block.synthetic() && block.fillsTile) || block.checkForceDark(this)); + return block.isDarkened(this); } public Floor floor(){ @@ -280,6 +280,8 @@ public class Tile implements Position, QuadTreeObject, Displayable{ changed(); changing = false; + + block.blockChanged(this); } public void setBlock(Block type, Team team){ diff --git a/core/src/mindustry/world/blocks/ConstructBlock.java b/core/src/mindustry/world/blocks/ConstructBlock.java index 77f6288ab1..9a10dcbe3d 100644 --- a/core/src/mindustry/world/blocks/ConstructBlock.java +++ b/core/src/mindustry/world/blocks/ConstructBlock.java @@ -77,10 +77,8 @@ public class ConstructBlock extends Block{ if(block instanceof OverlayFloor overlay){ tile.setOverlay(overlay); - overlay.placed(tile, config); }else if(block instanceof Floor floor){ tile.setFloor(floor); - floor.placed(tile, config); }else{ tile.setBlock(block, team, rotation); } @@ -114,7 +112,7 @@ public class ConstructBlock extends Block{ if(shouldPlay()) block.placeSound.at(tile, block.placePitchChange ? calcPitch(true) : 1f); } - block.placeEnded(tile, builder); + block.placeEnded(tile, builder, config); Events.fire(new BlockBuildEndEvent(tile, builder, team, false, config)); } diff --git a/core/src/mindustry/world/blocks/environment/ColoredFloor.java b/core/src/mindustry/world/blocks/environment/ColoredFloor.java index 2a6b2b6a2d..7940de4f41 100644 --- a/core/src/mindustry/world/blocks/environment/ColoredFloor.java +++ b/core/src/mindustry/world/blocks/environment/ColoredFloor.java @@ -6,6 +6,7 @@ import arc.math.geom.*; import arc.util.*; import mindustry.*; import mindustry.entities.units.*; +import mindustry.gen.*; import mindustry.world.*; import mindustry.world.blocks.*; @@ -135,7 +136,7 @@ public class ColoredFloor extends Floor{ } @Override - public void placed(Tile tile, @Nullable Object config){ + public void placeEnded(Tile tile, @Nullable Unit builder, @Nullable Object config){ //config is assumed to be an integer RGBA color if(config instanceof Integer i){ tile.extraData = i; diff --git a/core/src/mindustry/world/blocks/environment/ColoredWall.java b/core/src/mindustry/world/blocks/environment/ColoredWall.java new file mode 100644 index 0000000000..68f568544f --- /dev/null +++ b/core/src/mindustry/world/blocks/environment/ColoredWall.java @@ -0,0 +1,74 @@ +package mindustry.world.blocks.environment; + +import arc.graphics.*; +import arc.graphics.g2d.*; +import arc.util.*; +import mindustry.entities.units.*; +import mindustry.gen.*; +import mindustry.world.*; + +public class ColoredWall extends StaticWall{ + /** If the alpha value of the color is set to this value, different colors are ignored and no border is drawn. */ + public static final int flagIgnoreDifferentColor = 1; + /** If the alpha value of the color is set to this value, the wall will have darkness applied, as other walls do. */ + public static final int flagApplyDarkness = 2; + + public Color defaultColor = Color.white; + protected int defaultColorRgba; + + public ColoredWall(String name){ + super(name); + saveData = true; + } + + @Override + public void init(){ + super.init(); + defaultColorRgba = defaultColor.rgba(); + } + + @Override + public void drawBase(Tile tile){ + //make sure to mask out the alpha channel - it's generally undesirable, and leads to invisible blocks when the data is not initialized + Draw.color(tile.extraData | 0xff); + super.drawBase(tile); + Draw.color(); + } + + @Override + public void blockChanged(Tile tile){ + //reset to white + tile.extraData = defaultColorRgba; + } + + @Override + public void placeEnded(Tile tile, @Nullable Unit builder, @Nullable Object config){ + //config is assumed to be an integer RGBA color + if(config instanceof Integer i){ + tile.extraData = i; + } + } + + @Override + public void drawPlanRegion(BuildPlan plan, Eachable list){ + if(plan.config instanceof Integer i){ + Draw.tint(Tmp.c1.set(i | 0xff)); + } + drawDefaultPlanRegion(plan, list); + } + + @Override + public boolean checkAutotileSame(Tile tile, @Nullable Tile other){ + return other != null && other.block() == this && ((tile.extraData & flagIgnoreDifferentColor) != 0 || tile.extraData == other.extraData); + } + + @Override + public boolean isDarkened(Tile tile){ + return (tile.extraData & flagApplyDarkness) != 0; + } + + @Override + public int minimapColor(Tile tile){ + return tile.extraData | 0xff; + } +} diff --git a/core/src/mindustry/world/blocks/environment/Floor.java b/core/src/mindustry/world/blocks/environment/Floor.java index 4bae99e420..d72565bc53 100644 --- a/core/src/mindustry/world/blocks/environment/Floor.java +++ b/core/src/mindustry/world/blocks/environment/Floor.java @@ -290,9 +290,6 @@ public class Floor extends Block{ /** Called when this floor is set on the specified tile. */ public void floorChanged(Tile tile){} - /** Called when this floor or overlay is placed on a tile. The config may be null. */ - public void placed(Tile tile, @Nullable Object config){} - /** @return whether to index this floor by flag */ public boolean shouldIndex(Tile tile){ return true; diff --git a/core/src/mindustry/world/blocks/environment/RemoveOre.java b/core/src/mindustry/world/blocks/environment/RemoveOre.java index b50d019c4f..88904f8aaa 100644 --- a/core/src/mindustry/world/blocks/environment/RemoveOre.java +++ b/core/src/mindustry/world/blocks/environment/RemoveOre.java @@ -44,7 +44,7 @@ public class RemoveOre extends OverlayFloor{ } @Override - public void placeEnded(Tile tile, @Nullable Unit builder){ + public void placeEnded(Tile tile, @Nullable Unit builder, Object config){ tile.setOverlay(Blocks.air); } diff --git a/core/src/mindustry/world/blocks/environment/RemoveWall.java b/core/src/mindustry/world/blocks/environment/RemoveWall.java index 0359ee7052..69bd0bcb34 100644 --- a/core/src/mindustry/world/blocks/environment/RemoveWall.java +++ b/core/src/mindustry/world/blocks/environment/RemoveWall.java @@ -43,7 +43,7 @@ public class RemoveWall extends Block{ } @Override - public void placeEnded(Tile tile, @Nullable Unit builder){ + public void placeEnded(Tile tile, @Nullable Unit builder, Object config){ tile.setBlock(Blocks.air); if(tile.overlay().wallOre){ tile.setOverlay(Blocks.air); diff --git a/core/src/mindustry/world/blocks/environment/StaticWall.java b/core/src/mindustry/world/blocks/environment/StaticWall.java index a287b2a419..fd48bf0c58 100644 --- a/core/src/mindustry/world/blocks/environment/StaticWall.java +++ b/core/src/mindustry/world/blocks/environment/StaticWall.java @@ -4,6 +4,7 @@ import arc.*; import arc.graphics.g2d.*; import arc.math.*; import arc.math.geom.*; +import arc.util.*; import mindustry.annotations.Annotations.*; import mindustry.content.*; import mindustry.graphics.*; @@ -40,7 +41,7 @@ public class StaticWall extends Prop{ for(int i = 0; i < 8; i++){ Tile other = tile.nearby(Geometry.d8[i]); - if(other != null && other.block() == this){ + if(checkAutotileSame(tile, other)){ bits |= (1 << i); } } @@ -65,6 +66,10 @@ public class StaticWall extends Prop{ } } + public boolean checkAutotileSame(Tile tile, @Nullable Tile other){ + return other != null && other.block() == this; + } + @Override public void load(){ super.load();