From c15aec641a0a0c87e91bdecbba955bf8ce7326f7 Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 8 Jul 2020 12:40:17 -0400 Subject: [PATCH] Environmental lights / Bugfixes --- core/src/mindustry/content/Blocks.java | 8 ++++++ core/src/mindustry/content/UnitTypes.java | 2 +- .../src/mindustry/graphics/BlockRenderer.java | 27 ++++++++++++++----- core/src/mindustry/graphics/Drawf.java | 4 +++ .../src/mindustry/graphics/LightRenderer.java | 2 +- core/src/mindustry/ui/Styles.java | 3 +++ core/src/mindustry/world/Block.java | 12 +++++++++ 7 files changed, 49 insertions(+), 9 deletions(-) diff --git a/core/src/mindustry/content/Blocks.java b/core/src/mindustry/content/Blocks.java index cd2d11b337..370cdc0986 100644 --- a/core/src/mindustry/content/Blocks.java +++ b/core/src/mindustry/content/Blocks.java @@ -228,6 +228,10 @@ public class Blocks implements ContentList{ attributes.set(Attribute.heat, 0.5f); attributes.set(Attribute.water, -0.2f); blendGroup = ignarock; + + emitLight = true; + lightRadius = 30f; + lightColor = Color.orange.cpy().a(0.15f); }}; magmarock = new Floor("magmarock"){{ @@ -235,6 +239,10 @@ public class Blocks implements ContentList{ attributes.set(Attribute.water, -0.5f); updateEffect = Fx.magmasmoke; blendGroup = ignarock; + + emitLight = true; + lightRadius = 60f; + lightColor = Color.orange.cpy().a(0.3f); }}; sand = new Floor("sand"){{ diff --git a/core/src/mindustry/content/UnitTypes.java b/core/src/mindustry/content/UnitTypes.java index 7a0406b157..4c2fef44c5 100644 --- a/core/src/mindustry/content/UnitTypes.java +++ b/core/src/mindustry/content/UnitTypes.java @@ -534,7 +534,7 @@ public class UnitTypes implements ContentList{ isCounted = false; flying = true; - mineSpeed = 12f; + mineSpeed = 10f; mineTier = 1; buildSpeed = 0.5f; drag = 0.05f; diff --git a/core/src/mindustry/graphics/BlockRenderer.java b/core/src/mindustry/graphics/BlockRenderer.java index 5d00e88900..dd66dd86e9 100644 --- a/core/src/mindustry/graphics/BlockRenderer.java +++ b/core/src/mindustry/graphics/BlockRenderer.java @@ -201,7 +201,7 @@ public class BlockRenderer implements Disposable{ } //lights are drawn even in the expanded range - if(tile.build != null){ + if(tile.build != null || tile.block().emitLight){ lightview.add(tile); } @@ -213,6 +213,11 @@ public class BlockRenderer implements Disposable{ } } } + + //special case for floors + if(block == Blocks.air && tile.floor().emitLight){ + lightview.add(tile); + } } } @@ -257,15 +262,23 @@ public class BlockRenderer implements Disposable{ } } - //draw lights - for(int i = 0; i < lightview.size; i++){ - Tile tile = lightview.items[i]; - Building entity = tile.build; + if(renderer.lights.enabled()){ + //draw lights + for(int i = 0; i < lightview.size; i++){ + Tile tile = lightview.items[i]; + Building entity = tile.build; - if(entity != null){ - entity.drawLight(); + if(entity != null){ + entity.drawLight(); + }else if(tile.block().emitLight){ + tile.block().drawEnvironmentLight(tile); + }else if(tile.floor().emitLight){ + tile.floor().drawEnvironmentLight(tile); + } } } + + } @Override diff --git a/core/src/mindustry/graphics/Drawf.java b/core/src/mindustry/graphics/Drawf.java index d5ee5eb397..05de2877d8 100644 --- a/core/src/mindustry/graphics/Drawf.java +++ b/core/src/mindustry/graphics/Drawf.java @@ -26,6 +26,10 @@ public class Drawf{ return z; } + public static void light(float x, float y, float radius, Color color, float opacity){ + renderer.lights.add(x, y, radius, color, opacity); + } + public static void light(Team team, float x, float y, float radius, Color color, float opacity){ if(allowLight(team)) renderer.lights.add(x, y, radius, color, opacity); } diff --git a/core/src/mindustry/graphics/LightRenderer.java b/core/src/mindustry/graphics/LightRenderer.java index b8c93823b4..63cd3f2783 100644 --- a/core/src/mindustry/graphics/LightRenderer.java +++ b/core/src/mindustry/graphics/LightRenderer.java @@ -171,7 +171,7 @@ public class LightRenderer{ } public boolean enabled(){ - return state.rules.lighting; + return state.rules.lighting && state.rules.ambientLight.a > 0.00001f; } public void draw(){ diff --git a/core/src/mindustry/ui/Styles.java b/core/src/mindustry/ui/Styles.java index 52bb6d29d0..39a19bd8d8 100644 --- a/core/src/mindustry/ui/Styles.java +++ b/core/src/mindustry/ui/Styles.java @@ -194,6 +194,9 @@ public class Styles{ down = flatDown; up = none; over = flatOver; + disabled = black8; + imageDisabledColor = Color.lightGray; + imageUpColor = Color.white; }}; clearPartial2i = new ImageButtonStyle(){{ down = whiteui; diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 865d8dfc85..6628c74dea 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -146,6 +146,14 @@ public class Block extends UnlockableContent{ public Sound breakSound = Sounds.boom; /** How reflective this block is. */ public float albedo = 0f; + /** Environmental passive light color. */ + public Color lightColor = Color.white.cpy(); + /** + * Whether this environmental block passively emits light. + * Not valid for non-environmental blocks. */ + public boolean emitLight = false; + /** Radius of the light emitted by this block. */ + public float lightRadius = 60f; /** The sound that this block makes while active. One sound loop. Do not overuse.*/ public Sound activeSound = Sounds.none; @@ -212,6 +220,10 @@ public class Block extends UnlockableContent{ .sumf(other -> !other.floor().isLiquid ? 1f : 0f) / size / size; } + public void drawEnvironmentLight(Tile tile){ + Drawf.light(tile.worldx(), tile.worldy(), lightRadius, lightColor, lightColor.a); + } + /** Drawn when you are placing a block. */ public void drawPlace(int x, int y, int rotation, boolean valid){ }