mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Tidy up attach logic
This commit is contained in:
parent
5129716612
commit
f3847b90fd
@ -39,7 +39,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
/// Displays an interactive ruleset gameplay instance.
|
/// Displays an interactive ruleset gameplay instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="TObject">The type of HitObject contained by this DrawableRuleset.</typeparam>
|
/// <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
|
where TObject : HitObject
|
||||||
{
|
{
|
||||||
public override event Action<JudgementResult> NewResult;
|
public override event Action<JudgementResult> NewResult;
|
||||||
@ -339,9 +339,10 @@ namespace osu.Game.Rulesets.UI
|
|||||||
public abstract DrawableHitObject<TObject> CreateDrawableRepresentation(TObject h);
|
public abstract DrawableHitObject<TObject> CreateDrawableRepresentation(TObject h);
|
||||||
|
|
||||||
public void Attach(KeyCounterDisplay keyCounter) =>
|
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>
|
/// <summary>
|
||||||
/// Creates a key conversion input manager. An exception will be thrown if a valid <see cref="RulesetInputManager{T}"/> is not returned.
|
/// Creates a key conversion input manager. An exception will be thrown if a valid <see cref="RulesetInputManager{T}"/> is not returned.
|
||||||
|
@ -25,7 +25,7 @@ using static osu.Game.Input.Handlers.ReplayInputHandler;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.UI
|
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
|
where T : struct
|
||||||
{
|
{
|
||||||
public readonly KeyBindingContainer<T> KeyBindingContainer;
|
public readonly KeyBindingContainer<T> KeyBindingContainer;
|
||||||
@ -169,7 +169,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
.Select(action => new KeyCounterAction<T>(action)));
|
.Select(action => new KeyCounterAction<T>(action)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ActionReceptor : KeyCounterDisplay.Receptor, IKeyBindingHandler<T>
|
private class ActionReceptor : KeyCounterDisplay.Receptor, IKeyBindingHandler<T>
|
||||||
{
|
{
|
||||||
public ActionReceptor(KeyCounterDisplay target)
|
public ActionReceptor(KeyCounterDisplay target)
|
||||||
: base(target)
|
: base(target)
|
||||||
@ -191,8 +191,6 @@ namespace osu.Game.Rulesets.UI
|
|||||||
|
|
||||||
public void Attach(ClicksPerSecondCalculator calculator)
|
public void Attach(ClicksPerSecondCalculator calculator)
|
||||||
{
|
{
|
||||||
if (calculator == null) return;
|
|
||||||
|
|
||||||
var listener = new ActionListener(calculator);
|
var listener = new ActionListener(calculator);
|
||||||
|
|
||||||
KeyBindingContainer.Add(listener);
|
KeyBindingContainer.Add(listener);
|
||||||
@ -200,23 +198,22 @@ namespace osu.Game.Rulesets.UI
|
|||||||
calculator.Listener = listener;
|
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)
|
public bool OnPressed(KeyBindingPressEvent<T> e)
|
||||||
{
|
{
|
||||||
Calculator.AddTimestamp();
|
Calculator.AddTimestamp();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnReleased(KeyBindingReleaseEvent<T> e)
|
public void OnReleased(KeyBindingReleaseEvent<T> e)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionListener(ClicksPerSecondCalculator calculator)
|
|
||||||
: base(calculator)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -256,10 +253,10 @@ namespace osu.Game.Rulesets.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Supports attaching a <see cref="KeyCounterDisplay"/>.
|
/// Supports attaching various HUD pieces.
|
||||||
/// Keys will be populated automatically and a receptor will be injected inside.
|
/// Keys will be populated automatically and a receptor will be injected inside.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface ICanAttachKeyCounter
|
public interface ICanAttachHUDPieces
|
||||||
{
|
{
|
||||||
void Attach(KeyCounterDisplay keyCounter);
|
void Attach(KeyCounterDisplay keyCounter);
|
||||||
void Attach(ClicksPerSecondCalculator calculator);
|
void Attach(ClicksPerSecondCalculator calculator);
|
||||||
|
@ -264,8 +264,11 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
protected virtual void BindDrawableRuleset(DrawableRuleset drawableRuleset)
|
protected virtual void BindDrawableRuleset(DrawableRuleset drawableRuleset)
|
||||||
{
|
{
|
||||||
(drawableRuleset as ICanAttachKeyCounter)?.Attach(KeyCounter);
|
if (drawableRuleset is ICanAttachHUDPieces attachTarget)
|
||||||
(drawableRuleset as ICanAttachKeyCounter)?.Attach(clicksPerSecondCalculator);
|
{
|
||||||
|
attachTarget.Attach(KeyCounter);
|
||||||
|
attachTarget.Attach(clicksPerSecondCalculator);
|
||||||
|
}
|
||||||
|
|
||||||
replayLoaded.BindTo(drawableRuleset.HasReplayLoaded);
|
replayLoaded.BindTo(drawableRuleset.HasReplayLoaded);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user