Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hover to expand mod customise panel #29136

Merged
merged 17 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
Expand All @@ -10,6 +11,7 @@
using osu.Game.Overlays.Mods;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osuTK;

namespace osu.Game.Tests.Visual.UserInterface
{
Expand All @@ -19,6 +21,8 @@ public partial class TestSceneModCustomisationPanel : OsuManualInputManagerTestS
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);

private ModCustomisationPanel panel = null!;
private ModCustomisationHeader header = null!;
private Container content = null!;

[SetUp]
public void SetUp() => Schedule(() =>
Expand All @@ -36,6 +40,9 @@ public void SetUp() => Schedule(() =>
SelectedMods = { BindTarget = SelectedMods },
}
};

header = panel.Children.OfType<ModCustomisationHeader>().First();
content = panel.Children.OfType<Container>().First();
});

[Test]
Expand All @@ -62,5 +69,68 @@ public void TestDisplay()
panel.Enabled.Value = panel.Expanded.Value = false;
});
}

[Test]
public void TestHoverExpand()
{
// Can not expand by hovering when no supported mod
{
AddStep("hover header", () => InputManager.MoveMouseTo(header));

AddAssert("not expanded", () => !panel.Expanded.Value);

AddStep("hover content", () => InputManager.MoveMouseTo(content));

AddAssert("neither expanded", () => !panel.Expanded.Value);

AddStep("left from content", () => InputManager.MoveMouseTo(Vector2.One));
}

AddStep("add customisable mod", () =>
{
SelectedMods.Value = new[] { new OsuModDoubleTime() };
panel.Enabled.Value = true;
});

// Can expand by hovering when supported mod
{
AddStep("hover header", () => InputManager.MoveMouseTo(header));

AddAssert("expanded", () => panel.Expanded.Value);

AddStep("hover content", () => InputManager.MoveMouseTo(content));

AddAssert("still expanded", () => panel.Expanded.Value);
}

// Will collapse when mouse left from content
{
AddStep("left from content", () => InputManager.MoveMouseTo(Vector2.One));

AddAssert("not expanded", () => !panel.Expanded.Value);
}

// Will collapse when mouse left from header
{
AddStep("hover header", () => InputManager.MoveMouseTo(header));

AddAssert("expanded", () => panel.Expanded.Value);

AddStep("left from header", () => InputManager.MoveMouseTo(Vector2.One));

AddAssert("not expanded", () => !panel.Expanded.Value);
}

// Not collapse when mouse left if not expanded by hovering
{
AddStep("expand not by hovering", () => panel.Expanded.Value = true);

AddStep("hover content", () => InputManager.MoveMouseTo(content));

AddStep("moust left", () => InputManager.MoveMouseTo(Vector2.One));

AddAssert("still expanded", () => panel.Expanded.Value);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void SetUpSteps()
AddStep("reset ruleset", () => Ruleset.Value = rulesetStore.GetRuleset(0));
AddStep("reset mods", () => SelectedMods.SetDefault());
AddStep("reset config", () => configManager.SetValue(OsuSetting.ModSelectTextSearchStartsActive, true));
AddStep("reset mouse", () => InputManager.MoveMouseTo(Vector2.One));
AddStep("set beatmap", () => Beatmap.Value = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo));
AddStep("set up presets", () =>
{
Expand Down
27 changes: 27 additions & 0 deletions osu.Game/Overlays/Mods/ModCustomisationHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
Expand All @@ -28,6 +29,8 @@ public partial class ModCustomisationHeader : OsuHoverContainer

public readonly BindableBool Expanded = new BindableBool();

protected new ModCustomisationPanel? Parent => (ModCustomisationPanel?)base.Parent;
bdach marked this conversation as resolved.
Show resolved Hide resolved

public ModCustomisationHeader()
{
Action = Expanded.Toggle;
Expand Down Expand Up @@ -91,5 +94,29 @@ protected override void LoadComplete()
icon.ScaleTo(v.NewValue ? new Vector2(1, -1) : Vector2.One, 300, Easing.OutQuint);
}, true);
}

private bool touchedThisFrame;

protected override bool OnTouchDown(TouchDownEvent e)
{
if (Enabled.Value)
{
touchedThisFrame = true;
Schedule(() => touchedThisFrame = false);
}

return base.OnTouchDown(e);
}

protected override bool OnHover(HoverEvent e)
{
if (Enabled.Value)
{
if (!touchedThisFrame)
Parent?.UpdateHoverExpansion(true);
}

return base.OnHover(e);
}
}
}
32 changes: 32 additions & 0 deletions osu.Game/Overlays/Mods/ModCustomisationPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
Expand Down Expand Up @@ -81,6 +82,7 @@ private void load()
Colour = Color4.Black.Opacity(0.25f),
},
Expanded = { BindTarget = Expanded },
ExpandedByHovering = { BindTarget = ExpandedByHovering },
Children = new Drawable[]
{
new Box
Expand Down Expand Up @@ -175,6 +177,25 @@ private void updateDisplay()
content.ResizeHeightTo(header_height, 400, Easing.OutQuint);
content.FadeOut(400, Easing.OutSine);
}

ExpandedByHovering.Value = false;
}

public readonly BindableBool ExpandedByHovering = new BindableBool();
bdach marked this conversation as resolved.
Show resolved Hide resolved

public void UpdateHoverExpansion(bool hovered)
{
if (hovered && !Expanded.Value)
{
Expanded.Value = true;
ExpandedByHovering.Value = true;
}
else if (!hovered && ExpandedByHovering.Value)
{
Debug.Assert(Expanded.Value);

Expanded.Value = false;
}
}

private void updateMods()
Expand Down Expand Up @@ -203,9 +224,20 @@ protected override void Update()
private partial class FocusGrabbingContainer : InputBlockingContainer
{
public IBindable<bool> Expanded { get; } = new BindableBool();
public IBindable<bool> ExpandedByHovering { get; } = new BindableBool();

public override bool RequestsFocus => Expanded.Value;
public override bool AcceptsFocus => Expanded.Value;

public new ModCustomisationPanel? Parent => (ModCustomisationPanel?)base.Parent;
bdach marked this conversation as resolved.
Show resolved Hide resolved

protected override void OnHoverLost(HoverLostEvent e)
{
if (ExpandedByHovering.Value && !ReceivePositionalInputAt(e.ScreenSpaceMousePosition))
Parent?.UpdateHoverExpansion(false);

base.OnHoverLost(e);
}
}
}
}
Loading