2019-01-24 17:43:03 +09: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.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-02-13 01:24:27 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
2023-03-07 16:28:54 +09:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2023-03-07 16:31:36 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An individual key display which is intended to be displayed within a <see cref="KeyCounterDisplay"/>.
|
|
|
|
|
/// </summary>
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public abstract partial class KeyCounter : Container
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2023-03-07 21:28:42 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The <see cref="InputTrigger"/> which activates and deactivates this <see cref="KeyCounter"/>.
|
|
|
|
|
/// </summary>
|
2023-02-13 21:59:17 +00:00
|
|
|
|
public readonly InputTrigger Trigger;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-03-07 21:28:42 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The current count of registered key presses.
|
|
|
|
|
/// </summary>
|
2023-06-14 19:39:28 +02:00
|
|
|
|
public IBindable<int> CountPresses => Trigger.ActivationCount;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-03-07 21:28:42 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Whether this <see cref="KeyCounter"/> is currently in the "activated" state because the associated key is currently pressed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected readonly Bindable<bool> IsActive = new BindableBool();
|
|
|
|
|
|
2023-02-13 21:59:17 +00:00
|
|
|
|
protected KeyCounter(InputTrigger trigger)
|
2023-02-13 10:59:10 +00:00
|
|
|
|
{
|
2023-06-14 19:39:28 +02:00
|
|
|
|
Trigger = trigger;
|
|
|
|
|
|
2023-02-16 23:15:03 +00:00
|
|
|
|
Trigger.OnActivate += Activate;
|
|
|
|
|
Trigger.OnDeactivate += Deactivate;
|
2023-02-13 10:59:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 19:02:56 +00:00
|
|
|
|
protected virtual void Activate(bool forwardPlayback = true)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2023-02-17 00:40:01 +00:00
|
|
|
|
IsActive.Value = true;
|
2023-02-16 21:59:39 +00:00
|
|
|
|
}
|
2023-02-13 01:24:27 +00:00
|
|
|
|
|
2023-02-21 19:02:56 +00:00
|
|
|
|
protected virtual void Deactivate(bool forwardPlayback = true)
|
2023-02-16 21:59:39 +00:00
|
|
|
|
{
|
2023-02-17 00:40:01 +00:00
|
|
|
|
IsActive.Value = false;
|
2023-02-16 21:59:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2023-06-14 19:39:28 +02:00
|
|
|
|
|
2023-06-26 19:12:49 +02:00
|
|
|
|
Trigger.OnActivate -= Activate;
|
|
|
|
|
Trigger.OnDeactivate -= Deactivate;
|
2023-02-16 21:59:39 +00:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|