2022-04-04 01:53:05 +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-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-05-06 22:43:24 +08:00
|
|
|
using System.Collections.Generic;
|
2022-04-17 22:54:30 +08:00
|
|
|
using System.Linq;
|
2022-04-04 01:53:05 +08:00
|
|
|
using NUnit.Framework;
|
2022-05-06 22:43:24 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-04-04 01:53:05 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-05-15 02:18:44 +08:00
|
|
|
using osu.Framework.Input;
|
2022-04-17 22:54:30 +08:00
|
|
|
using osu.Framework.Testing;
|
|
|
|
using osu.Game.Overlays.Mods;
|
2022-05-07 03:35:22 +08:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2022-05-06 22:43:24 +08:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-04-04 01:53:05 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay;
|
2022-05-06 22:43:24 +08:00
|
|
|
using osuTK.Input;
|
2022-04-04 01:53:05 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
2022-05-12 00:04:39 +08:00
|
|
|
public class TestSceneFreeModSelectOverlay : MultiplayerTestScene
|
2022-04-04 01:53:05 +08:00
|
|
|
{
|
2022-05-11 04:29:57 +08:00
|
|
|
private FreeModSelectOverlay freeModSelectOverlay;
|
2022-05-06 22:43:24 +08:00
|
|
|
private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuGameBase osuGameBase)
|
|
|
|
{
|
|
|
|
availableMods.BindTo(osuGameBase.AvailableMods);
|
|
|
|
}
|
2022-05-07 03:35:22 +08:00
|
|
|
|
2022-04-04 01:53:05 +08:00
|
|
|
[Test]
|
|
|
|
public void TestFreeModSelect()
|
|
|
|
{
|
2022-05-07 03:35:22 +08:00
|
|
|
createFreeModSelect();
|
2022-04-17 22:54:30 +08:00
|
|
|
|
2022-04-22 06:07:00 +08:00
|
|
|
AddUntilStep("all visible mods are playable",
|
2022-04-17 22:54:30 +08:00
|
|
|
() => this.ChildrenOfType<ModPanel>()
|
|
|
|
.Where(panel => panel.IsPresent)
|
|
|
|
.All(panel => panel.Mod.HasImplementation && panel.Mod.UserPlayable));
|
|
|
|
|
2022-04-04 01:53:05 +08:00
|
|
|
AddToggleStep("toggle visibility", visible =>
|
|
|
|
{
|
2022-05-11 04:29:57 +08:00
|
|
|
if (freeModSelectOverlay != null)
|
|
|
|
freeModSelectOverlay.State.Value = visible ? Visibility.Visible : Visibility.Hidden;
|
2022-04-04 01:53:05 +08:00
|
|
|
});
|
|
|
|
}
|
2022-05-07 03:35:22 +08:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCustomisationNotAvailable()
|
|
|
|
{
|
|
|
|
createFreeModSelect();
|
|
|
|
|
2022-05-11 04:29:57 +08:00
|
|
|
AddStep("select difficulty adjust", () => freeModSelectOverlay.SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
|
2022-05-07 03:35:22 +08:00
|
|
|
AddWaitStep("wait some", 3);
|
|
|
|
AddAssert("customisation area not expanded", () => this.ChildrenOfType<ModSettingsArea>().Single().Height == 0);
|
|
|
|
}
|
|
|
|
|
2022-05-15 02:18:44 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSelectDeselectAllViaKeyboard()
|
|
|
|
{
|
|
|
|
createFreeModSelect();
|
|
|
|
|
|
|
|
AddStep("press ctrl+a", () => InputManager.Keys(PlatformAction.SelectAll));
|
|
|
|
AddUntilStep("all mods selected", assertAllAvailableModsSelected);
|
|
|
|
|
|
|
|
AddStep("press backspace", () => InputManager.Key(Key.BackSpace));
|
|
|
|
AddUntilStep("all mods deselected", () => !freeModSelectOverlay.SelectedMods.Value.Any());
|
|
|
|
}
|
|
|
|
|
2022-05-06 22:43:24 +08:00
|
|
|
[Test]
|
|
|
|
public void TestSelectDeselectAll()
|
|
|
|
{
|
|
|
|
createFreeModSelect();
|
|
|
|
|
2022-05-26 04:27:54 +08:00
|
|
|
AddAssert("select all button enabled", () => this.ChildrenOfType<SelectAllModsButton>().Single().Enabled.Value);
|
2022-05-26 03:49:31 +08:00
|
|
|
|
2022-05-06 22:43:24 +08:00
|
|
|
AddStep("click select all button", () =>
|
|
|
|
{
|
2022-05-26 04:27:54 +08:00
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<SelectAllModsButton>().Single());
|
2022-05-06 22:43:24 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
AddUntilStep("all mods selected", assertAllAvailableModsSelected);
|
2022-05-26 04:27:54 +08:00
|
|
|
AddAssert("select all button disabled", () => !this.ChildrenOfType<SelectAllModsButton>().Single().Enabled.Value);
|
2022-05-06 22:43:24 +08:00
|
|
|
|
|
|
|
AddStep("click deselect all button", () =>
|
|
|
|
{
|
2022-05-26 04:27:54 +08:00
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<DeselectAllModsButton>().Single());
|
2022-05-06 22:43:24 +08:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2022-05-11 04:29:57 +08:00
|
|
|
AddUntilStep("all mods deselected", () => !freeModSelectOverlay.SelectedMods.Value.Any());
|
2022-05-26 04:27:54 +08:00
|
|
|
AddAssert("select all button enabled", () => this.ChildrenOfType<SelectAllModsButton>().Single().Enabled.Value);
|
2022-05-06 22:43:24 +08:00
|
|
|
}
|
|
|
|
|
2022-05-07 03:35:22 +08:00
|
|
|
private void createFreeModSelect()
|
|
|
|
{
|
2022-05-11 04:29:57 +08:00
|
|
|
AddStep("create free mod select screen", () => Child = freeModSelectOverlay = new FreeModSelectOverlay
|
2022-05-07 03:35:22 +08:00
|
|
|
{
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
});
|
|
|
|
AddUntilStep("all column content loaded",
|
2022-05-11 04:29:57 +08:00
|
|
|
() => freeModSelectOverlay.ChildrenOfType<ModColumn>().Any()
|
|
|
|
&& freeModSelectOverlay.ChildrenOfType<ModColumn>().All(column => column.IsLoaded && column.ItemsLoaded));
|
2022-05-07 03:35:22 +08:00
|
|
|
}
|
2022-05-06 22:43:24 +08:00
|
|
|
|
|
|
|
private bool assertAllAvailableModsSelected()
|
|
|
|
{
|
|
|
|
var allAvailableMods = availableMods.Value
|
|
|
|
.SelectMany(pair => pair.Value)
|
|
|
|
.Where(mod => mod.UserPlayable && mod.HasImplementation)
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
foreach (var availableMod in allAvailableMods)
|
|
|
|
{
|
2022-05-11 04:29:57 +08:00
|
|
|
if (freeModSelectOverlay.SelectedMods.Value.All(selectedMod => selectedMod.GetType() != availableMod.GetType()))
|
2022-05-06 22:43:24 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-04-04 01:53:05 +08:00
|
|
|
}
|
|
|
|
}
|