documentation.
This commit is contained in:
@@ -6,17 +6,40 @@ using RecrownedAthenaeum.UI.Skin.Definitions;
|
||||
|
||||
namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
{
|
||||
public delegate bool Clicked();
|
||||
/// <summary>
|
||||
/// Function to be called when button is clicked.
|
||||
/// </summary>
|
||||
public delegate void Clicked();
|
||||
|
||||
/// <summary>
|
||||
/// A very primitive button containing all the basic functions.
|
||||
/// </summary>
|
||||
public class Button : UIModule
|
||||
{
|
||||
private ButtonSkinDefinition skinDefinition;
|
||||
private ISpecialDrawable downTexture, upTexture, highlightedTexture, disabledTexture;
|
||||
/// <summary>
|
||||
/// Click event listeners.
|
||||
/// </summary>
|
||||
public event Clicked Listeners;
|
||||
private bool pressed;
|
||||
/// <summary>
|
||||
/// Whether or not this button should be currently disabled.
|
||||
/// </summary>
|
||||
public bool disabled = false;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this button is currently being hovered on.
|
||||
/// </summary>
|
||||
public bool Highlighted { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs this button using <see cref="ISpecialDrawable"/>s for the different states it could be in.
|
||||
/// </summary>
|
||||
/// <param name="down">Button being pressed.</param>
|
||||
/// <param name="up">Button not being pressed.</param>
|
||||
/// <param name="disabled">Disabled button.</param>
|
||||
/// <param name="selected">Button being highlighted.</param>
|
||||
public Button(ISpecialDrawable down, ISpecialDrawable up, ISpecialDrawable disabled = null, ISpecialDrawable selected = null)
|
||||
{
|
||||
this.downTexture = down;
|
||||
@@ -25,6 +48,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
this.highlightedTexture = selected;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructs this button using the skin system.
|
||||
/// </summary>
|
||||
/// <param name="skin">The skin containing the information of the textures and design to follow.</param>
|
||||
/// <param name="definitionName">The name of the definition in the skin. Can be null to select the default.</param>
|
||||
public Button(Skin.Skin skin, string definitionName = null)
|
||||
{
|
||||
this.skinDefinition = skin.ObtainDefinition<ButtonSkinDefinition>(definitionName, GetType());
|
||||
@@ -34,6 +62,10 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
highlightedTexture = skin.textureAtlas[skinDefinition.selectedRegion];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the button.
|
||||
/// </summary>
|
||||
/// <param name="batch">Batch used to draw the button.</param>
|
||||
public override void Draw(SpriteBatch batch)
|
||||
{
|
||||
if (disabled)
|
||||
@@ -54,6 +86,11 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
base.Draw(batch);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the mouse changes state.
|
||||
/// </summary>
|
||||
/// <param name="state">The new state.</param>
|
||||
/// <returns>Whether or not to continue calling the next mouse change listener.</returns>
|
||||
public sealed override bool MouseStateChanged(MouseState state)
|
||||
{
|
||||
if (InputUtilities.MouseWithinBoundries(bounds))
|
||||
@@ -81,12 +118,17 @@ namespace RecrownedAthenaeum.UI.Modular.Modules.Interactive
|
||||
return base.MouseStateChanged(state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when the state of the keyboard changes.
|
||||
/// </summary>
|
||||
/// <param name="state">The new state.</param>
|
||||
/// <returns>Whether or not the next keyboard change listener should be called.</returns>
|
||||
public sealed override bool KeyboardStateChanged(KeyboardState state)
|
||||
{
|
||||
return base.KeyboardStateChanged(state);
|
||||
}
|
||||
|
||||
protected void OnClick()
|
||||
internal void OnClick()
|
||||
{
|
||||
Listeners?.Invoke();
|
||||
}
|
||||
|
Reference in New Issue
Block a user