Many refactors and minor changes. idk.

This commit is contained in:
Harrison Deng 2019-04-08 23:58:27 -05:00
parent 4d4d46ad1b
commit 3e5b838abe
13 changed files with 465 additions and 60 deletions

View File

@ -85,11 +85,13 @@
<Compile Include="UI\Modular\Modules\Interactive\Button.cs" />
<Compile Include="UI\Modular\Modules\Interactive\TextButton.cs" />
<Compile Include="UI\Modular\Modules\Text.cs" />
<Compile Include="UI\Modular\Modules\UIScrollable.cs" />
<Compile Include="UI\Modular\UIModule.cs" />
<Compile Include="UI\Modular\UIModuleGroup.cs" />
<Compile Include="UI\SkinSystem\Definitions\ButtonSkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\SkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\TextButtonSkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\UIScrollableSkinDefinition.cs" />
<Compile Include="UI\SkinSystem\ISkin.cs" />
<Compile Include="UI\SkinSystem\Skin.cs" />
<Compile Include="Data\SkinData.cs" />

View File

@ -39,13 +39,8 @@ namespace RecrownedAthenaeum.SpecialTypes
this.bottom = bottom;
this.top = top;
sourcePatches = GenerateSourcesPatches();
}
private Rectangle[] GenerateSourcesPatches()
{
Rectangle[] patches =
{
{
new Rectangle(0, 0, left, bottom),
new Rectangle(left, 0, textureRegion.Width - left - right, bottom),
new Rectangle(textureRegion.Width - right, 0, right, bottom),
@ -62,7 +57,9 @@ namespace RecrownedAthenaeum.SpecialTypes
patches[i].X += textureRegion.X;
patches[i].Y += textureRegion.Y;
}
return patches;
sourcePatches = patches;
}
private Rectangle[] GenenerateDestinationRectangles(int width, int height)
@ -122,7 +119,11 @@ namespace RecrownedAthenaeum.SpecialTypes
public void Draw(ConsistentSpriteBatch spriteBatch, Rectangle destination, Color color, float rotation = 0, Vector2 origin = default(Vector2))
{
if (rotation != 0) throw new NotImplementedException("Ninepatches can't be rotated.");
if (origin != default(Vector2)) throw new NotImplementedException("Ninepatches can't have origin changed (hint: use the destination rectangle to shift and position).");
if (origin != default(Vector2))
{
destination.X -= (int)origin.X;
destination.Y -= (int)origin.Y;
}
Draw(spriteBatch, color, destination);
}
}

View File

@ -97,7 +97,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
if (targetPage != null)
{
Vector2 position;
Rectangle targetBounds = targetPage.situation;
Rectangle targetBounds = targetPage.Boundaries;
position.X = targetBounds.X + (targetBounds.Width * 0.5f);
position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
camera.LinearInterpolationToPosition(0.4f, position, (float)gameTime.ElapsedGameTime.TotalSeconds);
@ -173,7 +173,7 @@ namespace RecrownedAthenaeum.UI.BookSystem
/// <param name="page">Page to go to.</param>
public void GoToPage(Page page)
{
Rectangle targetBounds = page.situation;
Rectangle targetBounds = page.Boundaries;
camera.position.X = targetBounds.X + (targetBounds.Width * 0.5f);
camera.position.Y = targetBounds.Y + (targetBounds.Height * 0.5f);
}

View File

@ -36,10 +36,10 @@ namespace RecrownedAthenaeum.UI.BookSystem
/// <param name="height">New Height</param>
public virtual void ApplySize(int width, int height)
{
situation.X = pageX * width;
situation.Y = pageY * height;
situation.Width = width;
situation.Height = height;
X = pageX * width;
Y = pageY * height;
Width = width;
Height = height;
requiresSizeUpdate = false;
}

View File

@ -24,12 +24,12 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
/// <summary>
/// Scale of of the X axis.
/// </summary>
public float ScaleX { get { return (float)situation.Width / texture.Width; } set { situation.Width = (int)(texture.Width * value); } }
public float ScaleX { get { return (float)Width / texture.Width; } set { Width = (int)(texture.Width * value); } }
/// <summary>
/// Scale of the Y axis.
/// </summary>
public float ScaleY { get { return (float)situation.Height / texture.Height; } set { situation.Height = (int)(texture.Height * value); } }
public float ScaleY { get { return (float)Height / texture.Height; } set { Height = (int)(texture.Height * value); } }
/// <summary>
/// Sets scale of X and Y.
@ -43,7 +43,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
public Image(Texture2D texture)
{
this.texture = texture ?? throw new ArgumentException("Image requires a texture.");
situation = texture.Bounds;
SetPositionAndDimensions(texture.Bounds);
}
/// <summary>
@ -52,7 +52,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
/// <param name="batch">The batch to use.</param>
public override void Draw(ConsistentSpriteBatch batch)
{
batch.Draw(texture, situation, null, color, rotation, origin, SpriteEffects.None, 0f);
batch.Draw(texture, new Rectangle(X, Y, Width, Height), null, color, rotation, origin, SpriteEffects.None, 0f);
base.Draw(batch);
}
@ -69,8 +69,17 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
this.color = color;
this.rotation = rotation;
this.origin = origin;
situation = destination;
SetPositionAndDimensions(destination);
Draw(spriteBatch);
}
/// <summary>
/// Center's the origin to the middle of the dimensions of the texture.
/// </summary>
public override void CenterOrigin()
{
origin.X = texture.Bounds.Width / 2f;
origin.Y = texture.Bounds.Height / 2f;
}
}
}

View File

@ -76,7 +76,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
/// <param name="gameTime">Snapshot of information about time for game.</param>
public override void Update(GameTime gameTime)
{
text.situation = Boundaries;
text.SetPositionAndDimensions(Boundaries);
text.Update(gameTime);
base.Update(gameTime);
}

View File

@ -66,8 +66,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
/// <param name="gameTime">The game time.</param>
public override void Update(GameTime gameTime)
{
position.X = situation.X;
position.Y = situation.Y;
position.X = X;
position.Y = Y;
if (useEllipses) AttemptToApplyEllipsis();
if (autoWrap) AttemptToWrapText();
@ -92,7 +92,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
/// </summary>
public void AttemptToApplyEllipsis()
{
if (modifiedTextSize.X * scale > situation.Width && ModifiedText.Length > ellipsis.Length + 1)
if (modifiedTextSize.X * scale > Width && ModifiedText.Length > ellipsis.Length + 1)
{
RemoveLineBreaks();
StringBuilder stringBuilder = new StringBuilder(ModifiedText);
@ -101,7 +101,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
stringBuilder.Remove(stringBuilder.Length, ellipsis.Length - 1);
stringBuilder.Insert(stringBuilder.Length, ellipsis);
}
while (font.MeasureString(stringBuilder).X * scale > situation.Width);
while (font.MeasureString(stringBuilder).X * scale > Width);
ModifiedText = stringBuilder.ToString();
}
@ -113,18 +113,18 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
public void AttemptToScaleFont()
{
if (situation.Width < situation.Height)
if (Width < Height)
{
if (Math.Round(modifiedTextSize.X * scale ) != situation.Width)
if (Math.Round(modifiedTextSize.X * scale ) != Width)
{
scale = situation.Width / modifiedTextSize.X;
scale = Width / modifiedTextSize.X;
}
}
else
{
if (Math.Round(modifiedTextSize.Y * scale ) != situation.Height)
if (Math.Round(modifiedTextSize.Y * scale ) != Height)
{
scale = situation.Height / (modifiedTextSize.Y);
scale = Height / (modifiedTextSize.Y);
}
}
}
@ -152,7 +152,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
public void AttemptToWrapText(bool unwrap = false)
{
if (unwrap) RemoveLineBreaks();
if (modifiedTextSize.X * scale > situation.Width)
if (modifiedTextSize.X * scale > Width)
{
ModifiedText = ModifiedText.Replace("\n", " ");
string[] words = ModifiedText.Split(' ');
@ -164,7 +164,7 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
string word = words[w];
float scaledWidth = font.MeasureString(word).X * scale;
if (currentScaledLineWidth + scaledWidth <= situation.Width)
if (currentScaledLineWidth + scaledWidth <= Width)
{
stringBuilder.Append(word);
currentScaledLineWidth += scaledWidth;
@ -183,18 +183,18 @@ namespace RecrownedAthenaeum.UI.Modular.Modules
{
Vector2 textSize = new Vector2(modifiedTextSize.X * scale, modifiedTextSize.Y * scale);
if (textSize.X <= situation.Width)
if (textSize.X <= Width)
{
position.X = situation.X + (situation.Width - textSize.X) / 2f;
position.X = X + (Width - textSize.X) / 2f;
}
else
{
return false;
}
if (textSize.Y <= situation.Height)
if (textSize.Y <= Height)
{
position.Y = situation.Y + (situation.Height - textSize.Y) / 2f;
position.Y = Y + (Height - textSize.Y) / 2f;
}
else
{

View File

@ -0,0 +1,319 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using RecrownedAthenaeum.Input;
using RecrownedAthenaeum.Render;
using RecrownedAthenaeum.SpecialTypes;
using RecrownedAthenaeum.UI.SkinSystem;
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecrownedAthenaeum.UI.Modular.Modules
{
public class UIScrollable : UIModule
{
UIModuleGroup group;
float opacityOfBar;
bool showingBars;
int shiftX, shiftY;
int furthestX;
int furthestY;
UIModule furthestXMod, furthestYMod;
bool horScrollAvailable, vertScrollAvailable;
Rectangle horizontalScrollBarBounds, verticalScrollBarBounds;
/// <summary>
/// How fast the bars fade away in opacity (0 to 254) per second.
/// </summary>
public float barFadeSpeed;
ISpecialDrawable horizontalScrollBar, verticalScrollBar;
ISpecialDrawable background, horizontalBarTrack, verticalBarTrack;
private int topPadding, bottomPadding, leftPadding, rightPadding;
public int PadTop { get { return topPadding; } set { topPadding = value; HeightOrYChange(); } }
public int PadBottom { get { return bottomPadding; } set { bottomPadding = value; HeightOrYChange(); } }
public int PadLeft { get { return leftPadding; } set { leftPadding = value; WidthOrXChange(); } }
public int PadRight { get { return rightPadding; } set { rightPadding = value; WidthOrXChange(); } }
/// <summary>
/// The minimum bar length for the scroll bar.
/// </summary>
public int minimumBarLength = 16;
/// <summary>
/// The thickness of the scroll bars.
/// </summary>
int horizontalBarThickness, verticalBarThickness;
public int HorizontalBarThickness { get { return horizontalBarThickness; } set { horizontalBarThickness = value; HeightOrYChange(); } }
public int VerticalBarThickness { get { return verticalBarThickness; } set { verticalBarThickness = value; WidthOrXChange(); } }
/// <summary>
/// Whether or not to hide scroll bars.
/// </summary>
public bool HideScrollBars
{
get { return hideScrollBars; }
set
{
hideScrollBars = value;
WidthOrXChange();
HeightOrYChange();
}
}
bool hideScrollBars = true;
/// <summary>
/// Set to true to change from the normal position to the new position.
/// </summary>
public bool verticalBarLeftPosition, horizontalBarTopPosition;
public override int Width
{
get
{
return base.Width;
}
set
{
base.Width = value;
WidthOrXChange();
}
}
public override int Height
{
get
{
return base.Height;
}
set
{
base.Height = value;
HeightOrYChange();
}
}
public override int X
{
get
{
return base.X;
}
set
{
WidthOrXChange(true);
base.X = value;
}
}
public override int Y
{
get
{
return base.Y;
}
set
{
HeightOrYChange(true);
base.Y = value;
}
}
public UIScrollable(ISpecialDrawable horizontalScrollBar, ISpecialDrawable verticalScrollBar, ISpecialDrawable horizontalBarTrack = null, ISpecialDrawable verticalBarTrack = null, ISpecialDrawable background = null)
{
this.horizontalScrollBar = horizontalScrollBar;
this.verticalScrollBar = verticalScrollBar;
this.horizontalBarTrack = horizontalBarTrack;
this.verticalBarTrack = verticalBarTrack;
this.background = background;
group = new UIModuleGroup(new BasicScissor());
}
public UIScrollable(ISkin skin, string definition) :
this(skin.GetTextureAtlasRegion(skin.ObtainDefinition<UIScrollableSkinDefinition>().horizontalBar, true),
skin.GetTextureAtlasRegion(skin.ObtainDefinition<UIScrollableSkinDefinition>().verticalBar, true),
skin.GetTextureAtlasRegion(skin.ObtainDefinition<UIScrollableSkinDefinition>().horizontalBarTrack),
skin.GetTextureAtlasRegion(skin.ObtainDefinition<UIScrollableSkinDefinition>().verticalBarTrack),
skin.GetTextureAtlasRegion(skin.ObtainDefinition<UIScrollableSkinDefinition>().background))
{
}
public override void Update(GameTime gameTime)
{
if (hideScrollBars)
{
if (!showingBars)
{
if (opacityOfBar <= 0)
{
opacityOfBar -= (barFadeSpeed / 255f) * gameTime.ElapsedGameTime.Seconds;
}
}
else
{
opacityOfBar = 1f;
}
}
if (horScrollAvailable)
{
horizontalScrollBarBounds.X = (int)(((float)-shiftX / furthestX) * (group.Width - horizontalScrollBarBounds.Width));
}
if (vertScrollAvailable)
{
verticalScrollBarBounds.Y = (int)(((float)-shiftY / furthestY) * (group.Height - verticalScrollBarBounds.Height));
}
base.Update(gameTime);
}
public override void Draw(ConsistentSpriteBatch spriteBatch)
{
background.Draw(spriteBatch, Boundaries, color, origin: origin);
if (horScrollAvailable)
{
horizontalScrollBar.Draw(spriteBatch, horizontalScrollBarBounds, color);
}
if (vertScrollAvailable)
{
horizontalScrollBar.Draw(spriteBatch, verticalScrollBarBounds, color);
}
base.Draw(spriteBatch);
}
public void AddModules(params UIModule[] addModules)
{
group.AddModules(addModules);
for (int i = 0; i < addModules.Length; i++)
{
UIModule m = addModules[i];
int mFurthestX = m.Boundaries.X + m.Boundaries.Width;
int mFurthestY = m.Boundaries.Y + m.Boundaries.Height;
if (mFurthestX > furthestX)
{
furthestXMod = m;
furthestX = mFurthestX;
}
if (mFurthestY > furthestY)
{
furthestYMod = m;
furthestY = mFurthestY;
}
}
}
public void RemoveModule(UIModule module)
{
group.RemoveModule(module);
if (module == furthestXMod)
{
furthestX = 0;
UIModule[] modules = group.GetCopyOfModules();
for (int i = 0; i < modules.Length; i++)
{
UIModule m = modules[i];
int mFurthestX = m.Boundaries.X + m.Boundaries.Width;
if (mFurthestX > furthestX)
{
furthestXMod = m;
furthestX = mFurthestX;
}
}
}
if (module == furthestYMod)
{
furthestY = 0;
UIModule[] modules = group.GetCopyOfModules();
for (int i = 0; i < modules.Length; i++)
{
UIModule m = modules[i];
int mFurthestY = m.Boundaries.Y + m.Boundaries.Height;
if (mFurthestY > furthestY)
{
furthestYMod = m;
furthestY = mFurthestY;
}
}
}
}
private void WidthOrXChange(bool onlyXChange = false)
{
group.X = X + leftPadding;
if (!onlyXChange)
{
group.Width = Width - rightPadding - leftPadding;
if (Width < furthestX)
{
horScrollAvailable = true;
horizontalScrollBarBounds.Width = (int)(Width * ((float)Width / furthestX));
horizontalScrollBarBounds.Width = Math.Max(horizontalScrollBarBounds.Width, minimumBarLength);
}
else { horScrollAvailable = false; }
if (!hideScrollBars)
{
if (verticalBarLeftPosition)
{
group.X += verticalBarThickness;
group.Width -= verticalBarThickness;
}
group.Height -= verticalBarThickness;
}
}
}
private void HeightOrYChange(bool onlyYChange = false)
{
group.Y = Y + bottomPadding;
if (!onlyYChange)
{
group.Height = Height - bottomPadding - topPadding;
if (Height < furthestY)
{
horScrollAvailable = true;
verticalScrollBarBounds.Height = (int)(Height * ((float)Height / furthestY));
verticalScrollBarBounds.Height = Math.Max(verticalScrollBarBounds.Height, minimumBarLength);
}
else { vertScrollAvailable = false; }
if (!hideScrollBars)
{
if (!horizontalBarTopPosition)
{
group.Y += horizontalBarThickness;
group.Height -= horizontalBarThickness;
}
group.Height -= horizontalBarThickness;
}
}
}
public override bool MouseStateChanged(MouseState state)
{
if (InputUtilities.MouseWithinBoundries(Boundaries))
{
showingBars = true;
}
else
{
showingBars = false;
}
return base.MouseStateChanged(state);
}
}
}

View File

@ -10,12 +10,27 @@ namespace RecrownedAthenaeum.UI.Modular
/// <summary>
/// Module for UI layout.
/// </summary>
public class UIModule : IInputListener
public abstract class UIModule : IInputListener
{
/// <summary>
/// The bounds before factoring in the origin.
/// The width of the module.
/// </summary>
public Rectangle situation;
public virtual int Width { get; set; }
/// <summary>
/// The height of the module.
/// </summary>
public virtual int Height { get; set; }
/// <summary>
/// The X position of the module.
/// </summary>
public virtual int X { get; set; }
/// <summary>
/// The Y position of the module.
/// </summary>
public virtual int Y { get; set; }
/// <summary>
/// Bounds of this module (after factoring in the origin).
@ -24,7 +39,7 @@ namespace RecrownedAthenaeum.UI.Modular
{
get
{
return new Rectangle((int)(situation.X - origin.X), (int)(situation.Y - origin.Y), situation.Width, situation.Height);
return new Rectangle((int)(X - origin.X), (int)(Y - origin.Y), Width, Height);
}
}
@ -115,16 +130,16 @@ namespace RecrownedAthenaeum.UI.Modular
}
/// <summary>
/// Sets the origin to be the center of the bounds.
/// Sets the origin to be the center using the <see cref="Width"/> and <see cref="Height"/>.
/// </summary>
public void CenterOrigin()
public virtual void CenterOrigin()
{
origin.X = situation.Width / 2f;
origin.Y = situation.Height / 2f;
origin.X = Width / 2f;
origin.Y = Height / 2f;
}
/// <summary>
/// Centers this module's origin on the horizontal axis relative to the parent <see cref="UIModuleGroup"/>.
/// Centers this module's on the horizontal axis relative to the parent <see cref="UIModuleGroup"/>.
/// </summary>
/// <returns>True if possible and false if not.</returns>
public bool CenterHorizontally()
@ -134,7 +149,7 @@ namespace RecrownedAthenaeum.UI.Modular
Rectangle rectangle = parent.Boundaries;
if (parent != null && rectangle.Width >= Boundaries.Width)
{
situation.X = rectangle.Width / 2 + situation.X;
X = rectangle.Width / 2 + X;
return true;
}
}
@ -145,18 +160,30 @@ namespace RecrownedAthenaeum.UI.Modular
/// Centers this module's origin on the vertical axis relative to the parent <see cref="UIModuleGroup"/>.
/// </summary>
/// <returns>True if possible.</returns>
public bool CenterVertically()
public virtual bool CenterVertically()
{
if (parent != null)
{
Rectangle rectangle = parent.Boundaries;
if (rectangle.Height >= Boundaries.Height)
{
situation.Y = rectangle.Height / 2 + situation.Y;
Y = rectangle.Height / 2 + Y;
return true;
}
}
return false;
}
/// <summary>
/// Sets the position and dimension of this module.
/// </summary>
/// <param name="rectangle">The rectangle that represents the position and dimensions of the module.</param>
public virtual void SetPositionAndDimensions(Rectangle rectangle)
{
X = rectangle.X;
Y = rectangle.Y;
Width = rectangle.Width;
Height = rectangle.Height;
}
}
}

View File

@ -19,6 +19,15 @@ namespace RecrownedAthenaeum.UI.Modular
/// </summary>
public BasicScissor basicScissor;
/// <summary>
/// Instantiates the UI module group.
/// </summary>
/// <param name="basicScissor">Sets the <see cref="basicScissor"/> field.</param>
public UIModuleGroup(BasicScissor basicScissor = null)
{
this.basicScissor = basicScissor;
}
/// <summary>
/// Draws this group of modules. If scissoring, will use the matrix and effect designated in the <see cref="BasicScissor"/> to begin the batch normally again.
/// </summary>
@ -33,13 +42,13 @@ namespace RecrownedAthenaeum.UI.Modular
foreach (UIModule module in modules)
{
int offsetX = module.situation.X;
int offsetY = module.situation.Y;
module.situation.X = situation.X + offsetX;
module.situation.Y = situation.Y + offsetY;
int offsetX = module.X;
int offsetY = module.Y;
module.X = X + offsetX;
module.Y = Y + offsetY;
module.Draw(spriteBatch);
module.situation.X = offsetX;
module.situation.Y = offsetY;
module.X = offsetX;
module.Y = offsetY;
}
if (basicScissor != null)
@ -65,7 +74,7 @@ namespace RecrownedAthenaeum.UI.Modular
/// Adds module(s) to this group.
/// </summary>
/// <param name="addModules">The module(s) to add.</param>
public void AddModule(params UIModule[] addModules)
public virtual void AddModules(params UIModule[] addModules)
{
foreach (UIModule module in addModules)
{
@ -82,11 +91,19 @@ namespace RecrownedAthenaeum.UI.Modular
/// Removes given module from group.
/// </summary>
/// <param name="module">module to remove.</param>
public void RemoveModule(UIModule module)
public virtual void RemoveModule(UIModule module)
{
module.parent = null;
modules.Remove(module);
}
/// <summary>
/// Obtains an array snapshot of all the modules.
/// </summary>
public UIModule[] GetCopyOfModules()
{
return modules.ToArray();
}
/// <summary>
/// Updates the keyboard state of the modules in this group.

View File

@ -3,7 +3,7 @@
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
{
/// <summary>
/// Definition for a button.
/// Skin definition for a button.
/// </summary>
public class ButtonSkinDefinition : SkinDefinitionData
{

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
{
/// <summary>
/// Skin definition of a scroll module.
/// </summary>
public class UIScrollableSkinDefinition : SkinDefinitionData
{
/// <summary>
/// Name of the region that specifies the texture needed.
/// </summary>
public string horizontalBar, verticalBar, horizontalBarTrack, verticalBarTrack, background;
/// <summary>
/// Instantiates the definition with the minimum requirements.
/// </summary>
/// <param name="horizontalBar">Name of the region used by the skin that defines what the horizontal scroll bar looks like.</param>
/// <param name="verticalBar">Name of the region used by the skin that defines what the vertical scroll bar looks like.</param>
public UIScrollableSkinDefinition(string horizontalBar, string verticalBar)
{
this.horizontalBar = horizontalBar;
this.verticalBar = verticalBar;
}
}
}

View File

@ -22,7 +22,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
private TextureAtlas textureAtlas;
Dictionary<string, Color> colors;
readonly Dictionary<string, string> moduleTypeOfDefinition;
readonly Dictionary<string, string> definitionOfType;
readonly Dictionary<string, Dictionary<string, SkinDefinitionData>> definitions;
/// <summary>
@ -40,7 +40,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
this.textureAtlas = textureAtlas;
this.CursorTexture = cursorTexture;
colors = new Dictionary<string, Color>();
moduleTypeOfDefinition = new Dictionary<string, string>();
definitionOfType = new Dictionary<string, string>();
definitions = new Dictionary<string, Dictionary<string, SkinDefinitionData>>();
}
@ -105,7 +105,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
/// <returns>The definition cast to T.</returns>
public T ObtainDefinition<T>(string definitionName = null) where T : SkinDefinitionData
{
return (T)ObtainDefinition(moduleTypeOfDefinition[typeof(T).FullName], definitionName);
return (T)ObtainDefinition(definitionOfType[typeof(T).FullName], definitionName);
}
/// <summary>
@ -120,7 +120,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
if (definitionName == null) definitionName = "default";
if (!definitions.ContainsKey(skinDefinition.uiModuleTypeFullName))
{
moduleTypeOfDefinition.Add(skinDefinition.GetType().FullName, skinDefinition.uiModuleTypeFullName);
definitionOfType.Add(skinDefinition.GetType().FullName, skinDefinition.uiModuleTypeFullName);
definitions.Add(skinDefinition.uiModuleTypeFullName, new Dictionary<string, SkinDefinitionData>());
}
else if (definitions[skinDefinition.uiModuleTypeFullName].ContainsKey(definitionName)) throw new ArgumentException("Type of definition with that name already exists!");