1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:47:29 +08:00

Tidy class and change to be a VisibilityContainer similar to taiko implementation

This commit is contained in:
Dean Herbert 2024-05-14 19:28:14 +08:00
parent 390557634a
commit 5c9a90cb40
No known key found for this signature in database
3 changed files with 50 additions and 22 deletions

View File

@ -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<SkinnableDrawable>()
.SingleOrDefault(d => d.Lookup.Equals(new ManiaSkinComponentLookup(ManiaSkinComponents.TouchOverlay)));
private ManiaTouchInputArea? getTouchOverlay() => this.ChildrenOfType<ManiaTouchInputArea>().SingleOrDefault();
private ManiaTouchInputArea.InputReceptor getReceptor(int index) => this.ChildrenOfType<ManiaTouchInputArea.InputReceptor>().ElementAt(index);
private ManiaTouchInputArea.ColumnInputReceptor getReceptor(int index) => this.ChildrenOfType<ManiaTouchInputArea.ColumnInputReceptor>().ElementAt(index);
}
}

View File

@ -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.

View File

@ -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
/// <summary>
/// An overlay that captures and displays osu!mania mouse and touch input.
/// </summary>
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<ManiaAction> Action = new Bindable<ManiaAction>();
@ -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)