Even more documentation.

This commit is contained in:
2019-01-14 01:26:46 -06:00
parent 40c7772559
commit b019b7cf10
16 changed files with 368 additions and 46 deletions

View File

@@ -63,7 +63,7 @@ namespace RecrownedAthenaeum.UI.Book
for (int pageIndex = 0; pageIndex < pages.Count; pageIndex++)
{
Page page = pages.ElementAt(pageIndex).Value;
if (page.NeedsSizeUpdate) page.ApplySize(dimensions.Width, dimensions.Height);
if (page.requiresSizeUpdate) page.ApplySize(dimensions.Width, dimensions.Height);
page.Update(gameTime);
}
}

View File

@@ -2,26 +2,42 @@
namespace RecrownedAthenaeum.UI.Book
{
/// <summary>
/// A page a part of a <see cref="Book"/>.
/// </summary>
public class Page : UIModuleGroup
{
private readonly int pageX, pageY;
public bool NeedsSizeUpdate;
/// <summary>
/// Whether or not this book needs to be refreshed with new dimensions.
/// </summary>
public bool requiresSizeUpdate;
/// <summary>
/// Constructs a page.
/// </summary>
/// <param name="pageX">The X position in the book.</param>
/// <param name="pageY">The Y position in the book.</param>
public Page(int pageX, int pageY) : base(false)
{
this.pageX = pageX;
this.pageY = pageY;
NeedsSizeUpdate = true;
requiresSizeUpdate = true;
Name = ToString();
}
/// <summary>
/// Called when this page is flagged as needing a size update.
/// </summary>
/// <param name="width">New width.</param>
/// <param name="height">New Height</param>
public virtual void ApplySize(int width, int height)
{
bounds.X = pageX * width;
bounds.Y = pageY * height;
bounds.Width = width;
bounds.Height = height;
NeedsSizeUpdate = false;
requiresSizeUpdate = false;
}
}
}

View File

@@ -5,6 +5,9 @@ using System.Text;
namespace RecrownedAthenaeum.UI.Modular.Modules
{
/// <summary>
/// Represents text for the UI.
/// </summary>
public class Text : UIModule
{
private TextSkinDefinition skinDefinition;
@@ -14,28 +17,59 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
private string originalText;
private string displayedText;
private Vector2 modifiedTextSize;
/// <summary>
/// Whether or not to try and wrap text automatically. Meaning will check and attempt to wrap every update.
/// </summary>
public bool autoWrap;
/// <summary>
/// Whether or not to automatically scale the text every update. Happens after auto wrap if enabled.
/// </summary>
public bool autoScale;
/// <summary>
/// Should this use ellipses? Will perform this operation before auto wrapping or auto scalling.
/// </summary>
public bool useEllipses;
/// <summary>
/// The text to use for the ellipsis.
/// </summary>
public string ellipsis = "...";
private string ModifiedText { get { return displayedText; } set { displayedText = value; modifiedTextSize = font.MeasureString(value); } }
/// <summary>
/// The string to be displayed.
/// </summary>
public string Content { get { return originalText; } set { if (value == null) value = ellipsis; modifiedTextSize = font.MeasureString(value); originalText = value; displayedText = value; } }
/// <summary>
/// Creates a UI text object.
/// </summary>
/// <param name="font">The font to use.</param>
/// <param name="content">The string for the text.</param>
public Text(SpriteFont font, string content = null)
{
Content = content;
this.font = font;
}
public Text(Skin.Skin skin, string skinDefinitionName = null, string content = null)
/// <summary>
/// Creates a UI text object
/// </summary>
/// <param name="skin"></param>
/// <param name="skinDefinitionName"></param>
/// <param name="content"></param>
public Text(Skin.Skin skin, string skinDefinitionName = null, string content = null) : this(skin.fonts[skin.ObtainDefinition<TextSkinDefinition>(skinDefinitionName, typeof(Text)).font])
{
Content = content;
skinDefinition = skin.ObtainDefinition<TextSkinDefinition>(skinDefinitionName, GetType());
font = skin.fonts[skinDefinition.font];
color = skin.colors[skinDefinition.color];
}
/// <summary>
/// Updates the positioning and attempts to perform any operations that were marked automatic.
/// </summary>
/// <param name="gameTime">The game time.</param>
public override void Update(GameTime gameTime)
{
position.X = bounds.X;
@@ -48,12 +82,19 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
base.Update(gameTime);
}
/// <summary>
/// Draws the text.
/// </summary>
/// <param name="batch">Batch to use.</param>
public override void Draw(SpriteBatch batch)
{
batch.DrawString(font, Content, position, color, 0f, origin, scale, SpriteEffects.None, 0f);
base.Draw(batch);
}
/// <summary>
/// Attempts to apply ellipsis. Checks of nessecary.
/// </summary>
public void AttemptToApplyEllipsis()
{
if (modifiedTextSize.X * scale > bounds.Width && ModifiedText.Length > ellipsis.Length + 1)
@@ -71,6 +112,9 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
}
}
/// <summary>
/// Attempts to scale the font. Checks if nessecary.
/// </summary>
public void AttemptToScaleFont()
{
if (modifiedTextSize.X * scale > bounds.Width || modifiedTextSize.X * scale < bounds.Width - 5)
@@ -84,16 +128,26 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
}
}
/// <summary>
/// Removes line breaks.
/// </summary>
public void RemoveLineBreaks()
{
ModifiedText = ModifiedText.Replace("\n", " ");
}
/// <summary>
/// Resets to original text.
/// </summary>
public void ResetToOriginalText()
{
ModifiedText = originalText;
}
/// <summary>
/// Attempts to wrap text. Checks if nessecary.
/// </summary>
/// <param name="unwrap">If true, will first unwrap text, and the wrap again. This occurs before nessecity check.</param>
public void AttemptToWrapText(bool unwrap = false)
{
if (unwrap) RemoveLineBreaks();

View File

@@ -27,9 +27,9 @@ namespace RecrownedAthenaeum.UI.Skin
Dictionary<Type, Dictionary<string, ISkinDefinition>> definitions;
/// <summary>
///
/// Creates a basic unfilled skin.
/// </summary>
/// <param name="textureAtlas"></param>
/// <param name="textureAtlas">The texture atlas to use for this skin.</param>
public Skin(TextureAtlas textureAtlas)
{
this.textureAtlas = textureAtlas;
@@ -38,7 +38,16 @@ namespace RecrownedAthenaeum.UI.Skin
definitions = new Dictionary<Type, Dictionary<string, ISkinDefinition>>();
}
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, Type type, float rotation = 0, Vector2 origin = default(Vector2))
/// <summary>
/// Draws a region from the texture atlas.
/// </summary>
/// <param name="regionName">Region to draw.</param>
/// <param name="color">The color to tint the region.</param>
/// <param name="batch">The batch to use.</param>
/// <param name="destination">The destination to draw to.</param>
/// <param name="rotation">The rotation to use in radians.</param>
/// <param name="origin">The origin for the rotation.</param>
public void Draw(string regionName, string color, SpriteBatch batch, Rectangle destination, float rotation = 0, Vector2 origin = default(Vector2))
{
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
}
@@ -90,6 +99,11 @@ namespace RecrownedAthenaeum.UI.Skin
return ObtainDefinition<T>(null, type);
}
/// <summary>
/// Adds the definition.
/// </summary>
/// <param name="definitionName">The name of the definition.</param>
/// <param name="skinDefinition">The definition itself.</param>
public void AddDefinition(string definitionName, ISkinDefinition skinDefinition)
{
if (!definitions.ContainsKey(skinDefinition.UIModuleType))
@@ -100,6 +114,11 @@ namespace RecrownedAthenaeum.UI.Skin
definitions[skinDefinition.UIModuleType].Add(definitionName, skinDefinition);
}
/// <summary>
/// Removes the definition.
/// </summary>
/// <param name="definitionName">The name of the definition.</param>
/// <param name="definitionType">The type of the definition.</param>
public void RemoveDefinition(string definitionName, Type definitionType)
{
if (definitions.ContainsKey(definitionType) && definitions[definitionType].ContainsKey(definitionName))