2019-11-24 20:49:53 +00:00
|
|
|
|
using RecrownedAthenaeum.Render;
|
|
|
|
|
using RecrownedAthenaeum.Types;
|
2019-01-28 00:14:10 +00:00
|
|
|
|
using RecrownedAthenaeum.UI.SkinSystem;
|
2019-01-27 23:39:18 +00:00
|
|
|
|
using RecrownedAthenaeum.UI.SkinSystem.Definitions;
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2018-12-04 13:45:09 +00:00
|
|
|
|
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Button that holds a string.
|
|
|
|
|
/// </summary>
|
2018-12-04 13:45:09 +00:00
|
|
|
|
public class TextButton : Button
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-01-27 23:59:55 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The text that is used to display the string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public readonly Text text;
|
2019-01-15 02:00:11 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The color the font should be rendered in.
|
|
|
|
|
/// </summary>
|
2018-12-14 06:43:38 +00:00
|
|
|
|
public Color FontColor { get { return text.color; } set { text.color = value; } }
|
2018-11-30 02:41:06 +00:00
|
|
|
|
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs text button with the positions represented by <see cref="ISpecialDrawable"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">The string representing the text to be displayed.</param>
|
|
|
|
|
/// <param name="font">The font to be used to display the text.</param>
|
|
|
|
|
/// <param name="down">What to draw as button is pushed down.</param>
|
|
|
|
|
/// <param name="up">What to draw as button is not pushed.</param>
|
|
|
|
|
/// <param name="disabled">What to draw as button is disabled.</param>
|
|
|
|
|
/// <param name="selected">What to draw as button is selected.</param>
|
2018-12-14 06:43:38 +00:00
|
|
|
|
public TextButton(string text, SpriteFont font, ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null) : base(down, up, disabled, selected)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
2019-01-27 23:59:55 +00:00
|
|
|
|
this.text = new Text(font, text);
|
|
|
|
|
this.text.autoScale = true;
|
2019-03-08 16:17:37 +00:00
|
|
|
|
this.text.centered = true;
|
2018-12-14 06:43:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructs a text button using a skin and definition.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">The text to display.</param>
|
2019-01-20 07:08:38 +00:00
|
|
|
|
/// <param name="font">The font to be used.</param>
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <param name="skin">The skin to use.</param>
|
|
|
|
|
/// <param name="definitionName">Name of the definition for this type in the skin given.</param>
|
2019-01-29 22:00:13 +00:00
|
|
|
|
public TextButton(string text, SpriteFont font, ISkin skin, string definitionName = null) : base(skin, skin.ObtainDefinition<TextButtonSkinDefinition>(definitionName))
|
2018-12-14 06:43:38 +00:00
|
|
|
|
{
|
2019-01-29 01:43:41 +00:00
|
|
|
|
TextButtonSkinDefinition skinDefinition = skin.ObtainDefinition<TextButtonSkinDefinition>(definitionName);
|
2019-01-20 07:08:38 +00:00
|
|
|
|
this.text = new Text(font, text);
|
2019-03-06 03:42:28 +00:00
|
|
|
|
this.text.autoScale = true;
|
2019-03-08 16:17:37 +00:00
|
|
|
|
this.text.centered = true;
|
2019-01-20 07:08:38 +00:00
|
|
|
|
FontColor = skin.GetColor(skinDefinition.fontColor);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-29 22:00:13 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Creates a text button with a given definition.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="text">The text to be displayed on this button.</param>
|
|
|
|
|
/// <param name="font">The font to use for this button.</param>
|
|
|
|
|
/// <param name="skin">The skin the definition is from.</param>
|
|
|
|
|
/// <param name="skinDefinition">The definition to use.</param>
|
|
|
|
|
public TextButton(string text, SpriteFont font, ISkin skin, TextButtonSkinDefinition skinDefinition) :
|
|
|
|
|
this(text,
|
|
|
|
|
font,
|
2019-03-08 05:43:25 +00:00
|
|
|
|
skin.GetTextureAtlasRegion(skinDefinition.downRegion, true),
|
|
|
|
|
skin.GetTextureAtlasRegion(skinDefinition.upRegion, true),
|
2019-01-29 22:00:13 +00:00
|
|
|
|
skin.GetTextureAtlasRegion(skinDefinition.disabledRegion),
|
|
|
|
|
skin.GetTextureAtlasRegion(skinDefinition.selectedRegion))
|
|
|
|
|
{ }
|
|
|
|
|
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the text button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="gameTime">Snapshot of information about time for game.</param>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public override void Update(GameTime gameTime)
|
|
|
|
|
{
|
2019-04-09 04:58:27 +00:00
|
|
|
|
text.SetPositionAndDimensions(Boundaries);
|
2018-12-14 06:43:38 +00:00
|
|
|
|
text.Update(gameTime);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
base.Update(gameTime);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-15 02:00:11 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Called whenever game wants to render this button.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="batch">Batch to use. Batch should already be started.</param>
|
2019-03-24 00:04:43 +00:00
|
|
|
|
public override void Draw(ConsistentSpriteBatch batch)
|
2018-11-30 02:41:06 +00:00
|
|
|
|
{
|
|
|
|
|
base.Draw(batch);
|
2019-03-06 03:42:28 +00:00
|
|
|
|
text.Draw(batch);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|