1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-08 09:27:32 +08:00
osu-lazer/osu.Game/Screens/Play/KeyCounterKeyboard.cs
tsrk 74a58fb674
refactor: separate things in KeyCounter
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.
2023-02-13 01:24:27 +00:00

38 lines
824 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 osu.Framework.Input.Events;
using osuTK.Input;
namespace osu.Game.Screens.Play
{
public partial class KeyCounterKeyboard : KeyCounter.Trigger
{
public Key Key { get; }
public KeyCounterKeyboard(Key key)
: base(key.ToString())
{
Key = key;
}
protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Key == Key)
Lit();
return base.OnKeyDown(e);
}
protected override void OnKeyUp(KeyUpEvent e)
{
if (e.Key == Key)
Unlit();
base.OnKeyUp(e);
}
}
}