Added better exception throwing for missing regions for skins by adding a required option for regions.
This commit is contained in:
parent
59771b00a8
commit
ebe22fa9dc
@ -58,8 +58,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
public Button(ISkin skin, string definitionName = null)
|
public Button(ISkin skin, string definitionName = null)
|
||||||
{
|
{
|
||||||
skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName);
|
skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName);
|
||||||
downTexture = skin.GetTextureAtlasRegion(skinDefinition.downRegion);
|
downTexture = skin.GetTextureAtlasRegion(skinDefinition.downRegion, true);
|
||||||
upTexture = skin.GetTextureAtlasRegion(skinDefinition.upRegion);
|
upTexture = skin.GetTextureAtlasRegion(skinDefinition.upRegion, true);
|
||||||
disabledTexture = skin.GetTextureAtlasRegion(skinDefinition.disabledRegion);
|
disabledTexture = skin.GetTextureAtlasRegion(skinDefinition.disabledRegion);
|
||||||
highlightedTexture = skin.GetTextureAtlasRegion(skinDefinition.selectedRegion);
|
highlightedTexture = skin.GetTextureAtlasRegion(skinDefinition.selectedRegion);
|
||||||
}
|
}
|
||||||
@ -70,8 +70,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
/// <param name="skin">The skin the definition is defined in.</param>
|
/// <param name="skin">The skin the definition is defined in.</param>
|
||||||
/// <param name="skinDefinition">The definition itself.</param>
|
/// <param name="skinDefinition">The definition itself.</param>
|
||||||
public Button(ISkin skin, ButtonSkinDefinition skinDefinition) :
|
public Button(ISkin skin, ButtonSkinDefinition skinDefinition) :
|
||||||
this(skin.GetTextureAtlasRegion(skinDefinition.downRegion),
|
this(skin.GetTextureAtlasRegion(skinDefinition.downRegion, true),
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.upRegion),
|
skin.GetTextureAtlasRegion(skinDefinition.upRegion, true),
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
|
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
|
||||||
{}
|
{}
|
||||||
|
@ -62,8 +62,8 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
|||||||
public TextButton(string text, SpriteFont font, ISkin skin, TextButtonSkinDefinition skinDefinition) :
|
public TextButton(string text, SpriteFont font, ISkin skin, TextButtonSkinDefinition skinDefinition) :
|
||||||
this(text,
|
this(text,
|
||||||
font,
|
font,
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.downRegion),
|
skin.GetTextureAtlasRegion(skinDefinition.downRegion, true),
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.upRegion),
|
skin.GetTextureAtlasRegion(skinDefinition.upRegion, true),
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
||||||
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
|
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
|
||||||
{ }
|
{ }
|
||||||
|
@ -39,8 +39,9 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// Returns a <see cref="TextureAtlas.Region"/> with given name of region.
|
/// Returns a <see cref="TextureAtlas.Region"/> with given name of region.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of region.</param>
|
/// <param name="name">Name of region.</param>
|
||||||
/// <returns>The region corresponding to the name.</returns>
|
/// <param name="required">Whether or not the region is required. If true, it will throw an error if the region does not exist while if false, will return null if the region does not exist.</param>
|
||||||
TextureAtlas.Region GetTextureAtlasRegion(string name);
|
/// <returns>The region corresponding to the name and may return null depending on if the region exists, and is required.</returns>
|
||||||
|
TextureAtlas.Region GetTextureAtlasRegion(string name, bool required = false);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the proper definition for the given parameters or throws exception in the case the requested definition does not exist.
|
/// Returns the proper definition for the given parameters or throws exception in the case the requested definition does not exist.
|
||||||
|
@ -62,7 +62,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TextureAtlas.Region GetTextureAtlasRegion(string name)
|
public TextureAtlas.Region GetTextureAtlasRegion(string name, bool required = false)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
catch (NullReferenceException)
|
||||||
{
|
{
|
||||||
return alternateSkin.GetTextureAtlasRegion(name);
|
return alternateSkin.GetTextureAtlasRegion(name, required);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +47,18 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
/// Returns a <see cref="TextureAtlas.Region"/> with given name of region. Null values acceptable. Will return null if parameter is null.
|
/// Returns a <see cref="TextureAtlas.Region"/> with given name of region. Null values acceptable. Will return null if parameter is null.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Name of region.</param>
|
/// <param name="name">Name of region.</param>
|
||||||
|
/// <param name="required">Whether or not this texture is mandatory for the module to work. If true, will throw error on failing to retrieve.</param>
|
||||||
/// <returns>The region corresponding to the name or null if the requested region doesn't exist.</returns>
|
/// <returns>The region corresponding to the name or null if the requested region doesn't exist.</returns>
|
||||||
public TextureAtlas.Region GetTextureAtlasRegion(string name)
|
public TextureAtlas.Region GetTextureAtlasRegion(string name, bool required = false)
|
||||||
|
{
|
||||||
|
if (!required && (name == null || !textureAtlas.ContainsRegion(name)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
} else
|
||||||
{
|
{
|
||||||
if (name == null || !textureAtlas.ContainsRegion(name)) return null;
|
|
||||||
return textureAtlas[name];
|
return textureAtlas[name];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a <see cref="Color"/> with given name of defined color;
|
/// Returns a <see cref="Color"/> with given name of defined color;
|
||||||
@ -115,7 +121,8 @@ namespace RecrownedAthenaeum.UI.SkinSystem
|
|||||||
{
|
{
|
||||||
moduleTypeOfDefinition.Add(skinDefinition.GetType().FullName, skinDefinition.uiModuleTypeFullName);
|
moduleTypeOfDefinition.Add(skinDefinition.GetType().FullName, skinDefinition.uiModuleTypeFullName);
|
||||||
definitions.Add(skinDefinition.uiModuleTypeFullName, new Dictionary<string, SkinDefinitionData>());
|
definitions.Add(skinDefinition.uiModuleTypeFullName, new Dictionary<string, SkinDefinitionData>());
|
||||||
} else if (definitions[skinDefinition.uiModuleTypeFullName].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[skinDefinition.uiModuleTypeFullName].Add(definitionName, skinDefinition);
|
definitions[skinDefinition.uiModuleTypeFullName].Add(definitionName, skinDefinition);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user