1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 05:32:54 +08:00

Retrieve KeyBindingContainer via DI rather than traversal lookup

This commit is contained in:
Dean Herbert 2022-01-31 16:47:20 +09:00
parent cc7fb0e559
commit 0e764538e0
3 changed files with 14 additions and 9 deletions

View File

@ -2,11 +2,13 @@
// 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.ComponentModel; using System.ComponentModel;
using osu.Framework.Allocation;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
namespace osu.Game.Rulesets.Mania namespace osu.Game.Rulesets.Mania
{ {
[Cached] // Used for touch input, see ColumnTouchInputArea.
public class ManiaInputManager : RulesetInputManager<ManiaAction> public class ManiaInputManager : RulesetInputManager<ManiaAction>
{ {
public ManiaInputManager(RulesetInfo ruleset, int variant) public ManiaInputManager(RulesetInfo ruleset, int variant)

View File

@ -143,6 +143,11 @@ namespace osu.Game.Rulesets.Mania.UI
public class ColumnTouchInputArea : Drawable public class ColumnTouchInputArea : Drawable
{ {
[Resolved(canBeNull: true)]
private ManiaInputManager maniaInputManager { get; set; }
private KeyBindingContainer<ManiaAction> keyBindingContainer;
public ColumnTouchInputArea() public ColumnTouchInputArea()
{ {
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -152,32 +157,30 @@ namespace osu.Game.Rulesets.Mania.UI
protected override void LoadComplete() protected override void LoadComplete()
{ {
keyBindingContainer = (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; keyBindingContainer = maniaInputManager?.KeyBindingContainer;
} }
private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
keyBindingContainer.TriggerPressed(column.Action.Value); keyBindingContainer?.TriggerPressed(column.Action.Value);
return base.OnMouseDown(e); return base.OnMouseDown(e);
} }
protected override void OnMouseUp(MouseUpEvent e) protected override void OnMouseUp(MouseUpEvent e)
{ {
keyBindingContainer.TriggerReleased(column.Action.Value); keyBindingContainer?.TriggerReleased(column.Action.Value);
base.OnMouseUp(e); base.OnMouseUp(e);
} }
protected override bool OnTouchDown(TouchDownEvent e) protected override bool OnTouchDown(TouchDownEvent e)
{ {
keyBindingContainer.TriggerPressed(column.Action.Value); keyBindingContainer?.TriggerPressed(column.Action.Value);
return true; return true;
} }
protected override void OnTouchUp(TouchUpEvent e) protected override void OnTouchUp(TouchUpEvent e)
{ {
keyBindingContainer.TriggerReleased(column.Action.Value); keyBindingContainer?.TriggerReleased(column.Action.Value);
} }
} }
} }

View File

@ -24,6 +24,8 @@ namespace osu.Game.Rulesets.UI
public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler, IHasRecordingHandler public abstract class RulesetInputManager<T> : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler, IHasRecordingHandler
where T : struct where T : struct
{ {
public readonly KeyBindingContainer<T> KeyBindingContainer;
private ReplayRecorder recorder; private ReplayRecorder recorder;
public ReplayRecorder Recorder public ReplayRecorder Recorder
@ -43,8 +45,6 @@ namespace osu.Game.Rulesets.UI
protected override InputState CreateInitialState() => new RulesetInputManagerInputState<T>(base.CreateInitialState()); protected override InputState CreateInitialState() => new RulesetInputManagerInputState<T>(base.CreateInitialState());
public readonly KeyBindingContainer<T> KeyBindingContainer;
protected override Container<Drawable> Content => content; protected override Container<Drawable> Content => content;
private readonly Container content; private readonly Container content;