mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 13:22:55 +08:00
74a58fb674
To implement different different sources of input for KeyCounter, it is now possible to create a Trigger class (to inherit) instead of inheriting KeyCounter. This eases the creation of more input sources (like for tests) while allowing to implement different UI variants. That way, if another variant of the key counter needs to implemented (for whathever reason), this can be done by only inheriting KeyCounter and changing how things are arranged visually.
39 lines
950 B
C#
39 lines
950 B
C#
// 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.
|
|
|
|
#nullable disable
|
|
|
|
using System.Collections.Generic;
|
|
|
|
namespace osu.Game.Screens.Play
|
|
{
|
|
public partial class KeyCounterAction<T> : KeyCounter.Trigger
|
|
where T : struct
|
|
{
|
|
public T Action { get; }
|
|
|
|
public KeyCounterAction(T action)
|
|
: base($"B{(int)(object)action + 1}")
|
|
{
|
|
Action = action;
|
|
}
|
|
|
|
public bool OnPressed(T action, bool forwards)
|
|
{
|
|
if (!EqualityComparer<T>.Default.Equals(action, Action))
|
|
return false;
|
|
|
|
Lit(forwards);
|
|
return false;
|
|
}
|
|
|
|
public void OnReleased(T action, bool forwards)
|
|
{
|
|
if (!EqualityComparer<T>.Default.Equals(action, Action))
|
|
return;
|
|
|
|
Unlit(forwards);
|
|
}
|
|
}
|
|
}
|