diff --git a/osu.Game/Rulesets/UI/RulesetInputManager.cs b/osu.Game/Rulesets/UI/RulesetInputManager.cs index 889890e711..d3bc381f72 100644 --- a/osu.Game/Rulesets/UI/RulesetInputManager.cs +++ b/osu.Game/Rulesets/UI/RulesetInputManager.cs @@ -180,11 +180,8 @@ namespace osu.Game.Rulesets.UI private void attachKeyCounter(KeyCounterController keyCounter) { - var receptor = new ActionReceptor(keyCounter); + KeyBindingContainer.Add(keyCounter); - KeyBindingContainer.Add(receptor); - - keyCounter.SetReceptor(receptor); keyCounter.AddRange(KeyBindingContainer.DefaultKeyBindings .Select(b => b.GetAction()) .Distinct() @@ -192,24 +189,6 @@ namespace osu.Game.Rulesets.UI .Select(action => new KeyCounterActionTrigger(action))); } - private partial class ActionReceptor : KeyCounterController.Receptor, IKeyBindingHandler - { - public ActionReceptor(KeyCounterController target) - : base(target) - { - } - - public bool OnPressed(KeyBindingPressEvent e) => Target.Triggers - .OfType>() - .Any(c => c.OnPressed(e.Action, Clock.Rate >= 0)); - - public void OnReleased(KeyBindingReleaseEvent e) - { - foreach (var c in Target.Triggers.OfType>()) - c.OnReleased(e.Action, Clock.Rate >= 0); - } - } - #endregion #region Keys per second Counter Attachment diff --git a/osu.Game/Screens/Play/HUD/KeyCounterActionTrigger.cs b/osu.Game/Screens/Play/HUD/KeyCounterActionTrigger.cs index e5951a8bf4..f2c4487854 100644 --- a/osu.Game/Screens/Play/HUD/KeyCounterActionTrigger.cs +++ b/osu.Game/Screens/Play/HUD/KeyCounterActionTrigger.cs @@ -2,10 +2,12 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; +using osu.Framework.Input.Bindings; +using osu.Framework.Input.Events; namespace osu.Game.Screens.Play.HUD { - public partial class KeyCounterActionTrigger : InputTrigger + public partial class KeyCounterActionTrigger : InputTrigger, IKeyBindingHandler where T : struct { public T Action { get; } @@ -16,21 +18,21 @@ namespace osu.Game.Screens.Play.HUD Action = action; } - public bool OnPressed(T action, bool forwards) + public bool OnPressed(KeyBindingPressEvent e) { - if (!EqualityComparer.Default.Equals(action, Action)) + if (!EqualityComparer.Default.Equals(e.Action, Action)) return false; - Activate(forwards); + Activate(Clock.Rate >= 0); return false; } - public void OnReleased(T action, bool forwards) + public void OnReleased(KeyBindingReleaseEvent e) { - if (!EqualityComparer.Default.Equals(action, Action)) + if (!EqualityComparer.Default.Equals(e.Action, Action)) return; - Deactivate(forwards); + Deactivate(Clock.Rate >= 0); } } } diff --git a/osu.Game/Screens/Play/HUD/KeyCounterController.cs b/osu.Game/Screens/Play/HUD/KeyCounterController.cs index b138e64d6f..0fa02afbb4 100644 --- a/osu.Game/Screens/Play/HUD/KeyCounterController.cs +++ b/osu.Game/Screens/Play/HUD/KeyCounterController.cs @@ -5,11 +5,8 @@ using System; using System.Collections.Generic; using osu.Framework.Bindables; using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; -using osu.Framework.Input.Events; using osu.Game.Rulesets.UI; -using osuTK; namespace osu.Game.Screens.Play.HUD { @@ -17,8 +14,6 @@ namespace osu.Game.Screens.Play.HUD { public readonly Bindable IsCounting = new BindableBool(true); - private Receptor? receptor; - public event Action? OnNewTrigger; private readonly Container triggers; @@ -38,58 +33,8 @@ namespace osu.Game.Screens.Play.HUD } public void AddRange(IEnumerable inputTriggers) => inputTriggers.ForEach(Add); + public override bool HandleNonPositionalInput => true; - /// - /// Sets a that will populate keybinding events to this . - /// - /// The receptor to set - /// When a is already active on this - public void SetReceptor(Receptor receptor) - { - if (this.receptor != null) - throw new InvalidOperationException("Cannot set a new receptor when one is already active"); - - this.receptor = receptor; - } - - /// - /// Clears any active - /// - public void ClearReceptor() - { - receptor = null; - } - - public override bool HandleNonPositionalInput => receptor == null; - - public override bool HandlePositionalInput => receptor == null; - - public partial class Receptor : Drawable - { - protected readonly KeyCounterController Target; - - public Receptor(KeyCounterController target) - { - RelativeSizeAxes = Axes.Both; - Depth = float.MinValue; - Target = target; - } - - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => true; - - protected override bool Handle(UIEvent e) - { - switch (e) - { - case KeyDownEvent: - case KeyUpEvent: - case MouseDownEvent: - case MouseUpEvent: - return Target.TriggerEvent(e); - } - - return base.Handle(e); - } - } + public override bool HandlePositionalInput => true; } } diff --git a/osu.Game/Screens/Play/HUDOverlay.cs b/osu.Game/Screens/Play/HUDOverlay.cs index 15a0e0688b..21636ac04c 100644 --- a/osu.Game/Screens/Play/HUDOverlay.cs +++ b/osu.Game/Screens/Play/HUDOverlay.cs @@ -158,8 +158,8 @@ namespace osu.Game.Screens.Play Spacing = new Vector2(5) }, clicksPerSecondCalculator = new ClicksPerSecondCalculator(), - KeyCounter = new KeyCounterController() }; + KeyCounter = new KeyCounterController(); hideTargets = new List { mainComponents, rulesetComponents, topRightElements };