1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 05:12:54 +08:00

Tidy up attach logic

This commit is contained in:
Dean Herbert 2022-08-24 19:36:01 +09:00
parent 5129716612
commit f3847b90fd
3 changed files with 19 additions and 18 deletions

View File

@ -39,7 +39,7 @@ namespace osu.Game.Rulesets.UI
/// Displays an interactive ruleset gameplay instance.
/// </summary>
/// <typeparam name="TObject">The type of HitObject contained by this DrawableRuleset.</typeparam>
public abstract class DrawableRuleset<TObject> : DrawableRuleset, IProvideCursor, ICanAttachKeyCounter
public abstract class DrawableRuleset<TObject> : DrawableRuleset, IProvideCursor, ICanAttachHUDPieces
where TObject : HitObject
{
public override event Action<JudgementResult> NewResult;
@ -339,9 +339,10 @@ namespace osu.Game.Rulesets.UI
public abstract DrawableHitObject<TObject> CreateDrawableRepresentation(TObject h);
public void Attach(KeyCounterDisplay keyCounter) =>
(KeyBindingInputManager as ICanAttachKeyCounter)?.Attach(keyCounter);
(KeyBindingInputManager as ICanAttachHUDPieces)?.Attach(keyCounter);
public void Attach(ClicksPerSecondCalculator calculator) => (KeyBindingInputManager as ICanAttachKeyCounter)?.Attach(calculator);
public void Attach(ClicksPerSecondCalculator calculator) =>
(KeyBindingInputManager as ICanAttachHUDPieces)?.Attach(calculator);
/// <summary>
/// Creates a key conversion input manager. An exception will be thrown if a valid <see cref="RulesetInputManager{T}"/> is not returned.

View File

@ -25,7 +25,7 @@ using static osu.Game.Input.Handlers.ReplayInputHandler;
namespace osu.Game.Rulesets.UI
{
public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler, IHasRecordingHandler
public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachHUDPieces, IHasReplayHandler, IHasRecordingHandler
where T : struct
{
public readonly KeyBindingContainer<T> KeyBindingContainer;
@ -169,7 +169,7 @@ namespace osu.Game.Rulesets.UI
.Select(action => new KeyCounterAction<T>(action)));
}
public class ActionReceptor : KeyCounterDisplay.Receptor, IKeyBindingHandler<T>
private class ActionReceptor : KeyCounterDisplay.Receptor, IKeyBindingHandler<T>
{
public ActionReceptor(KeyCounterDisplay target)
: base(target)
@ -191,8 +191,6 @@ namespace osu.Game.Rulesets.UI
public void Attach(ClicksPerSecondCalculator calculator)
{
if (calculator == null) return;
var listener = new ActionListener(calculator);
KeyBindingContainer.Add(listener);
@ -200,23 +198,22 @@ namespace osu.Game.Rulesets.UI
calculator.Listener = listener;
}
public class ActionListener : ClicksPerSecondCalculator.InputListener, IKeyBindingHandler<T>
private class ActionListener : ClicksPerSecondCalculator.InputListener, IKeyBindingHandler<T>
{
public ActionListener(ClicksPerSecondCalculator calculator)
: base(calculator)
{
}
public bool OnPressed(KeyBindingPressEvent<T> e)
{
Calculator.AddTimestamp();
return false;
}
public void OnReleased(KeyBindingReleaseEvent<T> e)
{
}
public ActionListener(ClicksPerSecondCalculator calculator)
: base(calculator)
{
}
}
#endregion
@ -256,10 +253,10 @@ namespace osu.Game.Rulesets.UI
}
/// <summary>
/// Supports attaching a <see cref="KeyCounterDisplay"/>.
/// Supports attaching various HUD pieces.
/// Keys will be populated automatically and a receptor will be injected inside.
/// </summary>
public interface ICanAttachKeyCounter
public interface ICanAttachHUDPieces
{
void Attach(KeyCounterDisplay keyCounter);
void Attach(ClicksPerSecondCalculator calculator);

View File

@ -264,8 +264,11 @@ namespace osu.Game.Screens.Play
protected virtual void BindDrawableRuleset(DrawableRuleset drawableRuleset)
{
(drawableRuleset as ICanAttachKeyCounter)?.Attach(KeyCounter);
(drawableRuleset as ICanAttachKeyCounter)?.Attach(clicksPerSecondCalculator);
if (drawableRuleset is ICanAttachHUDPieces attachTarget)
{
attachTarget.Attach(KeyCounter);
attachTarget.Attach(clicksPerSecondCalculator);
}
replayLoaded.BindTo(drawableRuleset.HasReplayLoaded);
}