2023-02-22 23:03:44 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2023-06-15 01:39:28 +08:00
|
|
|
using osu.Framework.Bindables;
|
2023-02-22 23:03:44 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
2023-03-07 15:28:54 +08:00
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2023-02-22 23:03:44 +08:00
|
|
|
{
|
2023-03-07 15:31:36 +08:00
|
|
|
/// <summary>
|
|
|
|
/// An event trigger which can be used with <see cref="KeyCounter"/> to create visual tracking of button/key presses.
|
|
|
|
/// </summary>
|
2023-02-22 23:03:44 +08:00
|
|
|
public abstract partial class InputTrigger : Component
|
|
|
|
{
|
2023-03-08 04:22:59 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Callback to invoke when the associated input has been activated.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="forwardPlayback">Whether gameplay is progressing in the forward direction time-wise.</param>
|
|
|
|
public delegate void OnActivateCallback(bool forwardPlayback);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Callback to invoke when the associated input has been deactivated.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="forwardPlayback">Whether gameplay is progressing in the forward direction time-wise.</param>
|
|
|
|
public delegate void OnDeactivateCallback(bool forwardPlayback);
|
|
|
|
|
|
|
|
public event OnActivateCallback? OnActivate;
|
|
|
|
public event OnDeactivateCallback? OnDeactivate;
|
2023-02-22 23:03:44 +08:00
|
|
|
|
2023-06-15 01:39:28 +08:00
|
|
|
private readonly Bindable<int> activationCount = new BindableInt();
|
|
|
|
private readonly Bindable<bool> isCounting = new BindableBool(true);
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Number of times this <see cref="InputTrigger"/> has been activated.
|
|
|
|
/// </summary>
|
|
|
|
public IBindable<int> ActivationCount => activationCount;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Whether any activation or deactivation of this <see cref="InputTrigger"/> impacts its <see cref="ActivationCount"/>
|
|
|
|
/// </summary>
|
|
|
|
public IBindable<bool> IsCounting => isCounting;
|
|
|
|
|
2023-02-22 23:03:44 +08:00
|
|
|
protected InputTrigger(string name)
|
|
|
|
{
|
|
|
|
Name = name;
|
|
|
|
}
|
|
|
|
|
2023-06-15 01:39:28 +08:00
|
|
|
protected void Activate(bool forwardPlayback = true)
|
|
|
|
{
|
|
|
|
if (forwardPlayback && isCounting.Value)
|
|
|
|
activationCount.Value++;
|
|
|
|
|
|
|
|
OnActivate?.Invoke(forwardPlayback);
|
|
|
|
}
|
2023-02-22 23:03:44 +08:00
|
|
|
|
2023-06-15 01:39:28 +08:00
|
|
|
protected void Deactivate(bool forwardPlayback = true)
|
|
|
|
{
|
|
|
|
if (!forwardPlayback && isCounting.Value)
|
|
|
|
activationCount.Value--;
|
|
|
|
|
|
|
|
OnDeactivate?.Invoke(forwardPlayback);
|
|
|
|
}
|
2023-02-22 23:03:44 +08:00
|
|
|
}
|
|
|
|
}
|