changes in how skin system works.

This commit is contained in:
Harrison Deng 2019-01-29 16:22:14 -06:00
parent 359f3381bf
commit 32f9ff11fb
10 changed files with 44 additions and 62 deletions

View File

@ -96,14 +96,14 @@ namespace RecrownedAthenaeum.Data
/// <summary>
/// The skin definition data.
/// </summary>
public ISkinDefinitionData skin;
public SkinDefinitionData skin;
/// <summary>
/// Sets values for data.
/// </summary>
/// <param name="name">The name to be referenced by.</param>
/// <param name="skinDefinitionData">The skin data.</param>
public DefinitionData(string name, ISkinDefinitionData skinDefinitionData)
public DefinitionData(string name, SkinDefinitionData skinDefinitionData)
{
this.name = name;
skin = skinDefinitionData;

View File

@ -86,9 +86,8 @@
<Compile Include="UI\Modular\UIModule.cs" />
<Compile Include="UI\Modular\UIModuleGroup.cs" />
<Compile Include="UI\SkinSystem\Definitions\ButtonSkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\ISkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\SkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\TextButtonSkinDefinition.cs" />
<Compile Include="UI\SkinSystem\Definitions\TextSkinDefinition.cs" />
<Compile Include="UI\SkinSystem\ISkin.cs" />
<Compile Include="UI\SkinSystem\Skin.cs" />
<Compile Include="Data\SkinData.cs" />

View File

@ -6,16 +6,13 @@ namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
/// <summary>
/// Definition for a button.
/// </summary>
public class ButtonSkinDefinition : ISkinDefinitionData
public class ButtonSkinDefinition : SkinDefinitionData
{
/// <summary>
/// Names for the regions in the texture atlas respectively.
/// </summary>
public string upRegion, downRegion, disabledRegion, selectedRegion;
///<inheritDoc/>
public Type UIModuleType { get { return typeof(Button); } }
/// <summary>
/// Constructs the definition with minimum requirements.
/// </summary>
@ -23,8 +20,10 @@ namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
/// <param name="upRegion">Name of region specifying the texture shown for when the button is not pressed.</param>
public ButtonSkinDefinition(string downRegion, string upRegion)
{
UIModuleType = typeof(Button);
this.downRegion = downRegion;
this.upRegion = upRegion;
}
}
}

View File

@ -1,15 +0,0 @@
using System;
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
{
/// <summary>
/// A definition containing the data for the skin system. Should be in data transfer object model.
/// </summary>
public interface ISkinDefinitionData
{
/// <summary>
/// The module type this definition is definining.
/// </summary>
Type UIModuleType { get; }
}
}

View File

@ -0,0 +1,20 @@
using System;
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
{
/// <summary>
/// A definition containing the data for the skin system. Needs to follow data transfer object model.
/// </summary>
public class SkinDefinitionData
{
/// <summary>
/// The full name of the UI module this definition defines.
/// </summary>
public string uiModuleTypeFullName;
/// <summary>
/// Sets the module type by setting <see cref="uiModuleTypeFullName"/>.
/// </summary>
public Type UIModuleType { set { uiModuleTypeFullName = value.FullName; } }
}
}

View File

@ -13,11 +13,6 @@ namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
/// </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>
@ -25,7 +20,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
/// <param name="upRegion">The texture region that represents when the button is not pressed.</param>
public TextButtonSkinDefinition(string downRegion, string upRegion) : base(downRegion, upRegion)
{
UIModuleType = typeof(TextButton);
}
}
}

View File

@ -1,16 +0,0 @@
using System;
using static System.Net.Mime.MediaTypeNames;
namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
{
public class TextSkinDefinition : ISkinDefinitionData
{
public string color;
public Type UIModuleType { get { return typeof(Text); } }
public TextSkinDefinition(string color)
{
this.color = color;
}
}
}

View File

@ -47,6 +47,6 @@ namespace RecrownedAthenaeum.UI.SkinSystem
/// <typeparam name="T">Convenience to cast to the needed definition type.</typeparam>
/// <param name="definitionName">The name of the definition. Default is null and will be replaced with "default" for name.</param>
/// <returns>The definition cast to T.</returns>
T ObtainDefinition<T>(string definitionName = null) where T : ISkinDefinitionData;
T ObtainDefinition<T>(string definitionName = null) where T : SkinDefinitionData;
}
}

View File

@ -74,7 +74,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
}
}
public T ObtainDefinition<T>(string definitionName = null) where T : ISkinDefinitionData
public T ObtainDefinition<T>(string definitionName = null) where T : SkinDefinitionData
{
try
{

View File

@ -21,8 +21,8 @@ namespace RecrownedAthenaeum.UI.SkinSystem
private TextureAtlas textureAtlas;
Dictionary<string, Color> colors;
readonly Dictionary<string, Type> moduleTypeOfDefinition;
readonly Dictionary<Type, Dictionary<string, ISkinDefinitionData>> definitions;
readonly Dictionary<string, string> moduleTypeOfDefinition;
readonly Dictionary<string, Dictionary<string, SkinDefinitionData>> definitions;
/// <summary>
/// The texture for the cursor.
@ -39,8 +39,8 @@ namespace RecrownedAthenaeum.UI.SkinSystem
this.textureAtlas = textureAtlas;
this.CursorTexture = cursorTexture;
colors = new Dictionary<string, Color>();
moduleTypeOfDefinition = new Dictionary<string, Type>();
definitions = new Dictionary<Type, Dictionary<string, ISkinDefinitionData>>();
moduleTypeOfDefinition = new Dictionary<string, string>();
definitions = new Dictionary<string, Dictionary<string, SkinDefinitionData>>();
}
/// <summary>
@ -79,14 +79,14 @@ namespace RecrownedAthenaeum.UI.SkinSystem
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
}
private ISkinDefinitionData ObtainDefinition(Type type, string definitionName)
private SkinDefinitionData ObtainDefinition(string typeFullName, string definitionName)
{
if (disposed) throw new ObjectDisposedException(GetType().Name);
if (!Laminated) throw new InvalidOperationException("Skin has yet to be laminated yet.");
if (definitionName == null) definitionName = "default";
if (!definitions.ContainsKey(type)) throw new KeyNotFoundException("Could not find any skin definition defining type \"" + type.FullName + "\"");
if (!definitions[type].ContainsKey(definitionName)) throw new KeyNotFoundException("Could not find skin definition defining type \"" + type.Name + "\" with name \"" + definitionName + "\"");
return definitions[type][definitionName];
if (!definitions.ContainsKey(typeFullName)) throw new KeyNotFoundException("Could not find any skin definition defining type \"" + typeFullName + "\"");
if (!definitions[typeFullName].ContainsKey(definitionName)) throw new KeyNotFoundException("Could not find skin definition defining type \"" + typeFullName + "\" with name \"" + definitionName + "\"");
return definitions[typeFullName][definitionName];
}
/// <summary>
@ -95,7 +95,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
/// <typeparam name="T">Convenience to cast to the needed definition type.</typeparam>
/// <param name="definitionName">The name of the definition.</param>
/// <returns>The definition cast to T.</returns>
public virtual T ObtainDefinition<T>(string definitionName = null) where T : ISkinDefinitionData
public virtual T ObtainDefinition<T>(string definitionName = null) where T : SkinDefinitionData
{
return (T)ObtainDefinition(moduleTypeOfDefinition[typeof(T).FullName], definitionName);
}
@ -105,18 +105,18 @@ namespace RecrownedAthenaeum.UI.SkinSystem
/// </summary>
/// <param name="definitionName">The name of the definition. Default (if left blank) name is "default".</param>
/// <param name="skinDefinition">The definition itself.</param>
public virtual void AddDefinition(ISkinDefinitionData skinDefinition, string definitionName = null)
public virtual void AddDefinition(SkinDefinitionData skinDefinition, string definitionName = null)
{
if (disposed) throw new ObjectDisposedException(GetType().Name);
if (Laminated) throw new InvalidOperationException("This skin has been laminated and cannot be edited.");
if (definitionName == null) definitionName = "default";
if (!definitions.ContainsKey(moduleTypeOfDefinition[skinDefinition.GetType().FullName]))
if (!definitions.ContainsKey(skinDefinition.uiModuleTypeFullName))
{
moduleTypeOfDefinition.Add(skinDefinition.GetType().FullName, skinDefinition.UIModuleType);
definitions.Add(skinDefinition.UIModuleType, new Dictionary<string, ISkinDefinitionData>());
} else if (definitions[moduleTypeOfDefinition[skinDefinition.GetType().FullName]].ContainsKey(definitionName)) throw new ArgumentException("Type of definition with that name already exists!");
moduleTypeOfDefinition.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!");
definitions[moduleTypeOfDefinition[skinDefinition.GetType().FullName]].Add(definitionName, skinDefinition);
definitions[skinDefinition.uiModuleTypeFullName].Add(definitionName, skinDefinition);
}
/// <summary>