2018-11-30 02:41:06 +00:00
|
|
|
|
using Microsoft.Xna.Framework;
|
|
|
|
|
using Microsoft.Xna.Framework.Graphics;
|
2019-01-15 23:33:55 +00:00
|
|
|
|
using RecrownedAthenaeum.SpecialTypes;
|
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;
|
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-27 23:39:18 +00:00
|
|
|
|
public TextButton(string text, SpriteFont font, SkinSystem.Skin skin, string definitionName = null) : base(skin, definitionName)
|
2018-12-14 06:43:38 +00:00
|
|
|
|
{
|
|
|
|
|
TextButtonSkinDefinition skinDefinition = skin.ObtainDefinition<TextButtonSkinDefinition>(definitionName, GetType());
|
2019-01-20 07:08:38 +00:00
|
|
|
|
this.text = new Text(font, text);
|
|
|
|
|
FontColor = skin.GetColor(skinDefinition.fontColor);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2018-12-14 06:43:38 +00:00
|
|
|
|
text.bounds = bounds;
|
|
|
|
|
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>
|
2018-11-30 02:41:06 +00:00
|
|
|
|
public override void Draw(SpriteBatch batch)
|
|
|
|
|
{
|
2018-12-14 06:43:38 +00:00
|
|
|
|
text.Draw(batch);
|
2018-11-30 02:41:06 +00:00
|
|
|
|
base.Draw(batch);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|