implemented skin system to ui modules; progress on functional text button.

This commit is contained in:
2018-12-14 00:43:38 -06:00
parent 4fd37b6675
commit 8ab83b5188
7 changed files with 142 additions and 21 deletions

View File

@@ -9,9 +9,7 @@ namespace RecrownedAthenaeum.UI.Skin.Definitions
{
public class ButtonSkinDefinition : ISkinDefinition
{
public string downRegion;
public string upRegion;
public string disabledRegion;
public string upRegion, downRegion, disabledRegion, selectedRegion;
public Type UIModuleType { get { return typeof(Button); } }
public ButtonSkinDefinition(string downRegion, string upRegion)

View File

@@ -0,0 +1,22 @@
using RecrownedAthenaeum.UI.Modular.Modules.Interactive;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecrownedAthenaeum.UI.Skin.Definitions
{
public class TextButtonSkinDefinition : ButtonSkinDefinition
{
public string fontName;
public string fontColor;
public new Type UIModuleType => typeof(TextButton);
public TextButtonSkinDefinition(string downRegion, string upRegion) : base(downRegion, upRegion)
{
}
}
}

View File

@@ -12,9 +12,9 @@ namespace RecrownedAthenaeum.UI.Skin
{
public class Skin
{
TextureAtlas textureAtlas;
Dictionary<string, Color> colors;
Dictionary<string, SpriteFont> fonts;
public readonly TextureAtlas textureAtlas;
public readonly Dictionary<string, Color> colors;
public readonly Dictionary<string, SpriteFont> fonts;
Dictionary<Type, Dictionary<string, ISkinDefinition>> definitions;
public Skin(TextureAtlas textureAtlas)
@@ -30,14 +30,51 @@ namespace RecrownedAthenaeum.UI.Skin
textureAtlas.Draw(regionName, batch, destination, colors[color], rotation, origin);
}
/// <summary>
/// Returns an <see cref="ISkinDefinition"/> of the given name and type.
/// </summary>
/// <param name="definitionName">Name of definition of the <paramref name="type"/></param>
/// <param name="type">The UIModule the definition defines.</param>
/// <returns>The interface for the definition.</returns>
public ISkinDefinition ObtainDefinition(string definitionName, Type type)
{
if (definitionName == null) definitionName = "default";
if (!definitions.ContainsKey(type) || !definitions[type].ContainsKey(definitionName)) throw new ArgumentException("Could not find skin of type " + type.Name + " with name " + definitionName);
return definitions[type][definitionName];
}
public T ObtainDefinition<T>(string definitionName) where T : ISkinDefinition
/// <summary>
/// Returns the default <see cref="ISkinDefinition"/> of the given parameters.
/// </summary>
/// <param name="type">The type of definition the default should be coming from.</param>
/// <returns>The default definition for the given type.</returns>
public ISkinDefinition ObtainDefinition(Type type)
{
return (T)definitions[typeof(T)][definitionName];
return ObtainDefinition(null, type);
}
/// <summary>
/// Returns the proper definition for the given parameters or throws exception in the case the requested definition does not exist.
/// </summary>
/// <typeparam name="T">Convenience to cast to the needed definition type.</typeparam>
/// <param name="definitionName">The name of the definition.</param>
/// <param name="type">UIModule type the definition defines.</param>
/// <returns>The definition cast to T.</returns>
public T ObtainDefinition<T>(string definitionName, Type type) where T : ISkinDefinition
{
if (definitionName == null) definitionName = "default";
return (T)ObtainDefinition(definitionName, type);
}
/// <summary>
/// Returns the default definition.
/// </summary>
/// <typeparam name="T">Convenience to cast to T.</typeparam>
/// <param name="type">The type of the UIModule to retrieve the default from.</param>
/// <returns>The default definition for the given type.</returns>
public T ObtainDefinition<T>(Type type) where T : ISkinDefinition
{
return ObtainDefinition<T>(null, type);
}
public void AddDefinition(string definitionName, ISkinDefinition skinDefinition)