mirror of
https://github.com/Ellpeck/MLEM.git
synced 2024-11-26 14:38:34 +01:00
return added items for all methods that use StaticSpriteBatch
This commit is contained in:
parent
6541c6d797
commit
f34d4e3b68
3 changed files with 51 additions and 35 deletions
|
@ -147,20 +147,20 @@ namespace MLEM.Extensions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D,Rectangle,Rectangle?,Color,float,Vector2,SpriteEffects,float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D,Rectangle,Rectangle?,Color,float,Vector2,SpriteEffects,float)"/>
|
||||||
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 source = sourceRectangle ?? new Rectangle(0, 0, texture.Width, texture.Height);
|
||||||
var scale = new Vector2(1F / source.Width, 1F / source.Height) * destinationRectangle.Size;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D,Rectangle,Rectangle?,Color)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D,Rectangle,Rectangle?,Color)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color) {
|
public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Rectangle? sourceRectangle, Color color) {
|
||||||
batch.Add(texture, destinationRectangle, sourceRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
|
return batch.Add(texture, destinationRectangle, sourceRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D,Rectangle,Color)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D,Rectangle,Color)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color) {
|
public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, Texture2D texture, RectangleF destinationRectangle, Color color) {
|
||||||
batch.Add(texture, destinationRectangle, null, color);
|
return batch.Add(texture, destinationRectangle, null, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AutoDispose(SpriteBatch batch, Texture2D texture) {
|
private static void AutoDispose(SpriteBatch batch, Texture2D texture) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
@ -42,14 +43,20 @@ namespace MLEM.Graphics {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="DrawAutoTile"/>
|
/// <inheritdoc cref="DrawAutoTile"/>
|
||||||
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<StaticSpriteBatch.Item> items = null) {
|
||||||
var orig = origin ?? Vector2.Zero;
|
var orig = origin ?? Vector2.Zero;
|
||||||
var sc = scale ?? Vector2.One;
|
var sc = scale ?? Vector2.One;
|
||||||
var (p1, r1, p2, r2, p3, r3, p4, r4) = CalculateAutoTile(pos, textureRegion, connectsTo, sc);
|
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);
|
var a1 = batch.Add(texture, p1, r1, color, 0, orig, sc, SpriteEffects.None, layerDepth);
|
||||||
batch.Add(texture, p2, r2, color, 0, orig, sc, SpriteEffects.None, layerDepth);
|
var a2 = batch.Add(texture, p2, r2, color, 0, orig, sc, SpriteEffects.None, layerDepth);
|
||||||
batch.Add(texture, p3, r3, color, 0, orig, sc, SpriteEffects.None, layerDepth);
|
var a3 = 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 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -95,20 +102,29 @@ namespace MLEM.Graphics {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="DrawExtendedAutoTile"/>
|
/// <inheritdoc cref="DrawExtendedAutoTile"/>
|
||||||
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<StaticSpriteBatch.Item> items = null) {
|
||||||
var orig = origin ?? Vector2.Zero;
|
var orig = origin ?? Vector2.Zero;
|
||||||
var sc = scale ?? Vector2.One;
|
var sc = scale ?? Vector2.One;
|
||||||
var od = layerDepth + overlayDepthOffset;
|
var od = layerDepth + overlayDepthOffset;
|
||||||
var (r1, r2, r3, r4) = CalculateExtendedAutoTile(pos, textureRegion, connectsTo, sc);
|
var (r1, r2, r3, r4) = CalculateExtendedAutoTile(pos, textureRegion, connectsTo, sc);
|
||||||
batch.Add(texture, pos, textureRegion, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth);
|
var background = batch.Add(texture, pos, textureRegion, backgroundColor, 0, orig, sc, SpriteEffects.None, layerDepth);
|
||||||
if (r1 != Rectangle.Empty)
|
items?.Add(background);
|
||||||
batch.Add(texture, pos, r1, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
if (r1 != Rectangle.Empty) {
|
||||||
if (r2 != Rectangle.Empty)
|
var o1 = batch.Add(texture, pos, r1, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||||
batch.Add(texture, pos, r2, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
items?.Add(o1);
|
||||||
if (r3 != Rectangle.Empty)
|
}
|
||||||
batch.Add(texture, pos, r3, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
if (r2 != Rectangle.Empty) {
|
||||||
if (r4 != Rectangle.Empty)
|
var o2 = batch.Add(texture, pos, r2, overlayColor, 0, orig, sc, SpriteEffects.None, od);
|
||||||
batch.Add(texture, pos, r4, 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) {
|
private static (Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle, Vector2, Rectangle) CalculateAutoTile(Vector2 pos, Rectangle textureRegion, ConnectsTo connectsTo, Vector2 scale) {
|
||||||
|
|
|
@ -173,38 +173,38 @@ namespace MLEM.Textures {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float 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) {
|
||||||
batch.Add(texture.Texture, position, texture.Area, color, rotation, origin + texture.PivotPixels, scale, effects, layerDepth);
|
return batch.Add(texture.Texture, position, texture.Area, color, rotation, origin + texture.PivotPixels, scale, effects, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float 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) {
|
||||||
batch.Add(texture, position, color, rotation, origin, new Vector2(scale), effects, layerDepth);
|
return batch.Add(texture, position, color, rotation, origin, new Vector2(scale), effects, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) {
|
public static StaticSpriteBatch.Item 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);
|
return batch.Add(texture.Texture, destinationRectangle, texture.Area, color, rotation, origin + texture.PivotPixels, effects, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color, float rotation, Vector2 origin, SpriteEffects effects, float layerDepth) {
|
public static StaticSpriteBatch.Item 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);
|
return batch.Add(texture.Texture, destinationRectangle, texture.Area, color, rotation, origin + texture.PivotPixels, effects, layerDepth);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color) {
|
public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Vector2 position, Color color) {
|
||||||
batch.Add(texture, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
|
return batch.Add(texture, position, color, 0, Vector2.Zero, Vector2.One, SpriteEffects.None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color) {
|
public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, Rectangle destinationRectangle, Color color) {
|
||||||
batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
|
return batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
/// <inheritdoc cref="StaticSpriteBatch.Add(Texture2D, Vector2, Rectangle?, Color, float, Vector2, Vector2, SpriteEffects, float)"/>
|
||||||
public static void Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color) {
|
public static StaticSpriteBatch.Item Add(this StaticSpriteBatch batch, TextureRegion texture, RectangleF destinationRectangle, Color color) {
|
||||||
batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
|
return batch.Add(texture, destinationRectangle, color, 0, Vector2.Zero, SpriteEffects.None, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue