1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 07:27:51 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/KeyCounter.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

87 lines
2.3 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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Play.HUD
{
/// <summary>
/// An individual key display which is intended to be displayed within a <see cref="KeyCounterDisplay"/>.
/// </summary>
2016-09-24 10:19:50 +08:00
public abstract partial class KeyCounter : Container
{
public readonly InputTrigger Trigger;
2018-04-13 17:19:50 +08:00
private readonly Container content;
protected override Container<Drawable> Content => content;
private readonly Bindable<int> countPresses = new BindableInt
2016-09-26 14:07:43 +08:00
{
MinValue = 0
};
2018-04-13 17:19:50 +08:00
public Bindable<bool> IsCounting { get; } = new BindableBool(true);
2019-02-28 12:31:40 +08:00
public IBindable<int> CountPresses => countPresses;
2018-04-13 17:19:50 +08:00
protected KeyCounter(InputTrigger trigger)
{
InternalChildren = new Drawable[]
{
content = new Container
{
RelativeSizeAxes = Axes.Both
},
Trigger = trigger,
};
Trigger.OnActivate += Activate;
Trigger.OnDeactivate += Deactivate;
Name = trigger.Name;
}
protected readonly Bindable<bool> IsActive = new BindableBool();
private void increment()
{
if (!IsCounting.Value)
return;
countPresses.Value++;
}
private void decrement()
{
if (!IsCounting.Value)
return;
countPresses.Value--;
}
2023-02-22 03:02:56 +08:00
protected virtual void Activate(bool forwardPlayback = true)
{
IsActive.Value = true;
2023-02-22 03:02:56 +08:00
if (forwardPlayback)
increment();
}
2023-02-22 03:02:56 +08:00
protected virtual void Deactivate(bool forwardPlayback = true)
{
IsActive.Value = false;
2023-02-22 03:02:56 +08:00
if (!forwardPlayback)
decrement();
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
Trigger.OnActivate -= Activate;
Trigger.OnDeactivate -= Deactivate;
}
}
}