1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 18:45:37 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/KeyCounter.cs

56 lines
1.7 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Containers;
namespace osu.Game.Screens.Play.HUD
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// An individual key display which is intended to be displayed within a <see cref="KeyCounterDisplay"/>.
/// </summary>
2022-11-24 13:32:20 +08:00
public abstract partial class KeyCounter : Container
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// The <see cref="InputTrigger"/> which activates and deactivates this <see cref="KeyCounter"/>.
/// </summary>
public readonly InputTrigger Trigger;
2018-04-13 17:19:50 +08:00
/// <summary>
/// The current count of registered key presses.
/// </summary>
public IBindable<int> CountPresses => Trigger.ActivationCount;
2018-04-13 17:19:50 +08: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();
protected KeyCounter(InputTrigger trigger)
{
Trigger = trigger;
Trigger.OnActivate += Activate;
Trigger.OnDeactivate += Deactivate;
}
2023-02-22 03:02:56 +08:00
protected virtual void Activate(bool forwardPlayback = true)
2018-04-13 17:19:50 +08:00
{
IsActive.Value = true;
}
2023-02-22 03:02:56 +08:00
protected virtual void Deactivate(bool forwardPlayback = true)
{
IsActive.Value = false;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Trigger.OnActivate -= Activate;
Trigger.OnDeactivate -= Deactivate;
}
2018-04-13 17:19:50 +08:00
}
}