changes in how skin system works.
This commit is contained in:
parent
359f3381bf
commit
32f9ff11fb
@ -96,14 +96,14 @@ namespace RecrownedAthenaeum.Data
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The skin definition data.
|
/// The skin definition data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ISkinDefinitionData skin;
|
public SkinDefinitionData skin;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets values for data.
|
/// Sets values for data.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">The name to be referenced by.</param>
|
/// <param name="name">The name to be referenced by.</param>
|
||||||
/// <param name="skinDefinitionData">The skin data.</param>
|
/// <param name="skinDefinitionData">The skin data.</param>
|
||||||
public DefinitionData(string name, ISkinDefinitionData skinDefinitionData)
|
public DefinitionData(string name, SkinDefinitionData skinDefinitionData)
|
||||||
{
|
{
|
||||||
this.name = name;
|
this.name = name;
|
||||||
skin = skinDefinitionData;
|
skin = skinDefinitionData;
|
||||||
|
@ -86,9 +86,8 @@
|
|||||||
<Compile Include="UI\Modular\UIModule.cs" />
|
<Compile Include="UI\Modular\UIModule.cs" />
|
||||||
<Compile Include="UI\Modular\UIModuleGroup.cs" />
|
<Compile Include="UI\Modular\UIModuleGroup.cs" />
|
||||||
<Compile Include="UI\SkinSystem\Definitions\ButtonSkinDefinition.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\TextButtonSkinDefinition.cs" />
|
||||||
<Compile Include="UI\SkinSystem\Definitions\TextSkinDefinition.cs" />
|
|
||||||
<Compile Include="UI\SkinSystem\ISkin.cs" />
|
<Compile Include="UI\SkinSystem\ISkin.cs" />
|
||||||
<Compile Include="UI\SkinSystem\Skin.cs" />
|
<Compile Include="UI\SkinSystem\Skin.cs" />
|
||||||
<Compile Include="Data\SkinData.cs" />
|
<Compile Include="Data\SkinData.cs" />
|
||||||
|
@ -6,16 +6,13 @@ namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Definition for a button.
|
/// Definition for a button.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ButtonSkinDefinition : ISkinDefinitionData
|
public class ButtonSkinDefinition : SkinDefinitionData
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Names for the regions in the texture atlas respectively.
|
/// Names for the regions in the texture atlas respectively.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string upRegion, downRegion, disabledRegion, selectedRegion;
|
public string upRegion, downRegion, disabledRegion, selectedRegion;
|
||||||
|
|
||||||
///<inheritDoc/>
|
|
||||||
public Type UIModuleType { get { return typeof(Button); } }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs the definition with minimum requirements.
|
/// Constructs the definition with minimum requirements.
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="upRegion">Name of region specifying the texture shown for when the button is not pressed.</param>
|
||||||
public ButtonSkinDefinition(string downRegion, string upRegion)
|
public ButtonSkinDefinition(string downRegion, string upRegion)
|
||||||
{
|
{
|
||||||
|
UIModuleType = typeof(Button);
|
||||||
this.downRegion = downRegion;
|
this.downRegion = downRegion;
|
||||||
this.upRegion = upRegion;
|
this.upRegion = upRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -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; } }
|
||||||
|
}
|
||||||
|
}
|
@ -13,11 +13,6 @@ namespace RecrownedAthenaeum.UI.SkinSystem.Definitions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string fontColor;
|
public string fontColor;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The type of module that will be using this definition.
|
|
||||||
/// </summary>
|
|
||||||
public new Type UIModuleType => typeof(TextButton);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates this definition with the most minimal requirements.
|
/// Creates this definition with the most minimal requirements.
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="upRegion">The texture region that represents when the button is not pressed.</param>
|
||||||
public TextButtonSkinDefinition(string downRegion, string upRegion) : base(downRegion, upRegion)
|
public TextButtonSkinDefinition(string downRegion, string upRegion) : base(downRegion, upRegion)
|
||||||
{
|
{
|
||||||
|
UIModuleType = typeof(TextButton);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -47,6 +47,6 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// <typeparam name="T">Convenience to cast to the needed definition type.</typeparam>
|
/// <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>
|
/// <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>
|
/// <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;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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
|
try
|
||||||
{
|
{
|
||||||
|
@ -21,8 +21,8 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
private TextureAtlas textureAtlas;
|
private TextureAtlas textureAtlas;
|
||||||
|
|
||||||
Dictionary<string, Color> colors;
|
Dictionary<string, Color> colors;
|
||||||
readonly Dictionary<string, Type> moduleTypeOfDefinition;
|
readonly Dictionary<string, string> moduleTypeOfDefinition;
|
||||||
readonly Dictionary<Type, Dictionary<string, ISkinDefinitionData>> definitions;
|
readonly Dictionary<string, Dictionary<string, SkinDefinitionData>> definitions;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The texture for the cursor.
|
/// The texture for the cursor.
|
||||||
@ -39,8 +39,8 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
this.textureAtlas = textureAtlas;
|
this.textureAtlas = textureAtlas;
|
||||||
this.CursorTexture = cursorTexture;
|
this.CursorTexture = cursorTexture;
|
||||||
colors = new Dictionary<string, Color>();
|
colors = new Dictionary<string, Color>();
|
||||||
moduleTypeOfDefinition = new Dictionary<string, Type>();
|
moduleTypeOfDefinition = new Dictionary<string, string>();
|
||||||
definitions = new Dictionary<Type, Dictionary<string, ISkinDefinitionData>>();
|
definitions = new Dictionary<string, Dictionary<string, SkinDefinitionData>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -79,14 +79,14 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
|
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 (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
if (!Laminated) throw new InvalidOperationException("Skin has yet to be laminated yet.");
|
if (!Laminated) throw new InvalidOperationException("Skin has yet to be laminated yet.");
|
||||||
if (definitionName == null) definitionName = "default";
|
if (definitionName == null) definitionName = "default";
|
||||||
if (!definitions.ContainsKey(type)) throw new KeyNotFoundException("Could not find any skin definition defining type \"" + type.FullName + "\"");
|
if (!definitions.ContainsKey(typeFullName)) throw new KeyNotFoundException("Could not find any skin definition defining type \"" + typeFullName + "\"");
|
||||||
if (!definitions[type].ContainsKey(definitionName)) throw new KeyNotFoundException("Could not find skin definition defining type \"" + type.Name + "\" with name \"" + definitionName + "\"");
|
if (!definitions[typeFullName].ContainsKey(definitionName)) throw new KeyNotFoundException("Could not find skin definition defining type \"" + typeFullName + "\" with name \"" + definitionName + "\"");
|
||||||
return definitions[type][definitionName];
|
return definitions[typeFullName][definitionName];
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -95,7 +95,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// <typeparam name="T">Convenience to cast to the needed definition type.</typeparam>
|
/// <typeparam name="T">Convenience to cast to the needed definition type.</typeparam>
|
||||||
/// <param name="definitionName">The name of the definition.</param>
|
/// <param name="definitionName">The name of the definition.</param>
|
||||||
/// <returns>The definition cast to T.</returns>
|
/// <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);
|
return (T)ObtainDefinition(moduleTypeOfDefinition[typeof(T).FullName], definitionName);
|
||||||
}
|
}
|
||||||
@ -105,18 +105,18 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="definitionName">The name of the definition. Default (if left blank) name is "default".</param>
|
/// <param name="definitionName">The name of the definition. Default (if left blank) name is "default".</param>
|
||||||
/// <param name="skinDefinition">The definition itself.</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 (disposed) throw new ObjectDisposedException(GetType().Name);
|
||||||
if (Laminated) throw new InvalidOperationException("This skin has been laminated and cannot be edited.");
|
if (Laminated) throw new InvalidOperationException("This skin has been laminated and cannot be edited.");
|
||||||
if (definitionName == null) definitionName = "default";
|
if (definitionName == null) definitionName = "default";
|
||||||
if (!definitions.ContainsKey(moduleTypeOfDefinition[skinDefinition.GetType().FullName]))
|
if (!definitions.ContainsKey(skinDefinition.uiModuleTypeFullName))
|
||||||
{
|
{
|
||||||
moduleTypeOfDefinition.Add(skinDefinition.GetType().FullName, skinDefinition.UIModuleType);
|
moduleTypeOfDefinition.Add(skinDefinition.GetType().FullName, skinDefinition.uiModuleTypeFullName);
|
||||||
definitions.Add(skinDefinition.UIModuleType, new Dictionary<string, ISkinDefinitionData>());
|
definitions.Add(skinDefinition.uiModuleTypeFullName, new Dictionary<string, SkinDefinitionData>());
|
||||||
} else if (definitions[moduleTypeOfDefinition[skinDefinition.GetType().FullName]].ContainsKey(definitionName)) throw new ArgumentException("Type of definition with that name already exists!");
|
} 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>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user