Skip to content

Commit

Permalink
Tidy class and change to be a VisibilityContainer similar to taiko …
Browse files Browse the repository at this point in the history
…implementation
  • Loading branch information
peppy committed May 14, 2024
1 parent 4335158 commit a67bc51
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
11 changes: 4 additions & 7 deletions osu.Game.Rulesets.Mania.Tests/Mods/TestSceneModTouchDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,14 +20,14 @@ public partial class TestSceneModTouchDevice : ModTestScene
{
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]
Expand All @@ -56,9 +54,8 @@ public void TestPressReceptors()
}
}

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);
}
}
7 changes: 1 addition & 6 deletions osu.Game.Rulesets.Mania/UI/DrawableManiaRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ private void load(ISkinSource source)

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;
Expand All @@ -122,8 +119,6 @@ protected override void Update()
private ScheduledDelegate? pendingSkinChange;
private float hitPosition;

private ManiaTouchInputArea touchArea = null!;

private void onSkinChange()
{
// schedule required to avoid calls after disposed.
Expand Down
54 changes: 45 additions & 9 deletions osu.Game.Rulesets.Mania/UI/ManiaTouchInputArea.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@
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)
{
Expand All @@ -35,6 +41,8 @@ public partial class ManiaTouchInputArea : CompositeDrawable, ISerialisableDrawa
[Resolved]
private DrawableManiaRuleset drawableRuleset { get; set; } = null!;

private GridContainer gridContainer = null!;

public ManiaTouchInputArea()
{
Anchor = Anchor.BottomCentre;
Expand Down Expand Up @@ -62,16 +70,17 @@ private void load()
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()
};
Expand All @@ -83,9 +92,36 @@ protected override void LoadComplete()
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;
}

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 InputReceptor : CompositeDrawable
public partial class ColumnInputReceptor : CompositeDrawable
{
public readonly IBindable<ManiaAction> Action = new Bindable<ManiaAction>();

Expand All @@ -96,7 +132,7 @@ public partial class InputReceptor : CompositeDrawable

private bool isPressed;

public InputReceptor()
public ColumnInputReceptor()
{
RelativeSizeAxes = Axes.Both;

Expand Down Expand Up @@ -128,7 +164,7 @@ public InputReceptor()
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)
Expand All @@ -139,7 +175,7 @@ protected override void OnTouchUp(TouchUpEvent e)
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)
Expand Down

0 comments on commit a67bc51

Please sign in to comment.