Even more documentation.

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

View File

@ -1,17 +1,37 @@
namespace RecrownedAthenaeum.Pipeline.NinePatch
using RecrownedAthenaeum.Pipeline.TextureAtlas;
namespace RecrownedAthenaeum.Pipeline.NinePatch
{
/// <summary>
/// Represents a data structure for 9patches.
/// </summary>
public class NinePatchData
{
/// <summary>
/// Name of texture associated with patch. May be null in the case of being apart of a <see cref="TextureAtlasData"/>
/// </summary>
public string textureName;
public int left, right, down, top;
public NinePatchData(string textureName, int left, int right, int down, int top)
/// <summary>
/// the boundaries of the patch.
/// </summary>
public int left, right, bottom, top;
/// <summary>
/// Constructs patch.
/// </summary>
/// <param name="textureName">Name of the texture. May be null.</param>
/// <param name="left">Left bound.</param>
/// <param name="right">Right bound.</param>
/// <param name="bottom">Bottom bound.</param>
/// <param name="Top">Top bound.</param>
public NinePatchData(string textureName, int left, int right, int bottom, int Top)
{
this.textureName = textureName;
this.left = left;
this.right = right;
this.down = down;
this.top = top;
this.bottom = bottom;
this.top = Top;
}
}
}

View File

@ -3,8 +3,19 @@ using Microsoft.Xna.Framework.Graphics;
namespace RecrownedAthenaeum.DataTypes
{
/// <summary>
/// A wrapper that makes sure anything implementing can be drawn with options.
/// </summary>
public interface ISpecialDrawable
{
/// <summary>
/// Should draw whatever implements this.
/// </summary>
/// <param name="spriteBatch">The batch to be used.</param>
/// <param name="destination">The location and dimensions to draw to.</param>
/// <param name="color">The color tint to draw with.</param>
/// <param name="rotation">The rotation to be used.</param>
/// <param name="origin">The origin for the rotation.</param>
void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0f, Vector2 origin = default(Vector2));
}
}

View File

@ -4,9 +4,18 @@ using System;
namespace RecrownedAthenaeum.DataTypes
{
/// <summary>
/// An object that represents a ninepatch.
/// </summary>
public class NinePatch : ISpecialDrawable
{
/// <summary>
/// color of 9patch.
/// </summary>
public Color color;
/// <summary>
/// Dimensions in ninepatch. May also represent position in texture atlas.
/// </summary>
public Rectangle textureRegion;
readonly Texture2D texture;
readonly int left, right, bottom, top;
@ -33,6 +42,11 @@ namespace RecrownedAthenaeum.DataTypes
color = Color.White;
}
/// <summary>
/// Draws the ninepatch.
/// </summary>
/// <param name="spriteBatch">Batch to use.</param>
/// <param name="destination">Where to the patch.</param>
public void Draw(SpriteBatch spriteBatch, Rectangle destination)
{
Rectangle sourceRectangle;
@ -175,6 +189,14 @@ namespace RecrownedAthenaeum.DataTypes
spriteBatch.Draw(texture, drawnRectangle, sourceRectangle, color);
}
/// <summary>
/// Draw with more options.
/// </summary>
/// <param name="spriteBatch">Spritebatch to use.</param>
/// <param name="destination">The destination to draw the patch.</param>
/// <param name="color">The tint for each patch.</param>
/// <param name="rotation">Not considered for 9patches.</param>
/// <param name="origin">Not considered for 9patches.</param>
public void Draw(SpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
{
this.color = color;

View File

@ -2,30 +2,50 @@
namespace RecrownedAthenaeum.DataTypes
{
public class Resolution : IComparable<Resolution>
/// <summary>
/// Holds a width and height while allowing for easier comparison between other <see cref="Resolution"/>s.
/// </summary>
public struct Resolution : IComparable<Resolution>
{
/// <summary>
/// Dimensions of resolution.
/// </summary>
public int Width, Height;
/// <summary>
/// Constructs resolution given the dimensions.
/// </summary>
/// <param name="width">Width of resolution.</param>
/// <param name="height">Height of resolution.</param>
public Resolution(int width, int height)
{
Width = width;
Height = height;
}
public Resolution()
{
}
/// <summary>
/// Compares area of this resolution to another.
/// </summary>
/// <param name="other">The other resolution to compare to.</param>
/// <returns>A value less than 0 for this being the smaller resolution, 0 for the two being the same in area, and larger for this being the larger in area.</returns>
public int CompareTo(Resolution other)
{
return Area() - other.Area();
}
/// <summary>
/// Gets a string representation of this resolution.
/// </summary>
/// <returns>"WidthxHeight"</returns>
public override string ToString()
{
return Width + "x" + Height;
}
/// <summary>
/// Calculates area of resolution.
/// </summary>
/// <returns>Area of resolution.</returns>
public int Area()
{
return Width * Height;

View File

@ -4,8 +4,14 @@ using System.Collections.Generic;
namespace RecrownedAthenaeum.Input
{
/// <summary>
/// Utilities to better manage input for the game.
/// </summary>
public static class InputUtilities
{
/// <summary>
/// Listeners for changes in input.
/// </summary>
public static List<IInputListener> InputListeners;
static KeyboardState keyboardState;
static MouseState mouseState;
@ -15,6 +21,10 @@ namespace RecrownedAthenaeum.Input
InputListeners = new List<IInputListener>();
}
/// <summary>
/// Updates inputs.
/// Should be called once every game update to be up to date with new states of inputs.
/// </summary>
public static void Update()
{
KeyboardState updatedKeyboardState = Keyboard.GetState();
@ -40,6 +50,10 @@ namespace RecrownedAthenaeum.Input
UpdateStates();
}
/// <summary>
/// Poll used to check if mouse was clicked.
/// </summary>
/// <returns>True if clicked.</returns>
public static bool MouseClicked()
{
if (mouseState.LeftButton == ButtonState.Pressed)
@ -55,6 +69,11 @@ namespace RecrownedAthenaeum.Input
mouseState = Mouse.GetState();
}
/// <summary>
/// Checks whether mouse is within boundaries.
/// </summary>
/// <param name="bounds">Boundaries to check.</param>
/// <returns></returns>
public static bool MouseWithinBoundries(Rectangle bounds)
{
MouseState mouseState = Mouse.GetState();

View File

@ -6,12 +6,20 @@ using System.Xml.Serialization;
namespace RecrownedAthenaeum.Persistence
{
/// <summary>
/// Manages a bundle of preferences.
/// </summary>
public class PreferencesManager
{
private readonly Dictionary<Type, object> preferenceList;
string savePath;
XmlSerializer xmlSerializer;
/// <summary>
/// Constructs the preference manager.
/// </summary>
/// <param name="savePath">The path of the directory in which the preferences should be saved.</param>
/// <param name="preferences">The preferences to be serialized and unserialized in XML format.</param>
public PreferencesManager(string savePath, params object[] preferences)
{
this.savePath = savePath;
@ -29,11 +37,19 @@ namespace RecrownedAthenaeum.Persistence
xmlSerializer = new XmlSerializer(typeof(object), preferenceTypes);
}
/// <summary>
/// Returns the preference by type.
/// </summary>
/// <typeparam name="T">The preference needed.</typeparam>
/// <returns>The preference needed.</returns>
public T GetPreferences<T>()
{
return (T)preferenceList[typeof(T)];
}
/// <summary>
/// Loads preferences.
/// </summary>
public void Load()
{
List<Type> keys = new List<Type>(preferenceList.Keys);
@ -47,6 +63,9 @@ namespace RecrownedAthenaeum.Persistence
}
}
/// <summary>
/// Saves preferences.
/// </summary>
public void Save()
{
foreach (KeyValuePair<Type, object> prefs in preferenceList)

View File

@ -25,7 +25,7 @@ namespace RecrownedAthenaeum.Pipeline
if (regionData.ninePatchData != null)
{
NinePatchData nPatchData = regionData.ninePatchData;
nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.down, nPatchData.down);
nPatch = new DataTypes.NinePatch(atlasTexture, nPatchData.left, nPatchData.right, nPatchData.bottom, nPatchData.bottom);
}
regions[regionID] = new DataTypes.TextureAtlas.TextureAtlasRegion(regionData.name, regionData.location, nPatch, atlasTexture);

View File

@ -6,9 +6,15 @@ using System.Collections.Generic;
namespace RecrownedAthenaeum.Render
{
/// <summary>
/// A batch used to draw primitive shapes by batching together vertices.
/// </summary>
public class PrimitiveBatch : IDisposable
{
List<VertexPositionColor> vertices;
/// <summary>
/// The maximum vertices expected. The further off this expectancy is from the true value, the less efficient.
/// </summary>
public int MaxVertices { get { return vertices.Capacity; } set { vertices.Capacity = value; } }
int bufferPosition;
BasicEffect basicEffect;
@ -80,7 +86,8 @@ namespace RecrownedAthenaeum.Render
if (primitiveType != PrimitiveType.LineStrip && primitiveType != PrimitiveType.TriangleStrip)
{
Flush();
} else
}
else
{
throw new InvalidOperationException("Buffer size isn't large enough.");
}
@ -103,23 +110,35 @@ namespace RecrownedAthenaeum.Render
bufferPosition = 0;
}
/// <summary>
/// Disposes this.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
public void Dispose(bool disposing)
/// <summary>
/// Overridable dispose.
/// </summary>
/// <param name="disposing">True for when user called for this to be disposed. False otherwise.</param>
public virtual void Dispose(bool disposing)
{
if (disposed) throw new ObjectDisposedException(this.GetType().Name);
disposed = true;
if (disposing && !disposed)
{
basicEffect.Dispose();
disposed = true;
}
else
{
if (disposed) throw new ObjectDisposedException(this.GetType().Name);
}
}
/// <summary>
/// Destructor.
/// </summary>
~PrimitiveBatch()
{
Dispose(false);
}
}
}

View File

@ -3,11 +3,14 @@ using Microsoft.Xna.Framework.Graphics;
namespace RecrownedAthenaeum.ScreenSystem
{
/// <summary>
/// Contracts a transition that the <see cref="ScreenManager"/> can use.
/// </summary>
public interface ITransition
{
/// <summary>
/// Called once when the transition is needed.
/// <param name="Dimensions">The dimensions of the screen.</param>
/// <param name="dimensions">The dimensions of the screen.</param>
/// </summary>
void InitiateTransition(Rectangle dimensions);
@ -16,9 +19,8 @@ namespace RecrownedAthenaeum.ScreenSystem
/// </summary>
/// <param name="delta">The time passed in seconds since the last frame.</param>
/// <param name="waiting">Whether or not this transition is waiting on something. Usually the <see cref="ContentSystem"/>.</param>
/// <param name="previousScreenExitFrame">The frame being rendered by the screen as it exits. This can be null.</param>
/// <returns>If this returns true, then it is considered that this transition is complete.</returns>
bool EnteringTransition(double delta, bool waiting);
bool UpdateEnteringTransition(double delta, bool waiting);
/// <summary>
/// Called every frame if the state of the screen this transition is placed upon is in the exit phase.
@ -26,7 +28,7 @@ namespace RecrownedAthenaeum.ScreenSystem
/// <param name="delta">The time passed in seconds since the last frame.</param>
/// <param name="waiting">Whether or not this transition is waiting on something. Usually the <see cref="ContentSystem"/>.</param>
/// <returns>If this returns true, then it is considered that this transition is complete.</returns>
bool ExitingTransition(double delta, bool waiting);
bool UpdateExitingTransition(double delta, bool waiting);
/// <summary>
/// Called once every frame while transition is active. Meant to draw transition.

View File

@ -5,6 +5,9 @@ using System;
namespace RecrownedAthenaeum.ScreenSystem
{
/// <summary>
/// A screen specifically meant to fill in loading times.
/// </summary>
public class LoadingScreen : Screen, ITransition
{
private const float ENTER_TIME = 2f;
@ -22,6 +25,13 @@ namespace RecrownedAthenaeum.ScreenSystem
readonly bool rotate;
Vector2 origin;
/// <summary>
/// Constructs a loading screen.
/// </summary>
/// <param name="game">The game itself to adjust mouse settings and such.</param>
/// <param name="screenImage"></param>
/// <param name="proportion"></param>
/// <param name="rotate"></param>
public LoadingScreen(Game game, Texture2D screenImage, float proportion, bool rotate = false) : base(true)
{
this.game = game;
@ -31,18 +41,24 @@ namespace RecrownedAthenaeum.ScreenSystem
Transitions.Add(this);
}
/// <inheritdoc />
public override void Show()
{
game.IsMouseVisible = false;
base.Show();
}
/// <inheritdoc />
public override void Hide()
{
game.IsMouseVisible = true;
base.Hide();
}
/// <summary>
/// Sets things to correct values for start of transition.
/// </summary>
/// <param name="dimensions">The window dimensions.</param>
public void InitiateTransition(Rectangle dimensions)
{
color = Color.White;
@ -63,13 +79,22 @@ namespace RecrownedAthenaeum.ScreenSystem
}
}
/// <summary>
/// Draws the transition.
/// </summary>
/// <param name="spriteBatch">Batch to use.</param>
public void DrawTransition(SpriteBatch spriteBatch)
{
spriteBatch.Draw(texture, textureBounds, null, color, rotation, origin, SpriteEffects.None, 0f);
}
public bool EnteringTransition(double delta, bool waiting)
/// <summary>
/// Updates the entering transition.
/// </summary>
/// <param name="delta">Time passed between frames.</param>
/// <param name="waiting">Whether or not this transition should be waiting.</param>
/// <returns>Whether or not transition is complete.</returns>
public bool UpdateEnteringTransition(double delta, bool waiting)
{
float deltaf = (float)delta;
if (rotate)
@ -106,7 +131,13 @@ namespace RecrownedAthenaeum.ScreenSystem
return false;
}
public bool ExitingTransition(double delta, bool waiting)
/// <summary>
/// Updates the exiting transition.
/// </summary>
/// <param name="delta">Time passed between frames.</param>
/// <param name="waiting">Whether or not this transition should be waiting.</param>
/// <returns>Whether or not transition is complete.</returns>
public bool UpdateExitingTransition(double delta, bool waiting)
{
float deltaf = (float)delta;
if (rotate)

View File

@ -5,18 +5,72 @@ using System.Collections.Generic;
namespace RecrownedAthenaeum.ScreenSystem
{
public enum ScreenState { EnterTransition, ExitTransition, Normal }
/// <summary>
/// Represents one of the poosible states a screen can be in.
/// </summary>
public enum ScreenState {
/// <summary>
/// Screen is transitioning in.
/// </summary>
EnterTransition,
/// <summary>
/// Screen is transitioning out.
/// </summary>
ExitTransition,
/// <summary>
/// Screen is currently displayed normally without transition.
/// </summary>
Normal
}
/// <summary>
/// A screen represents a virtual system of management that controls an system of items to be displayed.
/// </summary>
public class Screen
{
public List<ITransition> Transitions;
public bool UseRenderTargetForExitTransition;
/// <summary>
/// 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>
public bool UseRenderTargetForExitTransition { get; private set; }
/// <summary>
/// The background color to be used to clear the screen.
/// </summary>
public Color BackgroundColor;
public GraphicsDevice GraphicsDevice { get; private set; }
/// <summary>
/// The next screen to be displayed after exit transition finishes. May be null, leading to transition to previous screen or loading screen.
/// </summary>
public Screen NextScreen { get; set; }
/// <summary>
/// The current window size.
/// </summary>
public Rectangle ScreenSize { get; private set; }
/// <summary>
/// Whether or not screen have been initiated.
/// </summary>
public bool Initiated { get; private set; }
/// <summary>
/// The 2D camera to be used for the screen.
/// </summary>
public Camera2D Camera { get; private set; }
/// <summary>
/// Current state of the screen.
/// </summary>
public ScreenState State { get; private set; }
/// <summary>
/// Creates a new screen.
/// </summary>
/// <param name="useEnterTransition">True to start in entering transition state.</param>
public Screen(bool useEnterTransition = false)
{
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
@ -26,11 +80,10 @@ namespace RecrownedAthenaeum.ScreenSystem
/// <summary>
/// Called only once after initialization to give required parameters.
/// </summary>
public virtual void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
public virtual void Initiate(Rectangle screenSize, Camera2D camera)
{
this.Camera = camera;
this.ScreenSize = screenSize;
GraphicsDevice = graphicsDevice;
Initiated = true;
}
@ -82,7 +135,7 @@ namespace RecrownedAthenaeum.ScreenSystem
for (int transitionID = 0; transitionID < Transitions.Count; transitionID++)
{
ITransition transition = Transitions[transitionID];
if (!transition.EnteringTransition(delta, waiting))
if (!transition.UpdateEnteringTransition(delta, waiting))
{
complete = false;
}
@ -98,7 +151,7 @@ namespace RecrownedAthenaeum.ScreenSystem
bool complete = true;
foreach (ITransition transition in Transitions)
{
if (!transition.ExitingTransition(delta, waiting))
if (!transition.UpdateExitingTransition(delta, waiting))
{
complete = false;
}
@ -135,7 +188,6 @@ namespace RecrownedAthenaeum.ScreenSystem
}
public ScreenState State { get; private set; }
/// <summary>
/// Call this to begin exit transition.

View File

@ -12,6 +12,9 @@ namespace RecrownedAthenaeum.ScreenSystem
/// <param name="screen">The screen to show after the loading screen.</param>
public delegate void ShowFirstScreen(Screen screen);
/// <summary>
/// A manager for screens. Helps with transitions and updating screens as well as resizes.
/// </summary>
public class ScreenManager : IDisposable
{
bool disposed = false;
@ -42,7 +45,7 @@ namespace RecrownedAthenaeum.ScreenSystem
currentScreen = value;
if (!Screen.Initiated)
{
Screen.Initiate(graphics.GraphicsDevice, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), camera);
Screen.Initiate(new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), camera);
}
if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition)
{
@ -163,12 +166,19 @@ namespace RecrownedAthenaeum.ScreenSystem
ShowFirstScreenEvent?.Invoke(screen);
}
/// <summary>
/// Disposes this.
/// </summary>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
/// <summary>
/// An overridable dispose.
/// </summary>
/// <param name="disposing">True of user invoked dispose called.</param>
public virtual void Dispose(bool disposing)
{
if (disposed) return;
@ -178,5 +188,13 @@ namespace RecrownedAthenaeum.ScreenSystem
}
disposing = true;
}
/// <summary>
/// Destructor.
/// </summary>
~ScreenManager()
{
Dispose(false);
}
}
}

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))