mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 04:02:57 +08:00
refactor: move count logic in InputTrigger
This will allow us to keep track of the real count regardless of whether the key counter has been placed mid-replay or not.
This commit is contained in:
parent
758831b983
commit
e9ef270e46
@ -1,6 +1,7 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
@ -25,13 +26,38 @@ namespace osu.Game.Screens.Play.HUD
|
||||
public event OnActivateCallback? OnActivate;
|
||||
public event OnDeactivateCallback? OnDeactivate;
|
||||
|
||||
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;
|
||||
|
||||
protected InputTrigger(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
protected void Activate(bool forwardPlayback = true) => OnActivate?.Invoke(forwardPlayback);
|
||||
protected void Activate(bool forwardPlayback = true)
|
||||
{
|
||||
if (forwardPlayback && isCounting.Value)
|
||||
activationCount.Value++;
|
||||
|
||||
protected void Deactivate(bool forwardPlayback = true) => OnDeactivate?.Invoke(forwardPlayback);
|
||||
OnActivate?.Invoke(forwardPlayback);
|
||||
}
|
||||
|
||||
protected void Deactivate(bool forwardPlayback = true)
|
||||
{
|
||||
if (!forwardPlayback && isCounting.Value)
|
||||
activationCount.Value--;
|
||||
|
||||
OnDeactivate?.Invoke(forwardPlayback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,15 +22,10 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// </summary>
|
||||
public Bindable<bool> IsCounting { get; } = new BindableBool(true);
|
||||
|
||||
private readonly Bindable<int> countPresses = new BindableInt
|
||||
{
|
||||
MinValue = 0
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// The current count of registered key presses.
|
||||
/// </summary>
|
||||
public IBindable<int> CountPresses => countPresses;
|
||||
public IBindable<int> CountPresses => Trigger.ActivationCount;
|
||||
|
||||
private readonly Container content;
|
||||
|
||||
@ -49,46 +44,28 @@ namespace osu.Game.Screens.Play.HUD
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
Trigger = trigger,
|
||||
};
|
||||
|
||||
Trigger = trigger;
|
||||
|
||||
Trigger.OnActivate += Activate;
|
||||
Trigger.OnDeactivate += Deactivate;
|
||||
}
|
||||
|
||||
private void increment()
|
||||
{
|
||||
if (!IsCounting.Value)
|
||||
return;
|
||||
|
||||
countPresses.Value++;
|
||||
}
|
||||
|
||||
private void decrement()
|
||||
{
|
||||
if (!IsCounting.Value)
|
||||
return;
|
||||
|
||||
countPresses.Value--;
|
||||
}
|
||||
|
||||
protected virtual void Activate(bool forwardPlayback = true)
|
||||
{
|
||||
IsActive.Value = true;
|
||||
if (forwardPlayback)
|
||||
increment();
|
||||
}
|
||||
|
||||
protected virtual void Deactivate(bool forwardPlayback = true)
|
||||
{
|
||||
IsActive.Value = false;
|
||||
if (!forwardPlayback)
|
||||
decrement();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
Trigger.OnActivate -= Activate;
|
||||
Trigger.OnDeactivate -= Deactivate;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user