From 327822de5bb5e15098c53fce05ae0eddad495e58 Mon Sep 17 00:00:00 2001 From: pikokr Date: Mon, 27 Dec 2021 19:41:36 +0900 Subject: [PATCH 01/11] Add touchscreen support for osu!mania ruleset --- osu.Game.Rulesets.Mania/UI/Column.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 9d060944cd..df39b5397b 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -136,6 +136,33 @@ public void OnReleased(KeyBindingReleaseEvent e) { } + // https://github.com/ppy/osu-framework/blob/49c954321c3686628b2c223670363438f88a0341/osu.Framework/Graphics/Drawable.cs#L1513-L1524 + private T findClosestParent() where T : class, IDrawable + { + Drawable cursor = this; + + while ((cursor = cursor.Parent) != null) + { + if (cursor is T match) + return match; + } + + return default; + } + + private ManiaInputManager.RulesetKeyBindingContainer keyBindingManager => findClosestParent(); + + protected override bool OnTouchDown(TouchDownEvent e) + { + keyBindingManager.TriggerPressed(Action.Value); + return base.OnTouchDown(e); + } + + protected override void OnTouchUp(TouchUpEvent e) + { + keyBindingManager.TriggerReleased(Action.Value); + } + public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) // This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border => DrawRectangle.Inflate(new Vector2(Stage.COLUMN_SPACING / 2, 0)).Contains(ToLocalSpace(screenSpacePos)); From 58994b790c8e8a3c85fa5d82edc2835b648b8843 Mon Sep 17 00:00:00 2001 From: pikokr Date: Mon, 27 Dec 2021 21:20:52 +0900 Subject: [PATCH 02/11] Get key binding container once instead of getting on every touch --- osu.Game.Rulesets.Mania/ManiaInputManager.cs | 5 +++++ osu.Game.Rulesets.Mania/UI/Column.cs | 21 ++++++-------------- osu.Game/Rulesets/UI/DrawableRuleset.cs | 1 + 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaInputManager.cs b/osu.Game.Rulesets.Mania/ManiaInputManager.cs index 186fc4b15d..bf94735077 100644 --- a/osu.Game.Rulesets.Mania/ManiaInputManager.cs +++ b/osu.Game.Rulesets.Mania/ManiaInputManager.cs @@ -13,6 +13,11 @@ public ManiaInputManager(RulesetInfo ruleset, int variant) : base(ruleset, variant, SimultaneousBindingMode.Unique) { } + + public RulesetKeyBindingContainer GetKeyBindingContainer() + { + return (RulesetKeyBindingContainer)KeyBindingContainer; + } } public enum ManiaAction diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index df39b5397b..6be36619c7 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -136,31 +136,22 @@ public void OnReleased(KeyBindingReleaseEvent e) { } - // https://github.com/ppy/osu-framework/blob/49c954321c3686628b2c223670363438f88a0341/osu.Framework/Graphics/Drawable.cs#L1513-L1524 - private T findClosestParent() where T : class, IDrawable + private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } + + private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingManager() { - Drawable cursor = this; - - while ((cursor = cursor.Parent) != null) - { - if (cursor is T match) - return match; - } - - return default; + return keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); } - private ManiaInputManager.RulesetKeyBindingContainer keyBindingManager => findClosestParent(); - protected override bool OnTouchDown(TouchDownEvent e) { - keyBindingManager.TriggerPressed(Action.Value); + getKeyBindingManager().TriggerPressed(Action.Value); return base.OnTouchDown(e); } protected override void OnTouchUp(TouchUpEvent e) { - keyBindingManager.TriggerReleased(Action.Value); + getKeyBindingManager().TriggerReleased(Action.Value); } public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) diff --git a/osu.Game/Rulesets/UI/DrawableRuleset.cs b/osu.Game/Rulesets/UI/DrawableRuleset.cs index 29559f5036..30012784a3 100644 --- a/osu.Game/Rulesets/UI/DrawableRuleset.cs +++ b/osu.Game/Rulesets/UI/DrawableRuleset.cs @@ -50,6 +50,7 @@ public abstract class DrawableRuleset : DrawableRuleset, IProvideCursor /// /// The key conversion input manager for this DrawableRuleset. /// + [Cached] public PassThroughInputManager KeyBindingInputManager; public override double GameplayStartTime => Objects.FirstOrDefault()?.StartTime - 2000 ?? 0; From d62930500298d23419b2f37b0376881f0e6bb573 Mon Sep 17 00:00:00 2001 From: pikokr Date: Tue, 28 Dec 2021 21:47:58 +0900 Subject: [PATCH 03/11] Remove `Cached` attribute from `DrawableRuleset.KeyBindingInputManager` --- osu.Game/Rulesets/UI/DrawableRuleset.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Rulesets/UI/DrawableRuleset.cs b/osu.Game/Rulesets/UI/DrawableRuleset.cs index 30012784a3..29559f5036 100644 --- a/osu.Game/Rulesets/UI/DrawableRuleset.cs +++ b/osu.Game/Rulesets/UI/DrawableRuleset.cs @@ -50,7 +50,6 @@ public abstract class DrawableRuleset : DrawableRuleset, IProvideCursor /// /// The key conversion input manager for this DrawableRuleset. /// - [Cached] public PassThroughInputManager KeyBindingInputManager; public override double GameplayStartTime => Objects.FirstOrDefault()?.StartTime - 2000 ?? 0; From 59b4aea5f9dc22a3cf543bddae589e462a8be383 Mon Sep 17 00:00:00 2001 From: pikokr Date: Tue, 28 Dec 2021 21:52:46 +0900 Subject: [PATCH 04/11] Make method and property name to match class name --- osu.Game.Rulesets.Mania/UI/Column.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 6be36619c7..36473aa900 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -136,22 +136,22 @@ public void OnReleased(KeyBindingReleaseEvent e) { } - private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } + private ManiaInputManager.RulesetKeyBindingContainer rulesetKeyBindingContainer { get; set; } - private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingManager() + private ManiaInputManager.RulesetKeyBindingContainer getRulesetKeyBindingContainer() { - return keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); + return rulesetKeyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); } protected override bool OnTouchDown(TouchDownEvent e) { - getKeyBindingManager().TriggerPressed(Action.Value); + getRulesetKeyBindingContainer().TriggerPressed(Action.Value); return base.OnTouchDown(e); } protected override void OnTouchUp(TouchUpEvent e) { - getKeyBindingManager().TriggerReleased(Action.Value); + getRulesetKeyBindingContainer().TriggerReleased(Action.Value); } public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) From 62d6bb8c2e9c8a6e10a318599a7ad04974d55e76 Mon Sep 17 00:00:00 2001 From: pikokr Date: Tue, 28 Dec 2021 22:35:45 +0900 Subject: [PATCH 05/11] Trigger touch on click key area --- osu.Game.Rulesets.Mania/UI/Column.cs | 18 ------------- .../UI/Components/DefaultKeyArea.cs | 25 +++++++++++++++++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 36473aa900..9d060944cd 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -136,24 +136,6 @@ public void OnReleased(KeyBindingReleaseEvent e) { } - private ManiaInputManager.RulesetKeyBindingContainer rulesetKeyBindingContainer { get; set; } - - private ManiaInputManager.RulesetKeyBindingContainer getRulesetKeyBindingContainer() - { - return rulesetKeyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); - } - - protected override bool OnTouchDown(TouchDownEvent e) - { - getRulesetKeyBindingContainer().TriggerPressed(Action.Value); - return base.OnTouchDown(e); - } - - protected override void OnTouchUp(TouchUpEvent e) - { - getRulesetKeyBindingContainer().TriggerReleased(Action.Value); - } - public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) // This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border => DrawRectangle.Inflate(new Vector2(Stage.COLUMN_SPACING / 2, 0)).Contains(ToLocalSpace(screenSpacePos)); diff --git a/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs b/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs index 267ed1f5f4..4e0bb71514 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs @@ -36,10 +36,31 @@ public DefaultKeyArea() RelativeSizeAxes = Axes.Both; } + public class ChildContainer : Container + { + private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } + + private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingContainer() + { + return keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); + } + + protected override bool OnTouchDown(TouchDownEvent e) + { + getKeyBindingContainer().TriggerPressed(((DefaultKeyArea)Parent).column.Action.Value); + return base.OnTouchDown(e); + } + + protected override void OnTouchUp(TouchUpEvent e) + { + getKeyBindingContainer().TriggerReleased(((DefaultKeyArea)Parent).column.Action.Value); + } + } + [BackgroundDependencyLoader] private void load(IScrollingInfo scrollingInfo) { - InternalChild = directionContainer = new Container + InternalChild = directionContainer = new ChildContainer { RelativeSizeAxes = Axes.X, Height = Stage.HIT_TARGET_POSITION, @@ -69,7 +90,7 @@ private void load(IScrollingInfo scrollingInfo) AlwaysPresent = true } } - } + }, } }; From dec1f317494c73bbb4313d7be2f1cadb5fde488c Mon Sep 17 00:00:00 2001 From: pikokr Date: Tue, 28 Dec 2021 22:43:07 +0900 Subject: [PATCH 06/11] Make `KeyBindingContainer` public --- osu.Game.Rulesets.Mania/ManiaInputManager.cs | 5 ----- osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs | 2 +- osu.Game/Rulesets/UI/RulesetInputManager.cs | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaInputManager.cs b/osu.Game.Rulesets.Mania/ManiaInputManager.cs index bf94735077..186fc4b15d 100644 --- a/osu.Game.Rulesets.Mania/ManiaInputManager.cs +++ b/osu.Game.Rulesets.Mania/ManiaInputManager.cs @@ -13,11 +13,6 @@ public ManiaInputManager(RulesetInfo ruleset, int variant) : base(ruleset, variant, SimultaneousBindingMode.Unique) { } - - public RulesetKeyBindingContainer GetKeyBindingContainer() - { - return (RulesetKeyBindingContainer)KeyBindingContainer; - } } public enum ManiaAction diff --git a/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs b/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs index 4e0bb71514..b3a2a97bf7 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs @@ -42,7 +42,7 @@ public class ChildContainer : Container private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingContainer() { - return keyBindingContainer ??= ((ManiaInputManager)GetContainingInputManager()).GetKeyBindingContainer(); + return keyBindingContainer ??= (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; } protected override bool OnTouchDown(TouchDownEvent e) diff --git a/osu.Game/Rulesets/UI/RulesetInputManager.cs b/osu.Game/Rulesets/UI/RulesetInputManager.cs index 6564ff9e23..6ef99f8aae 100644 --- a/osu.Game/Rulesets/UI/RulesetInputManager.cs +++ b/osu.Game/Rulesets/UI/RulesetInputManager.cs @@ -43,7 +43,7 @@ public ReplayRecorder Recorder protected override InputState CreateInitialState() => new RulesetInputManagerInputState(base.CreateInitialState()); - protected readonly KeyBindingContainer KeyBindingContainer; + public readonly KeyBindingContainer KeyBindingContainer; protected override Container Content => content; From 4cb8272d14369fb7a129d5ec3997b92a14e14867 Mon Sep 17 00:00:00 2001 From: pikokr Date: Thu, 30 Dec 2021 17:37:14 +0900 Subject: [PATCH 07/11] Column Touch area & highlighting on start --- osu.Game.Rulesets.Mania/UI/Column.cs | 60 ++++++++++++++++++- .../UI/Components/DefaultKeyArea.cs | 23 +------ 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 9d060944cd..1e07c84d9f 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -44,6 +44,63 @@ public class Column : ScrollingPlayfield, IKeyBindingHandler, IHasA private readonly GameplaySampleTriggerSource sampleTriggerSource; + public class ColumnTouchInputArea : Container + { + private Column column => (Column)Parent; + + private Container hintContainer; + + public ColumnTouchInputArea() + { + RelativeSizeAxes = Axes.X; + Anchor = Anchor.BottomCentre; + Origin = Anchor.BottomCentre; + Height = 100; + InternalChild = hintContainer = new Container + { + RelativeSizeAxes = Axes.Both, + BorderColour = Color4.Red, + BorderThickness = 5, + Masking = true, + }; + } + + protected override void LoadComplete() + { + hintContainer.Delay(1000).FadeOutFromOne(500, Easing.OutSine); + } + + private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } + + private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingContainer() + { + return keyBindingContainer ??= (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; + } + + protected override bool OnTouchDown(TouchDownEvent e) + { + getKeyBindingContainer().TriggerPressed(column.Action.Value); + return base.OnTouchDown(e); + } + + protected override bool OnMouseDown(MouseDownEvent e) + { + getKeyBindingContainer().TriggerPressed(column.Action.Value); + + return base.OnMouseDown(e); + } + + protected override void OnMouseUp(MouseUpEvent e) + { + getKeyBindingContainer().TriggerReleased(column.Action.Value); + } + + protected override void OnTouchUp(TouchUpEvent e) + { + getKeyBindingContainer().TriggerReleased(column.Action.Value); + } + } + public Column(int index) { Index = index; @@ -68,7 +125,8 @@ public Column(int index) RelativeSizeAxes = Axes.Both }, background, - TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both } + TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }, + new ColumnTouchInputArea() }; hitPolicy = new OrderedHitPolicy(HitObjectContainer); diff --git a/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs b/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs index b3a2a97bf7..15018b464f 100644 --- a/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs +++ b/osu.Game.Rulesets.Mania/UI/Components/DefaultKeyArea.cs @@ -36,31 +36,10 @@ public DefaultKeyArea() RelativeSizeAxes = Axes.Both; } - public class ChildContainer : Container - { - private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } - - private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingContainer() - { - return keyBindingContainer ??= (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; - } - - protected override bool OnTouchDown(TouchDownEvent e) - { - getKeyBindingContainer().TriggerPressed(((DefaultKeyArea)Parent).column.Action.Value); - return base.OnTouchDown(e); - } - - protected override void OnTouchUp(TouchUpEvent e) - { - getKeyBindingContainer().TriggerReleased(((DefaultKeyArea)Parent).column.Action.Value); - } - } - [BackgroundDependencyLoader] private void load(IScrollingInfo scrollingInfo) { - InternalChild = directionContainer = new ChildContainer + InternalChild = directionContainer = new Container { RelativeSizeAxes = Axes.X, Height = Stage.HIT_TARGET_POSITION, From b0d61a18b05424bdc5b39b248a36c5d139ad241c Mon Sep 17 00:00:00 2001 From: pikokr Date: Fri, 7 Jan 2022 15:57:30 +0900 Subject: [PATCH 08/11] Load keyBindingContainer once on LoadComplete() & make touch area height to const --- osu.Game.Rulesets.Mania/UI/Column.cs | 43 ++++++---------------------- 1 file changed, 9 insertions(+), 34 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 1e07c84d9f..cd5f3d2170 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -28,6 +28,7 @@ public class Column : ScrollingPlayfield, IKeyBindingHandler, IHasA { public const float COLUMN_WIDTH = 80; public const float SPECIAL_COLUMN_WIDTH = 70; + public const float TOUCH_AREA_HEIGHT = 100; /// /// The index of this column as part of the whole playfield. @@ -44,60 +45,34 @@ public class Column : ScrollingPlayfield, IKeyBindingHandler, IHasA private readonly GameplaySampleTriggerSource sampleTriggerSource; - public class ColumnTouchInputArea : Container + public class ColumnTouchInputArea : Drawable { - private Column column => (Column)Parent; - - private Container hintContainer; - public ColumnTouchInputArea() { RelativeSizeAxes = Axes.X; Anchor = Anchor.BottomCentre; Origin = Anchor.BottomCentre; - Height = 100; - InternalChild = hintContainer = new Container - { - RelativeSizeAxes = Axes.Both, - BorderColour = Color4.Red, - BorderThickness = 5, - Masking = true, - }; + Height = TOUCH_AREA_HEIGHT; } + private Column column => (Column)Parent; + protected override void LoadComplete() { - hintContainer.Delay(1000).FadeOutFromOne(500, Easing.OutSine); + keyBindingContainer = (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; } private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } - private ManiaInputManager.RulesetKeyBindingContainer getKeyBindingContainer() - { - return keyBindingContainer ??= (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; - } - protected override bool OnTouchDown(TouchDownEvent e) { - getKeyBindingContainer().TriggerPressed(column.Action.Value); - return base.OnTouchDown(e); - } - - protected override bool OnMouseDown(MouseDownEvent e) - { - getKeyBindingContainer().TriggerPressed(column.Action.Value); - - return base.OnMouseDown(e); - } - - protected override void OnMouseUp(MouseUpEvent e) - { - getKeyBindingContainer().TriggerReleased(column.Action.Value); + keyBindingContainer.TriggerPressed(column.Action.Value); + return false; } protected override void OnTouchUp(TouchUpEvent e) { - getKeyBindingContainer().TriggerReleased(column.Action.Value); + keyBindingContainer.TriggerReleased(column.Action.Value); } } From cc7fb0e559b096566b2874607f2ff5f57ca8e0e3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 31 Jan 2022 16:36:56 +0900 Subject: [PATCH 09/11] Add mouse click support and increase area to full column height --- osu.Game.Rulesets.Mania/UI/Column.cs | 72 +++++++++++++++------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index cd5f3d2170..9bcd9ad853 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -28,7 +28,6 @@ public class Column : ScrollingPlayfield, IKeyBindingHandler, IHasA { public const float COLUMN_WIDTH = 80; public const float SPECIAL_COLUMN_WIDTH = 70; - public const float TOUCH_AREA_HEIGHT = 100; /// /// The index of this column as part of the whole playfield. @@ -45,37 +44,6 @@ public class Column : ScrollingPlayfield, IKeyBindingHandler, IHasA private readonly GameplaySampleTriggerSource sampleTriggerSource; - public class ColumnTouchInputArea : Drawable - { - public ColumnTouchInputArea() - { - RelativeSizeAxes = Axes.X; - Anchor = Anchor.BottomCentre; - Origin = Anchor.BottomCentre; - Height = TOUCH_AREA_HEIGHT; - } - - private Column column => (Column)Parent; - - protected override void LoadComplete() - { - keyBindingContainer = (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; - } - - private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } - - protected override bool OnTouchDown(TouchDownEvent e) - { - keyBindingContainer.TriggerPressed(column.Action.Value); - return false; - } - - protected override void OnTouchUp(TouchUpEvent e) - { - keyBindingContainer.TriggerReleased(column.Action.Value); - } - } - public Column(int index) { Index = index; @@ -172,5 +140,45 @@ public void OnReleased(KeyBindingReleaseEvent e) public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) // This probably shouldn't exist as is, but the columns in the stage are separated by a 1px border => DrawRectangle.Inflate(new Vector2(Stage.COLUMN_SPACING / 2, 0)).Contains(ToLocalSpace(screenSpacePos)); + + public class ColumnTouchInputArea : Drawable + { + public ColumnTouchInputArea() + { + RelativeSizeAxes = Axes.Both; + } + + private Column column => (Column)Parent; + + protected override void LoadComplete() + { + keyBindingContainer = (ManiaInputManager.RulesetKeyBindingContainer)((ManiaInputManager)GetContainingInputManager()).KeyBindingContainer; + } + + private ManiaInputManager.RulesetKeyBindingContainer keyBindingContainer { get; set; } + + protected override bool OnMouseDown(MouseDownEvent e) + { + keyBindingContainer.TriggerPressed(column.Action.Value); + return base.OnMouseDown(e); + } + + protected override void OnMouseUp(MouseUpEvent e) + { + keyBindingContainer.TriggerReleased(column.Action.Value); + base.OnMouseUp(e); + } + + protected override bool OnTouchDown(TouchDownEvent e) + { + keyBindingContainer.TriggerPressed(column.Action.Value); + return true; + } + + protected override void OnTouchUp(TouchUpEvent e) + { + keyBindingContainer.TriggerReleased(column.Action.Value); + } + } } } From 0e764538e0ea81293ef99994b25e3ab7ceed609e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 31 Jan 2022 16:47:20 +0900 Subject: [PATCH 10/11] Retrieve `KeyBindingContainer` via DI rather than traversal lookup --- osu.Game.Rulesets.Mania/ManiaInputManager.cs | 2 ++ osu.Game.Rulesets.Mania/UI/Column.cs | 17 ++++++++++------- osu.Game/Rulesets/UI/RulesetInputManager.cs | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaInputManager.cs b/osu.Game.Rulesets.Mania/ManiaInputManager.cs index 186fc4b15d..14ca27a11a 100644 --- a/osu.Game.Rulesets.Mania/ManiaInputManager.cs +++ b/osu.Game.Rulesets.Mania/ManiaInputManager.cs @@ -2,11 +2,13 @@ // See the LICENCE file in the repository root for full licence text. using System.ComponentModel; +using osu.Framework.Allocation; using osu.Framework.Input.Bindings; using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mania { + [Cached] // Used for touch input, see ColumnTouchInputArea. public class ManiaInputManager : RulesetInputManager { public ManiaInputManager(RulesetInfo ruleset, int variant) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index 9bcd9ad853..a6c64e9b2d 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -143,6 +143,11 @@ public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) public class ColumnTouchInputArea : Drawable { + [Resolved(canBeNull: true)] + private ManiaInputManager maniaInputManager { get; set; } + + private KeyBindingContainer keyBindingContainer; + public ColumnTouchInputArea() { RelativeSizeAxes = Axes.Both; @@ -152,32 +157,30 @@ public ColumnTouchInputArea() 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) { - keyBindingContainer.TriggerPressed(column.Action.Value); + keyBindingContainer?.TriggerPressed(column.Action.Value); return base.OnMouseDown(e); } protected override void OnMouseUp(MouseUpEvent e) { - keyBindingContainer.TriggerReleased(column.Action.Value); + keyBindingContainer?.TriggerReleased(column.Action.Value); base.OnMouseUp(e); } protected override bool OnTouchDown(TouchDownEvent e) { - keyBindingContainer.TriggerPressed(column.Action.Value); + keyBindingContainer?.TriggerPressed(column.Action.Value); return true; } protected override void OnTouchUp(TouchUpEvent e) { - keyBindingContainer.TriggerReleased(column.Action.Value); + keyBindingContainer?.TriggerReleased(column.Action.Value); } } } diff --git a/osu.Game/Rulesets/UI/RulesetInputManager.cs b/osu.Game/Rulesets/UI/RulesetInputManager.cs index 160c0a2606..84e42818be 100644 --- a/osu.Game/Rulesets/UI/RulesetInputManager.cs +++ b/osu.Game/Rulesets/UI/RulesetInputManager.cs @@ -24,6 +24,8 @@ namespace osu.Game.Rulesets.UI public abstract class RulesetInputManager : PassThroughInputManager, ICanAttachKeyCounter, IHasReplayHandler, IHasRecordingHandler where T : struct { + public readonly KeyBindingContainer KeyBindingContainer; + private ReplayRecorder recorder; public ReplayRecorder Recorder @@ -43,8 +45,6 @@ public ReplayRecorder Recorder protected override InputState CreateInitialState() => new RulesetInputManagerInputState(base.CreateInitialState()); - public readonly KeyBindingContainer KeyBindingContainer; - protected override Container Content => content; private readonly Container content; From 2f88efd3c3c2f66f0bc8104f737cbc532527251f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 1 Feb 2022 00:53:56 +0900 Subject: [PATCH 11/11] Pass column in rather than accessing parent --- osu.Game.Rulesets.Mania/UI/Column.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index a6c64e9b2d..dc3b86ac7f 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -69,7 +69,7 @@ public Column(int index) }, background, TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }, - new ColumnTouchInputArea() + new ColumnTouchInputArea(this) }; hitPolicy = new OrderedHitPolicy(HitObjectContainer); @@ -143,17 +143,19 @@ public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) public class ColumnTouchInputArea : Drawable { + private readonly Column column; + [Resolved(canBeNull: true)] private ManiaInputManager maniaInputManager { get; set; } private KeyBindingContainer keyBindingContainer; - public ColumnTouchInputArea() + public ColumnTouchInputArea(Column column) { RelativeSizeAxes = Axes.Both; - } - private Column column => (Column)Parent; + this.column = column; + } protected override void LoadComplete() {