1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-31 01:23:22 +08:00
osu-lazer/osu.Game/Screens/Play/HUD/KeyCounterActionTrigger.cs

39 lines
1.0 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
2019-11-13 22:35:50 +08:00
using System.Collections.Generic;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
2019-11-13 22:35:50 +08:00
namespace osu.Game.Screens.Play.HUD
2018-04-13 17:19:50 +08:00
{
public partial class KeyCounterActionTrigger<T> : InputTrigger, IKeyBindingHandler<T>
2018-04-13 17:19:50 +08:00
where T : struct
{
public T Action { get; }
public KeyCounterActionTrigger(T action)
2019-02-28 12:31:40 +08:00
: base($"B{(int)(object)action + 1}")
2018-04-13 17:19:50 +08:00
{
Action = action;
}
public bool OnPressed(KeyBindingPressEvent<T> e)
2018-04-13 17:19:50 +08:00
{
if (!EqualityComparer<T>.Default.Equals(e.Action, Action))
return false;
Activate(Clock.Rate >= 0);
2018-04-13 17:19:50 +08:00
return false;
}
public void OnReleased(KeyBindingReleaseEvent<T> e)
2018-04-13 17:19:50 +08:00
{
if (!EqualityComparer<T>.Default.Equals(e.Action, Action))
return;
Deactivate(Clock.Rate >= 0);
2018-04-13 17:19:50 +08:00
}
}
}