added documentation and cleaned up some parameters. Added obtain and draw functions to the skin class.
This commit is contained in:
parent
081f84cd47
commit
8ddb79c135
@ -13,7 +13,6 @@ namespace RecrownedAthenaeum.DataTypes
|
||||
{
|
||||
public class TextureAtlas
|
||||
{
|
||||
[JsonIgnore]
|
||||
private Texture2D texture;
|
||||
|
||||
private Dictionary<string, TextureAtlasRegion> dictionaryOfRegions = new Dictionary<string, TextureAtlasRegion>();
|
||||
@ -33,15 +32,29 @@ namespace RecrownedAthenaeum.DataTypes
|
||||
this.dictionaryOfRegions = dictionaryOfRegions;
|
||||
}
|
||||
|
||||
public void Draw(string name, SpriteBatch batch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = new Vector2())
|
||||
/// <summary>
|
||||
/// Draw the region given by a string in the atlas onto a destination rectangle.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of region to draw.</param>
|
||||
/// <param name="batch">SpriteBatch to be used.</param>
|
||||
/// <param name="destination">The location to draw this region.</param>
|
||||
/// <param name="color">Color to use.</param>
|
||||
/// <param name="rotation">Rotation of texture drawn.</param>
|
||||
/// <param name="origin">Origin used by rotation.</param>
|
||||
public void Draw(string name, SpriteBatch batch, Rectangle destination, Color color = default(Color), float rotation = 0, Vector2 origin = new Vector2())
|
||||
{
|
||||
dictionaryOfRegions[name].Draw(batch, destination, color, rotation, origin);
|
||||
}
|
||||
|
||||
|
||||
public Texture2D TextureOfRegion(string name, GraphicsDevice graphicsDevice)
|
||||
/// <summary>
|
||||
/// Creates or obtains a previously created texture of a region.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of region.</param>
|
||||
/// <param name="graphicsDevice">graphics device to be used.</param>
|
||||
/// <returns>The texture from the region.</returns>
|
||||
public Texture2D ObtainRegionAsTexture(string name, GraphicsDevice graphicsDevice)
|
||||
{
|
||||
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice, texture);
|
||||
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice);
|
||||
}
|
||||
|
||||
public class TextureAtlasRegion : IComparable<TextureAtlasRegion>, IDisposable
|
||||
@ -52,11 +65,18 @@ namespace RecrownedAthenaeum.DataTypes
|
||||
Texture2D atlasTexture;
|
||||
Texture2D regionTexture;
|
||||
|
||||
public TextureAtlasRegion(string name, Rectangle source, NinePatch ninePatch, Texture2D atlasTexture)
|
||||
/// <summary>
|
||||
/// A specified region in a texture atlas.
|
||||
/// </summary>
|
||||
/// <param name="name">Name of region.</param>
|
||||
/// <param name="sourceRegion">The location of the region on the atlas.</param>
|
||||
/// <param name="ninePatch">A <see cref="NinePatch"/> definition for the region.</param>
|
||||
/// <param name="atlasTexture">The texture that holds the image data for the atlas.</param>
|
||||
public TextureAtlasRegion(string name, Rectangle sourceRegion, NinePatch ninePatch, Texture2D atlasTexture)
|
||||
{
|
||||
this.atlasTexture = atlasTexture;
|
||||
this.name = name;
|
||||
this.sourceRectangle = source;
|
||||
this.atlasTexture = atlasTexture ?? throw new ArgumentNullException("Name parameters can be null.");
|
||||
this.name = name ?? throw new ArgumentNullException("Name parameters can be null.");
|
||||
this.sourceRectangle = sourceRegion;
|
||||
this.ninepatch = ninePatch;
|
||||
}
|
||||
|
||||
@ -65,13 +85,18 @@ namespace RecrownedAthenaeum.DataTypes
|
||||
batch.Draw(atlasTexture, destination, sourceRectangle, color, rotation, origin, SpriteEffects.None, 0f);
|
||||
}
|
||||
|
||||
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice, Texture2D textureAtlas)
|
||||
/// <summary>
|
||||
/// Create or obtains a previously created texture of this region.
|
||||
/// </summary>
|
||||
/// <param name="graphicsDevice">The graphics device to use to create the texture.</param>
|
||||
/// <returns>The texture of the region.</returns>
|
||||
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
if (regionTexture == null)
|
||||
{
|
||||
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
|
||||
regionTexture = new Texture2D(graphicsDevice, sourceRectangle.Width, sourceRectangle.Height);
|
||||
textureAtlas.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
||||
atlasTexture.GetData(0, sourceRectangle, data, 0, sourceRectangle.Width * sourceRectangle.Height);
|
||||
regionTexture.SetData(data);
|
||||
}
|
||||
return regionTexture;
|
||||
|
@ -5,11 +5,11 @@ using System.Runtime.InteropServices;
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Recrowned-Athenaeum")]
|
||||
[assembly: AssemblyTitle("RecrownedAthenaeum")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Recrowned-Athenaeum")]
|
||||
[assembly: AssemblyProduct("RecrownedAthenaeum")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2018")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
@ -25,9 +25,19 @@ namespace RecrownedAthenaeum.UI.Skin
|
||||
definitions = new Dictionary<Type, Dictionary<string, ISkinDefinition>>();
|
||||
}
|
||||
|
||||
public void Draw(string texture, string color, Rectangle region)
|
||||
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, Type type, float rotation = 0, Vector2 origin = default(Vector2))
|
||||
{
|
||||
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
|
||||
}
|
||||
|
||||
public ISkinDefinition ObtainDefinition(string definitionName, Type type)
|
||||
{
|
||||
return definitions[type][definitionName];
|
||||
}
|
||||
|
||||
public T ObtainDefinition<T>(string definitionName) where T : ISkinDefinition
|
||||
{
|
||||
return (T)definitions[typeof(T)][definitionName];
|
||||
}
|
||||
|
||||
public void AddDefinition(string definitionName, ISkinDefinition skinDefinition)
|
||||
|
Loading…
Reference in New Issue
Block a user