From 831da36bcc2210420591a3521c5cae95be7396e1 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 3 Dec 2021 18:04:03 +0100 Subject: [PATCH] allow drawing the background of extended auto tiles in a separate color --- Demos/AutoTilingDemo.cs | 2 +- MLEM/Graphics/AutoTiling.cs | 27 ++++++++++++++------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Demos/AutoTilingDemo.cs b/Demos/AutoTilingDemo.cs index 6ab657b..59d8a71 100644 --- a/Demos/AutoTilingDemo.cs +++ b/Demos/AutoTilingDemo.cs @@ -61,7 +61,7 @@ namespace Demos { AutoTiling.DrawAutoTile(this.SpriteBatch, new Vector2(x + 1, y + 1) * TileSize, this.texture, new Rectangle(0, 0, TileSize, TileSize), ConnectsTo, Color.White); // when drawing extended auto-tiles, the same rules apply, but the source texture layout is different - AutoTiling.DrawExtendedAutoTile(this.SpriteBatch, new Vector2(x + 8, y + 1) * TileSize, this.texture, new Rectangle(0, TileSize * 2, TileSize, TileSize), ConnectsTo, Color.White); + AutoTiling.DrawExtendedAutoTile(this.SpriteBatch, new Vector2(x + 8, y + 1) * TileSize, this.texture, new Rectangle(0, TileSize * 2, TileSize, TileSize), ConnectsTo, Color.White, Color.White); } } this.SpriteBatch.End(); diff --git a/MLEM/Graphics/AutoTiling.cs b/MLEM/Graphics/AutoTiling.cs index 16928ff..eb1411c 100644 --- a/MLEM/Graphics/AutoTiling.cs +++ b/MLEM/Graphics/AutoTiling.cs @@ -72,39 +72,40 @@ namespace MLEM.Graphics { /// The texture to use for drawing. /// The location of the first texture region, as described in the summary. /// A function that determines whether two positions should connect. - /// The color to draw with. + /// The color to draw the texture used for filling big areas with. + /// The color to draw border and corner textures with. /// The origin to draw from. /// The scale to draw with. /// The layer depth to draw with. - public static void DrawExtendedAutoTile(SpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color color, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0) { + public static void DrawExtendedAutoTile(SpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0) { var orig = origin ?? Vector2.Zero; var sc = scale ?? Vector2.One; var (p1, r1, p2, r2, p3, r3, p4, r4) = CalculateExtendedAutoTile(pos, textureRegion, connectsTo, sc); - batch.Draw(texture, pos, textureRegion, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Draw(texture, pos, textureRegion, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r1 != Rectangle.Empty) - batch.Draw(texture, p1, r1, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Draw(texture, p1, r1, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r2 != Rectangle.Empty) - batch.Draw(texture, p2, r2, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Draw(texture, p2, r2, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r3 != Rectangle.Empty) - batch.Draw(texture, p3, r3, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Draw(texture, p3, r3, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r4 != Rectangle.Empty) - batch.Draw(texture, p4, r4, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Draw(texture, p4, r4, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); } /// - public static void AddExtendedAutoTile(StaticSpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color color, float rotation = 0, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0) { + public static void AddExtendedAutoTile(StaticSpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, float rotation = 0, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0) { var orig = origin ?? Vector2.Zero; var sc = scale ?? Vector2.One; var (p1, r1, p2, r2, p3, r3, p4, r4) = CalculateExtendedAutoTile(pos, textureRegion, connectsTo, sc); - batch.Add(texture, pos, textureRegion, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Add(texture, pos, textureRegion, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r1 != Rectangle.Empty) - batch.Add(texture, p1, r1, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Add(texture, p1, r1, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r2 != Rectangle.Empty) - batch.Add(texture, p2, r2, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Add(texture, p2, r2, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r3 != Rectangle.Empty) - batch.Add(texture, p3, r3, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Add(texture, p3, r3, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); if (r4 != Rectangle.Empty) - batch.Add(texture, p4, r4, color, 0, orig, sc, SpriteEffects.None, layerDepth); + batch.Add(texture, p4, r4, overlayColor, 0, orig, sc, SpriteEffects.None, layerDepth); } private static (Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle) CalculateAutoTile(Vector2 pos, Rectangle textureRegion, ConnectsTo connectsTo, Vector2 scale) {