// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Bindables; using osu.Framework.Graphics; namespace osu.Game.Screens.Play.HUD { /// /// An event trigger which can be used with to create visual tracking of button/key presses. /// public abstract partial class InputTrigger : Component { /// /// Callback to invoke when the associated input has been activated. /// /// Whether gameplay is progressing in the forward direction time-wise. public delegate void OnActivateCallback(bool forwardPlayback); /// /// Callback to invoke when the associated input has been deactivated. /// /// Whether gameplay is progressing in the forward direction time-wise. public delegate void OnDeactivateCallback(bool forwardPlayback); public event OnActivateCallback? OnActivate; public event OnDeactivateCallback? OnDeactivate; private readonly Bindable activationCount = new BindableInt(); private readonly Bindable isCounting = new BindableBool(true); /// /// Number of times this has been activated. /// public IBindable ActivationCount => activationCount; /// /// Whether any activation or deactivation of this impacts its /// public IBindable IsCounting => isCounting; protected InputTrigger(string name) { Name = name; } protected void Activate(bool forwardPlayback = true) { if (forwardPlayback && isCounting.Value) activationCount.Value++; OnActivate?.Invoke(forwardPlayback); } protected void Deactivate(bool forwardPlayback = true) { if (!forwardPlayback && isCounting.Value) activationCount.Value--; OnDeactivate?.Invoke(forwardPlayback); } } }