mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 14:17:26 +08:00
refactor: improve attachement flow
This removes the hard reliance on individual classes and makes its usage easiser to ingreate anywhere else.
This commit is contained in:
parent
41b7eacc72
commit
4c397085c5
@ -158,9 +158,41 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
#endregion
|
||||
|
||||
#region Component attachement
|
||||
|
||||
public void Attach(IAttachableSkinComponent skinComponent)
|
||||
{
|
||||
switch (skinComponent)
|
||||
{
|
||||
case KeyCounterDisplay keyCounterDisplay:
|
||||
attachKeyCounter(keyCounterDisplay);
|
||||
break;
|
||||
|
||||
case ClicksPerSecondCalculator clicksPerSecondCalculator:
|
||||
attachClicksPerSecond(clicksPerSecondCalculator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Detach(IAttachableSkinComponent skinComponent)
|
||||
{
|
||||
switch (skinComponent)
|
||||
{
|
||||
case KeyCounterDisplay keyCounterDisplay:
|
||||
detachKeyCounter(keyCounterDisplay);
|
||||
break;
|
||||
|
||||
case ClicksPerSecondCalculator clicksPerSecondCalculator:
|
||||
detachClicksPerSecond(clicksPerSecondCalculator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Key Counter Attachment
|
||||
|
||||
public void Attach(KeyCounterDisplay keyCounter)
|
||||
private void attachKeyCounter(KeyCounterDisplay keyCounter)
|
||||
{
|
||||
var receptor = new ActionReceptor(keyCounter);
|
||||
|
||||
@ -174,6 +206,10 @@ namespace osu.Game.Rulesets.UI
|
||||
.Select(action => new KeyCounterActionTrigger<T>(action)));
|
||||
}
|
||||
|
||||
private void detachKeyCounter(KeyCounterDisplay keyCounter)
|
||||
{
|
||||
}
|
||||
|
||||
private partial class ActionReceptor : KeyCounterDisplay.Receptor, IKeyBindingHandler<T>
|
||||
{
|
||||
public ActionReceptor(KeyCounterDisplay target)
|
||||
@ -197,13 +233,17 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
#region Keys per second Counter Attachment
|
||||
|
||||
public void Attach(ClicksPerSecondCalculator calculator)
|
||||
private void attachClicksPerSecond(ClicksPerSecondCalculator calculator)
|
||||
{
|
||||
var listener = new ActionListener(calculator);
|
||||
|
||||
KeyBindingContainer.Add(listener);
|
||||
}
|
||||
|
||||
private void detachClicksPerSecond(ClicksPerSecondCalculator calculator)
|
||||
{
|
||||
}
|
||||
|
||||
private partial class ActionListener : Component, IKeyBindingHandler<T>
|
||||
{
|
||||
private readonly ClicksPerSecondCalculator calculator;
|
||||
@ -266,8 +306,12 @@ namespace osu.Game.Rulesets.UI
|
||||
/// </summary>
|
||||
public interface ICanAttachHUDPieces
|
||||
{
|
||||
void Attach(KeyCounterDisplay keyCounter);
|
||||
void Attach(ClicksPerSecondCalculator calculator);
|
||||
void Attach(IAttachableSkinComponent component);
|
||||
void Detach(IAttachableSkinComponent component);
|
||||
}
|
||||
|
||||
public interface IAttachableSkinComponent
|
||||
{
|
||||
}
|
||||
|
||||
public class RulesetInputManagerInputState<T> : InputState
|
||||
|
@ -8,7 +8,7 @@ using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD.ClicksPerSecond
|
||||
{
|
||||
public partial class ClicksPerSecondCalculator : Component
|
||||
public partial class ClicksPerSecondCalculator : Component, IAttachableSkinComponent
|
||||
{
|
||||
private readonly List<double> timestamps = new List<double>();
|
||||
|
||||
|
@ -11,6 +11,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Screens.Play.HUD
|
||||
@ -18,7 +19,7 @@ namespace osu.Game.Screens.Play.HUD
|
||||
/// <summary>
|
||||
/// A flowing display of all gameplay keys. Individual keys can be added using <see cref="InputTrigger"/> implementations.
|
||||
/// </summary>
|
||||
public abstract partial class KeyCounterDisplay : CompositeDrawable
|
||||
public abstract partial class KeyCounterDisplay : CompositeDrawable, IAttachableSkinComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Whether the key counter should be visible regardless of the configuration value.
|
||||
@ -44,6 +45,11 @@ namespace osu.Game.Screens.Play.HUD
|
||||
|
||||
private Receptor? receptor;
|
||||
|
||||
/// <summary>
|
||||
/// Sets a <see cref="Receptor"/> that will populate keybinding events to this <see cref="KeyCounterDisplay"/>.
|
||||
/// </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)
|
||||
@ -52,6 +58,14 @@ namespace osu.Game.Screens.Play.HUD
|
||||
this.receptor = receptor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears any <see cref="Receptor"/> active
|
||||
/// </summary>
|
||||
public void ClearReceptor()
|
||||
{
|
||||
receptor = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add a <see cref="InputTrigger"/> to this display.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user