2022-02-20 00:52:16 +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.
|
|
|
|
|
2022-02-20 20:40:52 +08:00
|
|
|
using System;
|
2022-02-20 20:09:06 +08:00
|
|
|
using System.Linq;
|
2022-02-20 00:52:16 +08:00
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Framework.Allocation;
|
2022-02-20 20:09:06 +08:00
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2022-02-20 00:52:16 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-02-20 20:09:06 +08:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-02-20 00:52:16 +08:00
|
|
|
using osu.Game.Overlays;
|
|
|
|
using osu.Game.Overlays.Mods;
|
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
using osu.Game.Rulesets.Mania;
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
using osu.Game.Rulesets.Taiko;
|
2022-02-20 20:09:06 +08:00
|
|
|
using osuTK.Input;
|
2022-02-20 00:52:16 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2022-02-20 20:09:06 +08:00
|
|
|
public class TestSceneModColumn : OsuManualInputManagerTestScene
|
2022-02-20 00:52:16 +08:00
|
|
|
{
|
|
|
|
[Cached]
|
|
|
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);
|
|
|
|
|
|
|
|
[TestCase(ModType.DifficultyReduction)]
|
|
|
|
[TestCase(ModType.DifficultyIncrease)]
|
|
|
|
[TestCase(ModType.Conversion)]
|
|
|
|
[TestCase(ModType.Automation)]
|
|
|
|
[TestCase(ModType.Fun)]
|
|
|
|
public void TestBasic(ModType modType)
|
|
|
|
{
|
|
|
|
AddStep("create content", () => Child = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(30),
|
2022-02-20 01:45:04 +08:00
|
|
|
Child = new ModColumn(modType, false)
|
2022-02-20 00:52:16 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("change ruleset to osu!", () => Ruleset.Value = new OsuRuleset().RulesetInfo);
|
|
|
|
AddStep("change ruleset to taiko", () => Ruleset.Value = new TaikoRuleset().RulesetInfo);
|
|
|
|
AddStep("change ruleset to catch", () => Ruleset.Value = new CatchRuleset().RulesetInfo);
|
|
|
|
AddStep("change ruleset to mania", () => Ruleset.Value = new ManiaRuleset().RulesetInfo);
|
|
|
|
}
|
2022-02-20 01:45:04 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestMultiSelection()
|
|
|
|
{
|
2022-03-01 04:36:13 +08:00
|
|
|
ModColumn column = null;
|
2022-02-20 01:45:04 +08:00
|
|
|
AddStep("create content", () => Child = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(30),
|
2022-03-01 04:36:13 +08:00
|
|
|
Child = column = new ModColumn(ModType.DifficultyIncrease, true)
|
2022-02-20 01:45:04 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
}
|
|
|
|
});
|
2022-02-20 20:09:06 +08:00
|
|
|
|
2022-03-01 04:36:13 +08:00
|
|
|
AddUntilStep("wait for panel load", () => column.IsLoaded && column.ItemsLoaded);
|
|
|
|
|
2022-02-20 20:09:06 +08:00
|
|
|
clickToggle();
|
|
|
|
AddUntilStep("all panels selected", () => this.ChildrenOfType<ModPanel>().All(panel => panel.Active.Value));
|
|
|
|
|
|
|
|
clickToggle();
|
|
|
|
AddUntilStep("all panels deselected", () => this.ChildrenOfType<ModPanel>().All(panel => !panel.Active.Value));
|
|
|
|
|
|
|
|
AddStep("manually activate all panels", () => this.ChildrenOfType<ModPanel>().ForEach(panel => panel.Active.Value = true));
|
|
|
|
AddUntilStep("checkbox selected", () => this.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
|
|
|
|
|
|
|
AddStep("deselect first panel", () => this.ChildrenOfType<ModPanel>().First().Active.Value = false);
|
2022-03-01 03:44:13 +08:00
|
|
|
AddUntilStep("checkbox not selected", () => !this.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
2022-02-20 20:09:06 +08:00
|
|
|
|
|
|
|
void clickToggle() => AddStep("click toggle", () =>
|
|
|
|
{
|
|
|
|
var checkbox = this.ChildrenOfType<OsuCheckbox>().Single();
|
|
|
|
InputManager.MoveMouseTo(checkbox);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2022-02-20 01:45:04 +08:00
|
|
|
}
|
2022-02-20 20:40:52 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFiltering()
|
|
|
|
{
|
|
|
|
TestModColumn column = null;
|
|
|
|
|
|
|
|
AddStep("create content", () => Child = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(30),
|
|
|
|
Child = column = new TestModColumn(ModType.Fun, true)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
AddStep("set filter", () => column.Filter = mod => mod.Name.Contains("Wind", StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
AddUntilStep("two panels visible", () => column.ChildrenOfType<ModPanel>().Count(panel => !panel.Filtered.Value) == 2);
|
|
|
|
|
|
|
|
clickToggle();
|
|
|
|
AddUntilStep("wait for animation", () => !column.SelectionAnimationRunning);
|
|
|
|
AddAssert("only visible items selected", () => column.ChildrenOfType<ModPanel>().Where(panel => panel.Active.Value).All(panel => !panel.Filtered.Value));
|
|
|
|
|
|
|
|
AddStep("unset filter", () => column.Filter = null);
|
|
|
|
AddUntilStep("all panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => !panel.Filtered.Value));
|
|
|
|
AddAssert("checkbox not selected", () => !column.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
|
|
|
|
|
|
|
AddStep("set filter", () => column.Filter = mod => mod.Name.Contains("Wind", StringComparison.CurrentCultureIgnoreCase));
|
|
|
|
AddUntilStep("two panels visible", () => column.ChildrenOfType<ModPanel>().Count(panel => !panel.Filtered.Value) == 2);
|
|
|
|
AddAssert("checkbox selected", () => column.ChildrenOfType<OsuCheckbox>().Single().Current.Value);
|
|
|
|
|
2022-02-20 21:14:19 +08:00
|
|
|
AddStep("filter out everything", () => column.Filter = _ => false);
|
|
|
|
AddUntilStep("no panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => panel.Filtered.Value));
|
|
|
|
AddUntilStep("checkbox hidden", () => !column.ChildrenOfType<OsuCheckbox>().Single().IsPresent);
|
|
|
|
|
|
|
|
AddStep("inset filter", () => column.Filter = null);
|
2022-03-01 03:44:13 +08:00
|
|
|
AddUntilStep("all panels visible", () => column.ChildrenOfType<ModPanel>().All(panel => !panel.Filtered.Value));
|
|
|
|
AddUntilStep("checkbox visible", () => column.ChildrenOfType<OsuCheckbox>().Single().IsPresent);
|
2022-02-20 21:14:19 +08:00
|
|
|
|
2022-02-20 20:40:52 +08:00
|
|
|
void clickToggle() => AddStep("click toggle", () =>
|
|
|
|
{
|
|
|
|
var checkbox = this.ChildrenOfType<OsuCheckbox>().Single();
|
|
|
|
InputManager.MoveMouseTo(checkbox);
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-20 21:10:35 +08:00
|
|
|
[Test]
|
|
|
|
public void TestKeyboardSelection()
|
|
|
|
{
|
|
|
|
ModColumn column = null;
|
|
|
|
AddStep("create content", () => Child = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding(30),
|
2022-03-01 04:36:13 +08:00
|
|
|
Child = column = new ModColumn(ModType.DifficultyReduction, true, new[] { Key.Q, Key.W, Key.E, Key.R, Key.T, Key.Y, Key.U, Key.I, Key.O, Key.P })
|
2022-02-20 21:10:35 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-03-01 04:36:13 +08:00
|
|
|
AddUntilStep("wait for panel load", () => column.IsLoaded && column.ItemsLoaded);
|
|
|
|
|
2022-02-20 21:10:35 +08:00
|
|
|
AddStep("press W", () => InputManager.Key(Key.W));
|
|
|
|
AddAssert("NF panel selected", () => this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
|
|
|
|
|
|
|
AddStep("press W again", () => InputManager.Key(Key.W));
|
|
|
|
AddAssert("NF panel deselected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
|
|
|
|
|
|
|
AddStep("set filter to NF", () => column.Filter = mod => mod.Acronym == "NF");
|
|
|
|
|
|
|
|
AddStep("press W", () => InputManager.Key(Key.W));
|
|
|
|
AddAssert("NF panel selected", () => this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
|
|
|
|
|
|
|
AddStep("press W again", () => InputManager.Key(Key.W));
|
|
|
|
AddAssert("NF panel deselected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
|
|
|
|
|
|
|
AddStep("filter out everything", () => column.Filter = _ => false);
|
|
|
|
|
|
|
|
AddStep("press W", () => InputManager.Key(Key.W));
|
|
|
|
AddAssert("NF panel not selected", () => !this.ChildrenOfType<ModPanel>().Single(panel => panel.Mod.Acronym == "NF").Active.Value);
|
|
|
|
|
|
|
|
AddStep("clear filter", () => column.Filter = null);
|
|
|
|
}
|
|
|
|
|
2022-02-20 20:40:52 +08:00
|
|
|
private class TestModColumn : ModColumn
|
|
|
|
{
|
|
|
|
public new bool SelectionAnimationRunning => base.SelectionAnimationRunning;
|
|
|
|
|
|
|
|
public TestModColumn(ModType modType, bool allowBulkSelection)
|
|
|
|
: base(modType, allowBulkSelection)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2022-02-20 00:52:16 +08:00
|
|
|
}
|
|
|
|
}
|