2019-01-24 08:43:03 +00:00
|
|
|
|
// 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 09:19:50 +00:00
|
|
|
|
|
2019-11-13 14:35:50 +00:00
|
|
|
|
using System.Collections.Generic;
|
2023-06-18 19:26:16 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2019-11-13 14:35:50 +00:00
|
|
|
|
|
2023-03-07 07:28:54 +00:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2017-08-21 03:31:21 +00:00
|
|
|
|
{
|
2023-06-18 19:26:16 +00:00
|
|
|
|
public partial class KeyCounterActionTrigger<T> : InputTrigger, IKeyBindingHandler<T>
|
2017-08-21 03:31:21 +00:00
|
|
|
|
where T : struct
|
|
|
|
|
{
|
|
|
|
|
public T Action { get; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-02-13 23:49:57 +00:00
|
|
|
|
public KeyCounterActionTrigger(T action)
|
2019-02-28 04:31:40 +00:00
|
|
|
|
: base($"B{(int)(object)action + 1}")
|
2017-08-21 03:31:21 +00:00
|
|
|
|
{
|
|
|
|
|
Action = action;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-06-18 19:26:16 +00:00
|
|
|
|
public bool OnPressed(KeyBindingPressEvent<T> e)
|
2017-08-21 03:31:21 +00:00
|
|
|
|
{
|
2023-06-18 19:26:16 +00:00
|
|
|
|
if (!EqualityComparer<T>.Default.Equals(e.Action, Action))
|
2019-09-12 06:41:53 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2023-06-18 19:26:16 +00:00
|
|
|
|
Activate(Clock.Rate >= 0);
|
2017-08-21 03:31:21 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-06-18 19:26:16 +00:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<T> e)
|
2017-08-21 03:31:21 +00:00
|
|
|
|
{
|
2023-06-18 19:26:16 +00:00
|
|
|
|
if (!EqualityComparer<T>.Default.Equals(e.Action, Action))
|
2020-01-22 04:22:34 +00:00
|
|
|
|
return;
|
2019-09-12 06:41:53 +00:00
|
|
|
|
|
2023-06-18 19:26:16 +00:00
|
|
|
|
Deactivate(Clock.Rate >= 0);
|
2017-08-21 03:31:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-05 11:21:19 +00:00
|
|
|
|
}
|