2018-02-06 18:13:21 +08:00
|
|
|
using System.Collections.Generic;
|
2018-12-30 18:00:05 +08:00
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2018-02-06 18:13:21 +08:00
|
|
|
|
|
|
|
namespace StardustCore.UIUtilities
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>A class that keeps track of a collection of textures that are layered one on top of the others.</summary>
|
2018-02-06 18:13:21 +08:00
|
|
|
public class LayeredTexture
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
public List<KeyValuePair<Rectangle, Texture2DExtended>> textureLayers;
|
2018-02-06 18:13:21 +08:00
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
public LayeredTexture(List<KeyValuePair<Rectangle, Texture2DExtended>> textures)
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
|
|
|
this.textureLayers = textures;
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds a new texture as the top layer.</summary>
|
|
|
|
public void addTexture(KeyValuePair<Rectangle, Texture2DExtended> texture)
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
|
|
|
this.textureLayers.Add(texture);
|
|
|
|
}
|
|
|
|
|
2018-12-30 18:00:05 +08:00
|
|
|
/// <summary>Adds a new texture at a specific layer depth.</summary>
|
|
|
|
public void addTexture(KeyValuePair<Rectangle, Texture2DExtended> texture, int index)
|
2018-02-06 18:13:21 +08:00
|
|
|
{
|
|
|
|
this.textureLayers.Insert(index, texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
public LayeredTexture Copy()
|
|
|
|
{
|
|
|
|
return new LayeredTexture(this.textureLayers);
|
|
|
|
}
|
|
|
|
|
2018-08-23 16:23:42 +08:00
|
|
|
public void draw(SpriteBatch b, Color color, float layerDepth)
|
|
|
|
{
|
2018-12-30 18:00:05 +08:00
|
|
|
foreach (var texture in this.textureLayers)
|
2018-08-23 16:23:42 +08:00
|
|
|
b.Draw(texture.Value.getTexture(), texture.Key, color);
|
|
|
|
}
|
2018-02-06 18:13:21 +08:00
|
|
|
}
|
|
|
|
}
|