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/KeyCounterMouse.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

56 lines
1.3 KiB
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;
using osuTK;
namespace osu.Game.Screens.Play
{
public partial class KeyCounterMouse : KeyCounter.Trigger
{
public MouseButton Button { get; }
public KeyCounterMouse(MouseButton button)
: base(getStringRepresentation(button))
{
Button = button;
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true;
private static string getStringRepresentation(MouseButton button)
{
switch (button)
{
default:
return button.ToString();
case MouseButton.Left:
return @"M1";
case MouseButton.Right:
return @"M2";
}
}
protected override bool OnMouseDown(MouseDownEvent e)
{
if (e.Button == Button)
Lit();
return base.OnMouseDown(e);
}
protected override void OnMouseUp(MouseUpEvent e)
{
if (e.Button == Button)
Unlit();
base.OnMouseUp(e);
}
}
}