2018-12-11 07:12:34 +00:00
using Microsoft.Xna.Framework ;
using Microsoft.Xna.Framework.Graphics ;
using RecrownedAthenaeum.DataTypes ;
using RecrownedAthenaeum.UI.Skin.Definitions ;
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
namespace RecrownedAthenaeum.UI.Skin
{
public class Skin
{
TextureAtlas textureAtlas ;
Dictionary < string , Color > colors ;
Dictionary < string , SpriteFont > fonts ;
Dictionary < Type , Dictionary < string , ISkinDefinition > > definitions ;
public Skin ( TextureAtlas textureAtlas )
{
this . textureAtlas = textureAtlas ;
colors = new Dictionary < string , Color > ( ) ;
fonts = new Dictionary < string , SpriteFont > ( ) ;
definitions = new Dictionary < Type , Dictionary < string , ISkinDefinition > > ( ) ;
}
2018-12-12 02:03:35 +00:00
public void Draw ( string regionName , string color , SpriteBatch batch , Rectangle destination , Type type , float rotation = 0 , Vector2 origin = default ( Vector2 ) )
2018-12-11 07:12:34 +00:00
{
2018-12-12 02:03:35 +00:00
textureAtlas . Draw ( regionName , batch , destination , colors [ color ] , rotation , origin ) ;
}
public ISkinDefinition ObtainDefinition ( string definitionName , Type type )
{
return definitions [ type ] [ definitionName ] ;
}
public T ObtainDefinition < T > ( string definitionName ) where T : ISkinDefinition
{
return ( T ) definitions [ typeof ( T ) ] [ definitionName ] ;
2018-12-11 07:12:34 +00:00
}
public void AddDefinition ( string definitionName , ISkinDefinition skinDefinition )
{
if ( ! definitions . ContainsKey ( skinDefinition . UIModuleType ) )
{
definitions . Add ( skinDefinition . UIModuleType , new Dictionary < string , ISkinDefinition > ( ) ) ;
} else if ( definitions [ skinDefinition . UIModuleType ] . ContainsKey ( definitionName ) ) throw new ArgumentException ( "Type of definition with that name already exists!" ) ;
definitions [ skinDefinition . UIModuleType ] . Add ( definitionName , skinDefinition ) ;
}
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." ) ;
}
}
}
}