Progress on skin system, added skin stack.
This commit is contained in:
@@ -14,13 +14,13 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
private Texture2D texture;
|
||||
private bool disposed;
|
||||
private Dictionary<string, Region> dictionaryOfRegions = new Dictionary<string, Region>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Given a name, can return a <see cref="Region"/>.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of <see cref="Region"/> to obtain.</param>
|
||||
/// <returns><see cref="Region"/> based off name.</returns>
|
||||
public Region this[string name] { get { if (name != null && dictionaryOfRegions.ContainsKey(name)) return dictionaryOfRegions[name]; else return null; } }
|
||||
public Region this[string name] { get { if (name != null && dictionaryOfRegions.ContainsKey(name)) return dictionaryOfRegions[name]; else throw new KeyNotFoundException("Given key \"" + name + "\" does not exist."); } }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a texture atlas with given main texture as well as an array of <see cref="Region"/> to represent locations of which textures reside within the atlas. Region names will be used to refer to the regions within the dictionary.
|
||||
@@ -92,7 +92,12 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
texture.Dispose();
|
||||
for (int i = 0; i < dictionaryOfRegions.Count; i++)
|
||||
{
|
||||
dictionaryOfRegions.ElementAt(i).Value.Dispose();
|
||||
Region region = dictionaryOfRegions.ElementAt(i).Value;
|
||||
|
||||
if (!region.Disposed)
|
||||
{
|
||||
dictionaryOfRegions.ElementAt(i).Value.Dispose();
|
||||
}
|
||||
}
|
||||
dictionaryOfRegions.Clear();
|
||||
}
|
||||
@@ -123,7 +128,11 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
readonly NinePatch ninepatch;
|
||||
Texture2D atlasTexture;
|
||||
Texture2D regionTexture;
|
||||
private bool disposed;
|
||||
|
||||
/// <summary>
|
||||
/// If region has already been disposed.
|
||||
/// </summary>
|
||||
public bool Disposed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// A specified region in a texture atlas.
|
||||
@@ -150,12 +159,13 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <param name="origin">The origin of the drawing. Ignored if is a 9patch.</param>
|
||||
public void Draw(SpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
{
|
||||
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
if (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
|
||||
if (ninepatch != null)
|
||||
{
|
||||
ninepatch.Draw(batch, destination);
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
batch.Draw(atlasTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
}
|
||||
@@ -168,7 +178,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <returns>The texture of the region.</returns>
|
||||
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
if (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
|
||||
if (regionTexture == null)
|
||||
{
|
||||
@@ -195,7 +205,7 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
if (Disposed) throw new ObjectDisposedException(GetType().Name);
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
@@ -206,13 +216,13 @@ namespace RecrownedAthenaeum.SpecialTypes
|
||||
/// <param name="disposing">Whether or not this was a user made call.</param>
|
||||
public virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && !disposed)
|
||||
if (disposing && !Disposed)
|
||||
{
|
||||
regionTexture?.Dispose();
|
||||
}
|
||||
disposed = true;
|
||||
Disposed = true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Destructor.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user