From 5c9a90cb40320cf2f22e4b6ba9f94a7ab0d4e632 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 14 May 2024 19:28:14 +0800 Subject: [PATCH] Tidy class and change to be a `VisibilityContainer` similar to taiko implementation --- .../Mods/TestSceneModTouchDevice.cs | 11 ++-- .../UI/DrawableManiaRuleset.cs | 7 +-- .../UI/ManiaTouchInputArea.cs | 54 +++++++++++++++---- 3 files changed, 50 insertions(+), 22 deletions(-) diff --git a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneModTouchDevice.cs b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneModTouchDevice.cs index 829cd0b62e..451cb617ee 100644 --- a/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneModTouchDevice.cs +++ b/osu.Game.Rulesets.Mania.Tests/Mods/TestSceneModTouchDevice.cs @@ -3,12 +3,10 @@ using System.Linq; using NUnit.Framework; -using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.Testing; using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mods; -using osu.Game.Skinning; using osu.Game.Tests.Visual; namespace osu.Game.Rulesets.Mania.Tests.Mods @@ -22,14 +20,14 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods { Mod = new ModTouchDevice(), Autoplay = false, - PassCondition = () => getSkinnableOverlay()?.IsPresent == true + PassCondition = () => getTouchOverlay()?.IsPresent == true }); [Test] public void TestOverlayNotVisibleWithoutMod() => CreateModTest(new ModTestData { Autoplay = false, - PassCondition = () => getSkinnableOverlay()?.IsPresent == false + PassCondition = () => getTouchOverlay()?.IsPresent == false }); [Test] @@ -56,9 +54,8 @@ namespace osu.Game.Rulesets.Mania.Tests.Mods } } - private Drawable? getSkinnableOverlay() => this.ChildrenOfType() - .SingleOrDefault(d => d.Lookup.Equals(new ManiaSkinComponentLookup(ManiaSkinComponents.TouchOverlay))); + private ManiaTouchInputArea? getTouchOverlay() => this.ChildrenOfType().SingleOrDefault(); - private ManiaTouchInputArea.InputReceptor getReceptor(int index) => this.ChildrenOfType().ElementAt(index); + private ManiaTouchInputArea.ColumnInputReceptor getReceptor(int index) => this.ChildrenOfType().ElementAt(index); } } diff --git a/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs b/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs index 5974b76d65..ce53862c76 100644 --- a/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs @@ -105,10 +105,7 @@ namespace osu.Game.Rulesets.Mania.UI TimeRange.Value = smoothTimeRange = ComputeScrollTime(configScrollSpeed.Value); - KeyBindingInputManager.Add(touchArea = new ManiaTouchInputArea - { - RelativeSizeAxes = Axes.Both - }); + KeyBindingInputManager.Add(new ManiaTouchInputArea()); } protected override void AdjustScrollSpeed(int amount) => configScrollSpeed.Value += amount; @@ -122,8 +119,6 @@ namespace osu.Game.Rulesets.Mania.UI private ScheduledDelegate? pendingSkinChange; private float hitPosition; - private ManiaTouchInputArea touchArea = null!; - private void onSkinChange() { // schedule required to avoid calls after disposed. diff --git a/osu.Game.Rulesets.Mania/UI/ManiaTouchInputArea.cs b/osu.Game.Rulesets.Mania/UI/ManiaTouchInputArea.cs index 0cb12128e8..32e4616a25 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaTouchInputArea.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaTouchInputArea.cs @@ -9,13 +9,19 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; using osu.Framework.Input.Events; using osu.Game.Configuration; -using osu.Game.Skinning; using osuTK; namespace osu.Game.Rulesets.Mania.UI { - public partial class ManiaTouchInputArea : CompositeDrawable, ISerialisableDrawable + /// + /// An overlay that captures and displays osu!mania mouse and touch input. + /// + public partial class ManiaTouchInputArea : VisibilityContainer { + // visibility state affects our child. we always want to handle input. + public override bool PropagatePositionalInputSubTree => true; + public override bool PropagateNonPositionalInputSubTree => true; + [SettingSource("Spacing", "The spacing between receptors.")] public BindableFloat Spacing { get; } = new BindableFloat(10) { @@ -35,6 +41,8 @@ namespace osu.Game.Rulesets.Mania.UI [Resolved] private DrawableManiaRuleset drawableRuleset { get; set; } = null!; + private GridContainer gridContainer = null!; + public ManiaTouchInputArea() { Anchor = Anchor.BottomCentre; @@ -62,16 +70,17 @@ namespace osu.Game.Rulesets.Mania.UI receptorGridDimensions.Add(new Dimension(GridSizeMode.AutoSize)); } - receptorGridContent.Add(new InputReceptor { Action = { BindTarget = column.Action } }); + receptorGridContent.Add(new ColumnInputReceptor { Action = { BindTarget = column.Action } }); receptorGridDimensions.Add(new Dimension()); first = false; } } - InternalChild = new GridContainer + InternalChild = gridContainer = new GridContainer { RelativeSizeAxes = Axes.Both, + AlwaysPresent = true, Content = new[] { receptorGridContent.ToArray() }, ColumnDimensions = receptorGridDimensions.ToArray() }; @@ -83,9 +92,36 @@ namespace osu.Game.Rulesets.Mania.UI Opacity.BindValueChanged(o => Alpha = o.NewValue, true); } - public bool UsesFixedAnchor { get; set; } + protected override bool OnKeyDown(KeyDownEvent e) + { + // Hide whenever the keyboard is used. + Hide(); + return false; + } - public partial class InputReceptor : CompositeDrawable + protected override bool OnMouseDown(MouseDownEvent e) + { + Show(); + return true; + } + + protected override bool OnTouchDown(TouchDownEvent e) + { + Show(); + return true; + } + + protected override void PopIn() + { + gridContainer.FadeIn(500, Easing.OutQuint); + } + + protected override void PopOut() + { + gridContainer.FadeOut(300); + } + + public partial class ColumnInputReceptor : CompositeDrawable { public readonly IBindable Action = new Bindable(); @@ -96,7 +132,7 @@ namespace osu.Game.Rulesets.Mania.UI private bool isPressed; - public InputReceptor() + public ColumnInputReceptor() { RelativeSizeAxes = Axes.Both; @@ -128,7 +164,7 @@ namespace osu.Game.Rulesets.Mania.UI protected override bool OnTouchDown(TouchDownEvent e) { updateButton(true); - return true; + return false; // handled by parent container to show overlay. } protected override void OnTouchUp(TouchUpEvent e) @@ -139,7 +175,7 @@ namespace osu.Game.Rulesets.Mania.UI protected override bool OnMouseDown(MouseDownEvent e) { updateButton(true); - return true; + return false; // handled by parent container to show overlay. } protected override void OnMouseUp(MouseUpEvent e)