2024-06-23 13:22:13 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2024-07-26 22:45:12 +08:00
|
|
|
using System.Linq;
|
2024-06-23 13:22:13 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-08-21 02:22:03 +08:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-06-23 13:22:13 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Mods;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2024-07-26 22:45:12 +08:00
|
|
|
using osuTK;
|
2024-08-06 18:25:23 +08:00
|
|
|
using osuTK.Input;
|
2024-06-23 13:22:13 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public partial class TestSceneModCustomisationPanel : OsuManualInputManagerTestScene
|
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine);
|
|
|
|
|
2024-07-03 17:03:52 +08:00
|
|
|
private ModCustomisationPanel panel = null!;
|
2024-07-26 22:45:12 +08:00
|
|
|
private ModCustomisationHeader header = null!;
|
|
|
|
private Container content = null!;
|
2024-07-03 17:03:52 +08:00
|
|
|
|
2024-06-23 13:22:13 +08:00
|
|
|
[SetUp]
|
|
|
|
public void SetUp() => Schedule(() =>
|
|
|
|
{
|
2024-08-06 18:25:23 +08:00
|
|
|
SelectedMods.Value = Array.Empty<Mod>();
|
|
|
|
InputManager.MoveMouseTo(Vector2.One);
|
|
|
|
|
2024-06-23 13:22:13 +08:00
|
|
|
Child = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(20f),
|
2024-07-03 17:03:52 +08:00
|
|
|
Child = panel = new ModCustomisationPanel
|
2024-06-23 13:22:13 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Width = 400f,
|
2024-06-28 13:52:52 +08:00
|
|
|
State = { Value = Visibility.Visible },
|
2024-06-23 13:22:13 +08:00
|
|
|
SelectedMods = { BindTarget = SelectedMods },
|
|
|
|
}
|
|
|
|
};
|
2024-07-26 22:45:12 +08:00
|
|
|
|
|
|
|
header = panel.Children.OfType<ModCustomisationHeader>().First();
|
|
|
|
content = panel.Children.OfType<Container>().First();
|
2024-06-23 13:22:13 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestDisplay()
|
|
|
|
{
|
2024-07-03 17:03:52 +08:00
|
|
|
AddStep("set DT", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = new[] { new OsuModDoubleTime() };
|
2024-08-07 20:01:30 +08:00
|
|
|
panel.Enabled.Value = true;
|
2024-08-28 16:09:47 +08:00
|
|
|
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
|
2024-07-03 17:03:52 +08:00
|
|
|
});
|
|
|
|
AddStep("set DA", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = new Mod[] { new OsuModDifficultyAdjust() };
|
2024-08-07 20:01:30 +08:00
|
|
|
panel.Enabled.Value = true;
|
2024-08-28 16:09:47 +08:00
|
|
|
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
|
2024-07-03 17:03:52 +08:00
|
|
|
});
|
|
|
|
AddStep("set FL+WU+DA+AD", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = new Mod[] { new OsuModFlashlight(), new ModWindUp(), new OsuModDifficultyAdjust(), new OsuModApproachDifferent() };
|
2024-08-07 20:01:30 +08:00
|
|
|
panel.Enabled.Value = true;
|
2024-08-28 16:09:47 +08:00
|
|
|
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.ExpandedByMod;
|
2024-07-03 17:03:52 +08:00
|
|
|
});
|
|
|
|
AddStep("set empty", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = Array.Empty<Mod>();
|
2024-08-07 20:01:30 +08:00
|
|
|
panel.Enabled.Value = false;
|
|
|
|
panel.ExpandedState.Value = ModCustomisationPanel.ModCustomisationPanelState.Collapsed;
|
2024-07-03 17:03:52 +08:00
|
|
|
});
|
2024-06-23 13:22:13 +08:00
|
|
|
}
|
2024-07-26 22:45:12 +08:00
|
|
|
|
|
|
|
[Test]
|
2024-08-06 18:25:23 +08:00
|
|
|
public void TestHoverDoesNotExpandWhenNoCustomisableMods()
|
2024-07-26 22:45:12 +08:00
|
|
|
{
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("hover header", () => InputManager.MoveMouseTo(header));
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
checkExpanded(false);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("hover content", () => InputManager.MoveMouseTo(content));
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
checkExpanded(false);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("left from content", () => InputManager.MoveMouseTo(Vector2.One));
|
|
|
|
}
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
[Test]
|
|
|
|
public void TestHoverExpandsWithCustomisableMods()
|
|
|
|
{
|
2024-07-26 22:45:12 +08:00
|
|
|
AddStep("add customisable mod", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = new[] { new OsuModDoubleTime() };
|
|
|
|
panel.Enabled.Value = true;
|
|
|
|
});
|
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("hover header", () => InputManager.MoveMouseTo(header));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("move to content", () => InputManager.MoveMouseTo(content));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
|
|
|
|
checkExpanded(false);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("hover header", () => InputManager.MoveMouseTo(header));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
|
|
|
|
checkExpanded(false);
|
|
|
|
}
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
[Test]
|
|
|
|
public void TestExpandedStatePersistsWhenClicked()
|
|
|
|
{
|
|
|
|
AddStep("add customisable mod", () =>
|
2024-07-26 22:45:12 +08:00
|
|
|
{
|
2024-08-06 18:25:23 +08:00
|
|
|
SelectedMods.Value = new[] { new OsuModDoubleTime() };
|
|
|
|
panel.Enabled.Value = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("hover header", () => InputManager.MoveMouseTo(header));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkExpanded(false);
|
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("move away", () => InputManager.MoveMouseTo(Vector2.One));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkExpanded(false);
|
|
|
|
}
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
[Test]
|
|
|
|
public void TestHoverExpandsAndCollapsesWhenHeaderClicked()
|
|
|
|
{
|
|
|
|
AddStep("add customisable mod", () =>
|
2024-07-26 22:45:12 +08:00
|
|
|
{
|
2024-08-06 18:25:23 +08:00
|
|
|
SelectedMods.Value = new[] { new OsuModDoubleTime() };
|
|
|
|
panel.Enabled.Value = true;
|
|
|
|
});
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("hover header", () => InputManager.MoveMouseTo(header));
|
|
|
|
checkExpanded(true);
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
AddStep("click", () => InputManager.Click(MouseButton.Left));
|
|
|
|
checkExpanded(false);
|
|
|
|
}
|
2024-07-26 22:45:12 +08:00
|
|
|
|
2024-08-21 02:22:03 +08:00
|
|
|
[Test]
|
|
|
|
public void TestDraggingKeepsPanelExpanded()
|
|
|
|
{
|
|
|
|
AddStep("add customisable mod", () =>
|
|
|
|
{
|
|
|
|
SelectedMods.Value = new[] { new OsuModDoubleTime() };
|
|
|
|
panel.Enabled.Value = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("hover header", () => InputManager.MoveMouseTo(header));
|
|
|
|
checkExpanded(true);
|
|
|
|
|
|
|
|
AddStep("hover slider bar nub", () => InputManager.MoveMouseTo(panel.ChildrenOfType<OsuSliderBar<double>>().First().ChildrenOfType<Nub>().Single()));
|
|
|
|
AddStep("hold", () => InputManager.PressButton(MouseButton.Left));
|
|
|
|
AddStep("drag outside", () => InputManager.MoveMouseTo(Vector2.Zero));
|
|
|
|
checkExpanded(true);
|
|
|
|
|
|
|
|
AddStep("release", () => InputManager.ReleaseButton(MouseButton.Left));
|
|
|
|
checkExpanded(false);
|
|
|
|
}
|
|
|
|
|
2024-08-06 18:25:23 +08:00
|
|
|
private void checkExpanded(bool expanded)
|
|
|
|
{
|
2024-08-07 20:01:30 +08:00
|
|
|
AddUntilStep(expanded ? "is expanded" : "not expanded", () => panel.ExpandedState.Value,
|
|
|
|
() => expanded ? Is.Not.EqualTo(ModCustomisationPanel.ModCustomisationPanelState.Collapsed) : Is.EqualTo(ModCustomisationPanel.ModCustomisationPanelState.Collapsed));
|
2024-07-26 22:45:12 +08:00
|
|
|
}
|
2024-06-23 13:22:13 +08:00
|
|
|
}
|
|
|
|
}
|