diff --git a/MLEM/Extensions/SpriteBatchExtensions.cs b/MLEM/Extensions/SpriteBatchExtensions.cs index d8da017..9894977 100644 --- a/MLEM/Extensions/SpriteBatchExtensions.cs +++ b/MLEM/Extensions/SpriteBatchExtensions.cs @@ -147,20 +147,20 @@ namespace MLEM.Extensions { } /// - public static void Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { var source = sourceRectangle ?? new Rectangle(0, 0, texture.Width, texture.Height); var scale = new Vector2(1F / source.Width, 1F / source.Height) * destinationRectangle.Size; - batch.Add(texture, destinationRectangle.Location, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); + return batch.Add(texture, destinationRectangle.Location, sourceRectangle, color, rotation, origin, scale, effects, layerDepth); } /// - public static void Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color) { - batch.Add(texture, destinationRectangle, sourceRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color) { + return batch.Add(texture, destinationRectangle, sourceRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0); } /// - public static void Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color) { - batch.Add(texture, destinationRectangle, null, color); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color) { + return batch.Add(texture, destinationRectangle, null, color); } private static void AutoDispose(SpriteBatch batch, Texture2D texture) { diff --git a/MLEM/Graphics/AutoTiling.cs b/MLEM/Graphics/AutoTiling.cs index 1958df6..7f86c4f 100644 --- a/MLEM/Graphics/AutoTiling.cs +++ b/MLEM/Graphics/AutoTiling.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -42,14 +43,20 @@ namespace MLEM.Graphics { } /// - public static void AddAutoTile(StaticSpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color color, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0) { + public static void AddAutoTile(StaticSpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color color, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0, ICollection items = null) { var orig = origin ?? Vector2.Zero; var sc = scale ?? Vector2.One; var (p1, r1, p2, r2, p3, r3, p4, r4) = CalculateAutoTile(pos, textureRegion, connectsTo, sc); - batch.Add(texture, p1, r1, color, 0, orig, sc, SpriteEffects.None, layerDepth); - batch.Add(texture, p2, r2, color, 0, orig, sc, SpriteEffects.None, layerDepth); - batch.Add(texture, p3, r3, color, 0, orig, sc, SpriteEffects.None, layerDepth); - batch.Add(texture, p4, r4, color, 0, orig, sc, SpriteEffects.None, layerDepth); + var a1 = batch.Add(texture, p1, r1, color, 0, orig, sc, SpriteEffects.None, layerDepth); + var a2 = batch.Add(texture, p2, r2, color, 0, orig, sc, SpriteEffects.None, layerDepth); + var a3 = batch.Add(texture, p3, r3, color, 0, orig, sc, SpriteEffects.None, layerDepth); + var a4 = batch.Add(texture, p4, r4, color, 0, orig, sc, SpriteEffects.None, layerDepth); + if (items != null) { + items.Add(a1); + items.Add(a2); + items.Add(a3); + items.Add(a4); + } } /// @@ -95,20 +102,29 @@ namespace MLEM.Graphics { } /// - public static void AddExtendedAutoTile(StaticSpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0, float overlayDepthOffset = 0) { + public static void AddExtendedAutoTile(StaticSpriteBatch batch, Vector2 pos, Texture2D texture, Rectangle textureRegion, ConnectsTo connectsTo, Color backgroundColor, Color overlayColor, Vector2? origin = null, Vector2? scale = null, float layerDepth = 0, float overlayDepthOffset = 0, ICollection items = null) { var orig = origin ?? Vector2.Zero; var sc = scale ?? Vector2.One; var od = layerDepth + overlayDepthOffset; var (r1, r2, r3, r4) = CalculateExtendedAutoTile(pos, textureRegion, connectsTo, sc); - batch.Add(texture, pos, textureRegion, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); - if (r1 != Rectangle.Empty) - batch.Add(texture, pos, r1, overlayColor, 0, orig, sc, SpriteEffects.None, od); - if (r2 != Rectangle.Empty) - batch.Add(texture, pos, r2, overlayColor, 0, orig, sc, SpriteEffects.None, od); - if (r3 != Rectangle.Empty) - batch.Add(texture, pos, r3, overlayColor, 0, orig, sc, SpriteEffects.None, od); - if (r4 != Rectangle.Empty) - batch.Add(texture, pos, r4, overlayColor, 0, orig, sc, SpriteEffects.None, od); + var background = batch.Add(texture, pos, textureRegion, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth); + items?.Add(background); + if (r1 != Rectangle.Empty) { + var o1 = batch.Add(texture, pos, r1, overlayColor, 0, orig, sc, SpriteEffects.None, od); + items?.Add(o1); + } + if (r2 != Rectangle.Empty) { + var o2 = batch.Add(texture, pos, r2, overlayColor, 0, orig, sc, SpriteEffects.None, od); + items?.Add(o2); + } + if (r3 != Rectangle.Empty) { + var o3 = batch.Add(texture, pos, r3, overlayColor, 0, orig, sc, SpriteEffects.None, od); + items?.Add(o3); + } + if (r4 != Rectangle.Empty) { + var o4 = batch.Add(texture, pos, r4, overlayColor, 0, orig, sc, SpriteEffects.None, od); + items?.Add(o4); + } } private static (Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle) CalculateAutoTile(Vector2 pos, Rectangle textureRegion, ConnectsTo connectsTo, Vector2 scale) { diff --git a/MLEM/Textures/TextureRegion.cs b/MLEM/Textures/TextureRegion.cs index 6557567..ecb6569 100644 --- a/MLEM/Textures/TextureRegion.cs +++ b/MLEM/Textures/TextureRegion.cs @@ -173,38 +173,38 @@ namespace MLEM.Textures { } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { - batch.Add(texture.Texture, position, texture.Area, color, rotation, origin + texture.PivotPixels, scale, effects, layerDepth); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) { + return batch.Add(texture.Texture, position, texture.Area, color, rotation, origin + texture.PivotPixels, scale, effects, layerDepth); } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { - batch.Add(texture, position, color, rotation, origin, new Vector2(scale), effects, layerDepth); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth) { + return batch.Add(texture, position, color, rotation, origin, new Vector2(scale), effects, layerDepth); } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { - batch.Add(texture.Texture, destinationRectangle, texture.Area, color, rotation, origin + texture.PivotPixels, effects, layerDepth); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { + return batch.Add(texture.Texture, destinationRectangle, texture.Area, color, rotation, origin + texture.PivotPixels, effects, layerDepth); } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { - batch.Add(texture.Texture, destinationRectangle, texture.Area, color, rotation, origin + texture.PivotPixels, effects, layerDepth); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) { + return batch.Add(texture.Texture, destinationRectangle, texture.Area, color, rotation, origin + texture.PivotPixels, effects, layerDepth); } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color) { - batch.Add(texture, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color) { + return batch.Add(texture, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color) { - batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color) { + return batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0); } /// - public static void Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color) { - batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0); + public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color) { + return batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0); } }