2022-03-18 18:46:44 +00:00
|
|
|
namespace MoonWorks.Input
|
|
|
|
{
|
2023-09-14 18:23:04 +00:00
|
|
|
/// <summary>
|
|
|
|
/// VirtualButtons map inputs to binary inputs, like a trigger threshold or joystick axis threshold.
|
|
|
|
/// </summary>
|
2022-07-12 23:09:23 +00:00
|
|
|
public abstract class VirtualButton
|
2022-03-18 18:46:44 +00:00
|
|
|
{
|
2022-07-12 23:09:23 +00:00
|
|
|
public ButtonState State { get; protected set; }
|
2022-03-18 18:46:44 +00:00
|
|
|
|
2022-03-18 18:58:10 +00:00
|
|
|
/// <summary>
|
2022-11-28 08:48:48 +00:00
|
|
|
/// True if the button was pressed this exact frame.
|
2022-03-18 18:58:10 +00:00
|
|
|
/// </summary>
|
2022-11-28 08:48:48 +00:00
|
|
|
public bool IsPressed => State.IsPressed;
|
2022-03-18 18:58:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// True if the button has been continuously held for more than one frame.
|
|
|
|
/// </summary>
|
2022-03-18 18:46:44 +00:00
|
|
|
public bool IsHeld => State.IsHeld;
|
2022-03-18 18:58:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2022-11-28 08:48:48 +00:00
|
|
|
/// True if the button is pressed or held.
|
2022-03-18 18:58:10 +00:00
|
|
|
/// </summary>
|
2022-11-28 08:48:48 +00:00
|
|
|
public bool IsDown => State.IsDown;
|
2022-03-18 18:58:10 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2022-11-28 08:48:48 +00:00
|
|
|
/// True if the button was released this frame.
|
2022-03-18 18:58:10 +00:00
|
|
|
/// </summary>
|
2022-03-18 18:46:44 +00:00
|
|
|
public bool IsReleased => State.IsReleased;
|
|
|
|
|
2022-11-28 08:48:48 +00:00
|
|
|
/// <summary>
|
|
|
|
/// True if the button was not pressed the previous or current frame.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsIdle => State.IsIdle;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// True if the button is idle or released.
|
|
|
|
/// </summary>
|
|
|
|
public bool IsUp => State.IsUp;
|
|
|
|
|
2022-07-12 23:09:23 +00:00
|
|
|
internal virtual void Update()
|
2022-03-18 18:46:44 +00:00
|
|
|
{
|
2022-07-12 23:09:23 +00:00
|
|
|
State = State.Update(CheckPressed());
|
2022-03-18 18:46:44 +00:00
|
|
|
}
|
2022-07-12 23:09:23 +00:00
|
|
|
|
|
|
|
internal abstract bool CheckPressed();
|
2022-03-18 18:46:44 +00:00
|
|
|
}
|
|
|
|
}
|