using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using RecrownedAthenaeum.DataTypes;
using RecrownedAthenaeum.UI.Skin.Definitions;
using System;
using System.Collections.Generic;
namespace RecrownedAthenaeum.UI.Skin
{
///
/// A skin is used to group a theme which can then be applied to the UI via the use of modules.
///
public class Skin
{
///
/// Texture atlas containing the skins textures.
///
public readonly TextureAtlas textureAtlas;
///
/// Colors stored in this skin.
///
public readonly Dictionary colors;
///
/// Fonts stored in this skin.
///
public readonly Dictionary fonts;
Dictionary> definitions;
///
/// Creates a basic unfilled skin.
///
/// The texture atlas to use for this skin.
public Skin(TextureAtlas textureAtlas)
{
this.textureAtlas = textureAtlas;
colors = new Dictionary();
fonts = new Dictionary();
definitions = new Dictionary>();
}
///
/// Draws a region from the texture atlas.
///
/// Region to draw.
/// The color to tint the region.
/// The batch to use.
/// The destination to draw to.
/// The rotation to use in radians.
/// The origin for the rotation.
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);
}
///
/// Returns an of the given name and type.
///
/// Name of definition of the
/// The UIModule the definition defines.
/// The interface for the definition.
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];
}
///
/// Returns the default of the given parameters.
///
/// The type of definition the default should be coming from.
/// The default definition for the given type.
public ISkinDefinition ObtainDefinition(Type type)
{
return ObtainDefinition(null, type);
}
///
/// Returns the proper definition for the given parameters or throws exception in the case the requested definition does not exist.
///
/// Convenience to cast to the needed definition type.
/// The name of the definition.
/// UIModule type the definition defines.
/// The definition cast to T.
public T ObtainDefinition(string definitionName, Type type) where T : ISkinDefinition
{
if (definitionName == null) definitionName = "default";
return (T)ObtainDefinition(definitionName, type);
}
///
/// Returns the default definition.
///
/// Convenience to cast to T.
/// The type of the UIModule to retrieve the default from.
/// The default definition for the given type.
public T ObtainDefinition(Type type) where T : ISkinDefinition
{
return ObtainDefinition(null, type);
}
///
/// Adds the definition.
///
/// The name of the definition.
/// The definition itself.
public void AddDefinition(string definitionName, ISkinDefinition skinDefinition)
{
if (!definitions.ContainsKey(skinDefinition.UIModuleType))
{
definitions.Add(skinDefinition.UIModuleType, new Dictionary());
} else if (definitions[skinDefinition.UIModuleType].ContainsKey(definitionName)) throw new ArgumentException("Type of definition with that name already exists!");
definitions[skinDefinition.UIModuleType].Add(definitionName, skinDefinition);
}
///
/// Removes the definition.
///
/// The name of the definition.
/// The type of the definition.
public void RemoveDefinition(string definitionName, Type definitionType)
{
if (definitions.ContainsKey(definitionType) && definitions[definitionType].ContainsKey(definitionName))
{
definitions[definitionType].Remove(definitionName);
} else
{
throw new ArgumentException("a definition of type " + definitionType.Name + " with a name of " + definitionName + " does not exist.");
}
}
}
}