began working on skin system.

This commit is contained in:
Harrison Deng 2018-12-11 01:12:34 -06:00
parent f3bfba0045
commit dd768ac751
5 changed files with 125 additions and 1 deletions

View File

@ -73,9 +73,13 @@
<Compile Include="UI\Modular\Modules\Image.cs" /> <Compile Include="UI\Modular\Modules\Image.cs" />
<Compile Include="UI\Modular\Modules\Interactive\Button.cs" /> <Compile Include="UI\Modular\Modules\Interactive\Button.cs" />
<Compile Include="UI\Modular\Modules\Interactive\TextButton.cs" /> <Compile Include="UI\Modular\Modules\Interactive\TextButton.cs" />
<Compile Include="UI\Modular\Modules\TextLabel.cs" /> <Compile Include="UI\Modular\Modules\Text.cs" />
<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\Skin\Definitions\ButtonSkinDefinition.cs" />
<Compile Include="UI\Skin\Definitions\ISkinDefinition.cs" />
<Compile Include="UI\Skin\Definitions\TextSkinDefinition.cs" />
<Compile Include="UI\Skin\Skin.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />

View File

@ -0,0 +1,27 @@
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 ButtonSkinDefinition : ISkinDefinition
{
public string downRegion;
public string upRegion;
public string disabledRegion;
public ButtonSkinDefinition(string downRegion, string upRegion)
{
this.downRegion = downRegion;
this.upRegion = upRegion;
}
public Type UIModuleType()
{
return typeof(Button);
}
}
}

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RecrownedAthenaeum.UI.Skin.Definitions
{
public interface ISkinDefinition
{
Type UIModuleType { get; }
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Net.Mime.MediaTypeNames;
namespace RecrownedAthenaeum.UI.Skin.Definitions
{
class TextSkinDefinition : ISkinDefinition
{
public string font;
public string color;
public TextSkinDefinition(string font, string color)
{
this.font = font;
this.color = color;
}
public Type UIModuleType()
{
return typeof(Text);
}
}
}

View File

@ -0,0 +1,54 @@
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>>();
}
public void Draw(string texture, string color, Rectangle region)
{
}
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.");
}
}
}
}