Done basic documentation. Further expansion may be needed. Maybe. But only maybe.

This commit is contained in:
Harrison Deng 2019-01-14 20:00:11 -06:00
parent b019b7cf10
commit 2a2a7cba49
5 changed files with 133 additions and 3 deletions

View File

@ -5,12 +5,27 @@ using System.Collections.Generic;
namespace RecrownedAthenaeum.DataTypes
{
/// <summary>
/// Holds information about an image file that contains various textures in various regions in the file.
/// </summary>
public class TextureAtlas
{
private Texture2D texture;
private Dictionary<string, TextureAtlasRegion> dictionaryOfRegions = new Dictionary<string, TextureAtlasRegion>();
/// <summary>
/// Given a name, can return a <see cref="TextureAtlasRegion"/>.
/// </summary>
/// <param name="name">Name of <see cref="TextureAtlasRegion"/> to obtain.</param>
/// <returns><see cref="TextureAtlasRegion"/> based off name.</returns>
public TextureAtlasRegion this[string name] { get { if (name != null && dictionaryOfRegions.ContainsKey(name)) return dictionaryOfRegions[name]; else return null; } }
/// <summary>
/// Creates a texture atlas with given main texture as well as an array of <see cref="TextureAtlasRegion"/> to represent locations of which textures reside within the atlas. Region names will be used to refer to the regions within the dictionary.
/// </summary>
/// <param name="texture">The texture representing the overall atlas.</param>
/// <param name="regions">The sub regions that represent the individual textures.</param>
public TextureAtlas(Texture2D texture, TextureAtlasRegion[] regions)
{
this.texture = texture;
@ -20,6 +35,11 @@ namespace RecrownedAthenaeum.DataTypes
}
}
/// <summary>
/// Creates a texture region given a dictionary of regions keyed to strings that can be used to refer to them.
/// </summary>
/// <param name="texture">The texture representing the overall atlas.</param>
/// <param name="dictionaryOfRegions"></param>
public TextureAtlas(Texture2D texture, Dictionary<string, TextureAtlasRegion> dictionaryOfRegions)
{
this.texture = texture;
@ -51,13 +71,23 @@ namespace RecrownedAthenaeum.DataTypes
return dictionaryOfRegions[name].AsTexture2D(graphicsDevice);
}
/// <summary>
/// A region of a <see cref="TextureAtlas"/>.
/// </summary>
public class TextureAtlasRegion : IComparable<TextureAtlasRegion>, ISpecialDrawable, IDisposable
{
/// <summary>
/// The name of the region. Mostly used to be refered to within the context of a <see cref="TextureAtlas"/>.
/// </summary>
public readonly string name;
/// <summary>
/// The location and dimensions of where the original texture resides on the texture representing the atlas.
/// </summary>
public readonly Rectangle sourceRectangle;
readonly NinePatch ninepatch;
Texture2D atlasTexture;
Texture2D regionTexture;
private bool disposed;
/// <summary>
/// A specified region in a texture atlas.
@ -74,8 +104,18 @@ namespace RecrownedAthenaeum.DataTypes
this.ninepatch = ninePatch;
}
public void Draw(SpriteBatch batch, Rectangle destination, Color color, float rotation, Vector2 origin)
/// <summary>
/// Draws the region. If ninepatch, rotation and origin are ignored.
/// </summary>
/// <param name="batch">The batch to use. Should be began.</param>
/// <param name="destination">The destination rectangle to draw to.</param>
/// <param name="color">The color to use.</param>
/// <param name="rotation">Rotation of the final drawing. Ignored if is a 9patch.</param>
/// <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 (ninepatch != null)
{
ninepatch.Draw(batch, destination);
@ -92,6 +132,8 @@ namespace RecrownedAthenaeum.DataTypes
/// <returns>The texture of the region.</returns>
public Texture2D AsTexture2D(GraphicsDevice graphicsDevice)
{
if (disposed) throw new ObjectDisposedException(GetType().Name);
if (regionTexture == null)
{
Color[] data = new Color[sourceRectangle.Width * sourceRectangle.Height];
@ -102,15 +144,46 @@ namespace RecrownedAthenaeum.DataTypes
return regionTexture;
}
/// <summary>
/// Compares this region to another in terms of name.
/// </summary>
/// <param name="other">The other region to compare to in terms of name.</param>
/// <returns>Less than one if precedes, greater than one if after, 0 if same.</returns>
public int CompareTo(TextureAtlasRegion other)
{
return name.CompareTo(other);
}
/// <summary>
/// Call this to dispose.
/// </summary>
public void Dispose()
{
if (disposed) throw new ObjectDisposedException(GetType().Name);
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// Overridable dispose.
/// </summary>
/// <param name="disposing">Whether or not this was a user made call.</param>
public virtual void Dispose(bool disposing)
{
if (disposing && !disposed)
{
regionTexture?.Dispose();
}
disposed = true;
}
/// <summary>
/// Destructor.
/// </summary>
~TextureAtlasRegion()
{
Dispose(false);
}
}
}
}

View File

@ -32,6 +32,7 @@ namespace RecrownedAthenaeum.ScreenSystem
/// Transitions to apply.
/// </summary>
public readonly List<ITransition> Transitions;
/// <summary>
/// Whether or not to continue rendering this screen onto a buffer for the benifit of the next screen to use as a transition.
/// </summary>
@ -113,7 +114,6 @@ namespace RecrownedAthenaeum.ScreenSystem
/// </summary>
/// <param name="delta">Time passed since last frame in seconds.</param>
/// <param name="waiting">If the this transition should wait.</param>
/// <param name="previousScreenExitFrame">The previous screen's frame. May be null.</param>
/// <returns>Only returns true if exit transition is complete. Returns false otherwise.</returns>
public bool UpdateTransition(double delta, bool waiting)
{

View File

@ -5,11 +5,27 @@ using RecrownedAthenaeum.UI.Skin.Definitions;
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
{
/// <summary>
/// Button that holds a string.
/// </summary>
public class TextButton : Button
{
private Text text;
/// <summary>
/// The color the font should be rendered in.
/// </summary>
public Color FontColor { get { return text.color; } set { text.color = value; } }
/// <summary>
/// Constructs text button with the positions represented by <see cref="ISpecialDrawable"/>
/// </summary>
/// <param name="text">The string representing the text to be displayed.</param>
/// <param name="font">The font to be used to display the text.</param>
/// <param name="down">What to draw as button is pushed down.</param>
/// <param name="up">What to draw as button is not pushed.</param>
/// <param name="disabled">What to draw as button is disabled.</param>
/// <param name="selected">What to draw as button is selected.</param>
public TextButton(string text, SpriteFont font, ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null) : base(down, up, disabled, selected)
{
this.text = new Text(font, text)
@ -18,6 +34,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
};
}
/// <summary>
/// Constructs a text button using a skin and definition.
/// </summary>
/// <param name="text">The text to display.</param>
/// <param name="skin">The skin to use.</param>
/// <param name="definitionName">Name of the definition for this type in the skin given.</param>
public TextButton(string text, Skin.Skin skin, string definitionName = null) : base(skin, definitionName)
{
TextButtonSkinDefinition skinDefinition = skin.ObtainDefinition<TextButtonSkinDefinition>(definitionName, GetType());
@ -25,6 +47,10 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
FontColor = skin.colors[skinDefinition.fontColor];
}
/// <summary>
/// Updates the text button.
/// </summary>
/// <param name="gameTime">Snapshot of information about time for game.</param>
public override void Update(GameTime gameTime)
{
text.bounds = bounds;
@ -32,6 +58,10 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
base.Update(gameTime);
}
/// <summary>
/// Called whenever game wants to render this button.
/// </summary>
/// <param name="batch">Batch to use. Batch should already be started.</param>
public override void Draw(SpriteBatch batch)
{
text.Draw(batch);

View File

@ -16,10 +16,19 @@ namespace RecrownedAthenaeum.UI.Modular
List<UIModule> modules = new List<UIModule>();
Rectangle scissorBounds;
RasterizerState scissorRasterizer = new RasterizerState();
/// <summary>
/// Camera used by the module for cropping.
/// </summary>
public Camera2D Camera { get; set; }
/// <summary>
/// Creates a module group.
/// </summary>
/// <param name="crop">Whether or not to crop out of bounds. Default is false.</param>
/// <param name="camera">What camera to use for cropping. Default is null.</param>
public UIModuleGroup(bool crop = false, Camera2D camera = null)
{
if (crop && camera == null) throw new ArgumentException("Cannot crop without camera.");
Camera = camera;
if (crop)
{

View File

@ -3,13 +3,31 @@ using System;
namespace RecrownedAthenaeum.UI.Skin.Definitions
{
/// <summary>
/// Definition for a text button for a skin theme.
/// </summary>
public class TextButtonSkinDefinition : ButtonSkinDefinition
{
/// <summary>
/// Name of font from the skin to use.
/// </summary>
public string fontName;
/// <summary>
/// Name of color from the skin to use for the font.
/// </summary>
public string fontColor;
/// <summary>
/// The type of module that will be using this definition.
/// </summary>
public new Type UIModuleType => typeof(TextButton);
/// <summary>
/// Creates this definition with the most minimal requirements.
/// </summary>
/// <param name="downRegion">Texture region from skin that represents when the button is pressed down.</param>
/// <param name="upRegion">The texture region that represents when the button is not pressed.</param>
public TextButtonSkinDefinition(string downRegion, string upRegion) : base(downRegion, upRegion)
{