mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 14:12:56 +08:00
style(KeyCounterController): remove reliance on Receptor
This commit is contained in:
parent
1a8219adf6
commit
141f9efad5
@ -180,11 +180,8 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
private void attachKeyCounter(KeyCounterController keyCounter)
|
private void attachKeyCounter(KeyCounterController keyCounter)
|
||||||
{
|
{
|
||||||
var receptor = new ActionReceptor(keyCounter);
|
KeyBindingContainer.Add(keyCounter);
|
||||||
|
|
||||||
KeyBindingContainer.Add(receptor);
|
|
||||||
|
|
||||||
keyCounter.SetReceptor(receptor);
|
|
||||||
keyCounter.AddRange(KeyBindingContainer.DefaultKeyBindings
|
keyCounter.AddRange(KeyBindingContainer.DefaultKeyBindings
|
||||||
.Select(b => b.GetAction<T>())
|
.Select(b => b.GetAction<T>())
|
||||||
.Distinct()
|
.Distinct()
|
||||||
@ -192,24 +189,6 @@ namespace osu.Game.Rulesets.UI
|
|||||||
.Select(action => new KeyCounterActionTrigger<T>(action)));
|
.Select(action => new KeyCounterActionTrigger<T>(action)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class ActionReceptor : KeyCounterController.Receptor, IKeyBindingHandler<T>
|
|
||||||
{
|
|
||||||
public ActionReceptor(KeyCounterController target)
|
|
||||||
: base(target)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool OnPressed(KeyBindingPressEvent<T> e) => Target.Triggers
|
|
||||||
.OfType<KeyCounterActionTrigger<T>>()
|
|
||||||
.Any(c => c.OnPressed(e.Action, Clock.Rate >= 0));
|
|
||||||
|
|
||||||
public void OnReleased(KeyBindingReleaseEvent<T> e)
|
|
||||||
{
|
|
||||||
foreach (var c in Target.Triggers.OfType<KeyCounterActionTrigger<T>>())
|
|
||||||
c.OnReleased(e.Action, Clock.Rate >= 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Keys per second Counter Attachment
|
#region Keys per second Counter Attachment
|
||||||
|
@ -2,10 +2,12 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using osu.Framework.Input.Bindings;
|
||||||
|
using osu.Framework.Input.Events;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
namespace osu.Game.Screens.Play.HUD
|
||||||
{
|
{
|
||||||
public partial class KeyCounterActionTrigger<T> : InputTrigger
|
public partial class KeyCounterActionTrigger<T> : InputTrigger, IKeyBindingHandler<T>
|
||||||
where T : struct
|
where T : struct
|
||||||
{
|
{
|
||||||
public T Action { get; }
|
public T Action { get; }
|
||||||
@ -16,21 +18,21 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
Action = action;
|
Action = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OnPressed(T action, bool forwards)
|
public bool OnPressed(KeyBindingPressEvent<T> e)
|
||||||
{
|
{
|
||||||
if (!EqualityComparer<T>.Default.Equals(action, Action))
|
if (!EqualityComparer<T>.Default.Equals(e.Action, Action))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Activate(forwards);
|
Activate(Clock.Rate >= 0);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnReleased(T action, bool forwards)
|
public void OnReleased(KeyBindingReleaseEvent<T> e)
|
||||||
{
|
{
|
||||||
if (!EqualityComparer<T>.Default.Equals(action, Action))
|
if (!EqualityComparer<T>.Default.Equals(e.Action, Action))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Deactivate(forwards);
|
Deactivate(Clock.Rate >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,8 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.Events;
|
|
||||||
using osu.Game.Rulesets.UI;
|
using osu.Game.Rulesets.UI;
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Screens.Play.HUD
|
namespace osu.Game.Screens.Play.HUD
|
||||||
{
|
{
|
||||||
@ -17,8 +14,6 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
{
|
{
|
||||||
public readonly Bindable<bool> IsCounting = new BindableBool(true);
|
public readonly Bindable<bool> IsCounting = new BindableBool(true);
|
||||||
|
|
||||||
private Receptor? receptor;
|
|
||||||
|
|
||||||
public event Action<InputTrigger>? OnNewTrigger;
|
public event Action<InputTrigger>? OnNewTrigger;
|
||||||
|
|
||||||
private readonly Container<InputTrigger> triggers;
|
private readonly Container<InputTrigger> triggers;
|
||||||
@ -38,58 +33,8 @@ namespace osu.Game.Screens.Play.HUD
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void AddRange(IEnumerable<InputTrigger> inputTriggers) => inputTriggers.ForEach(Add);
|
public void AddRange(IEnumerable<InputTrigger> inputTriggers) => inputTriggers.ForEach(Add);
|
||||||
|
public override bool HandleNonPositionalInput => true;
|
||||||
|
|
||||||
/// <summary>
|
public override bool HandlePositionalInput => true;
|
||||||
/// Sets a <see cref="Receptor"/> that will populate keybinding events to this <see cref="KeyCounterController"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="receptor">The receptor to set</param>
|
|
||||||
/// <exception cref="InvalidOperationException">When a <see cref="Receptor"/> is already active on this <see cref="KeyCounterDisplay"/></exception>
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clears any <see cref="KeyCounterController.Receptor"/> active
|
|
||||||
/// </summary>
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,8 @@ namespace osu.Game.Screens.Play
|
|||||||
Spacing = new Vector2(5)
|
Spacing = new Vector2(5)
|
||||||
},
|
},
|
||||||
clicksPerSecondCalculator = new ClicksPerSecondCalculator(),
|
clicksPerSecondCalculator = new ClicksPerSecondCalculator(),
|
||||||
KeyCounter = new KeyCounterController()
|
|
||||||
};
|
};
|
||||||
|
KeyCounter = new KeyCounterController();
|
||||||
|
|
||||||
hideTargets = new List<Drawable> { mainComponents, rulesetComponents, topRightElements };
|
hideTargets = new List<Drawable> { mainComponents, rulesetComponents, topRightElements };
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user