2022-04-03 17:53:05 +00: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-05-06 14:43:24 +00:00
|
|
|
using System.Collections.Generic;
|
2022-04-17 14:54:30 +00:00
|
|
|
using System.Linq;
|
2022-04-03 17:53:05 +00:00
|
|
|
using NUnit.Framework;
|
2022-05-06 14:43:24 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-04-03 17:53:05 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-04-17 14:54:30 +00:00
|
|
|
using osu.Framework.Testing;
|
2022-05-06 14:43:24 +00:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-04-17 14:54:30 +00:00
|
|
|
using osu.Game.Overlays.Mods;
|
2022-05-06 19:35:22 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Mods;
|
2022-05-06 14:43:24 +00:00
|
|
|
using osu.Game.Rulesets.Mods;
|
2022-04-03 17:53:05 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay;
|
2022-05-06 14:43:24 +00:00
|
|
|
using osuTK.Input;
|
2022-04-03 17:53:05 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
|
|
{
|
|
|
|
public class TestSceneFreeModSelectScreen : MultiplayerTestScene
|
|
|
|
{
|
2022-05-10 20:29:57 +00:00
|
|
|
private FreeModSelectOverlay freeModSelectOverlay;
|
2022-05-06 14:43:24 +00: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-06 19:35:22 +00:00
|
|
|
|
2022-04-03 17:53:05 +00:00
|
|
|
[Test]
|
|
|
|
public void TestFreeModSelect()
|
|
|
|
{
|
2022-05-06 19:35:22 +00:00
|
|
|
createFreeModSelect();
|
2022-04-17 14:54:30 +00:00
|
|
|
|
2022-04-21 22:07:00 +00:00
|
|
|
AddUntilStep("all visible mods are playable",
|
2022-04-17 14:54:30 +00:00
|
|
|
() => this.ChildrenOfType<ModPanel>()
|
|
|
|
.Where(panel => panel.IsPresent)
|
|
|
|
.All(panel => panel.Mod.HasImplementation && panel.Mod.UserPlayable));
|
|
|
|
|
2022-04-03 17:53:05 +00:00
|
|
|
AddToggleStep("toggle visibility", visible =>
|
|
|
|
{
|
2022-05-10 20:29:57 +00:00
|
|
|
if (freeModSelectOverlay != null)
|
|
|
|
freeModSelectOverlay.State.Value = visible ? Visibility.Visible : Visibility.Hidden;
|
2022-04-03 17:53:05 +00:00
|
|
|
});
|
|
|
|
}
|
2022-05-06 19:35:22 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestCustomisationNotAvailable()
|
|
|
|
{
|
|
|
|
createFreeModSelect();
|
|
|
|
|
2022-05-10 20:29:57 +00:00
|
|
|
AddStep("select difficulty adjust", () => freeModSelectOverlay.SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
|
2022-05-06 19:35:22 +00:00
|
|
|
AddWaitStep("wait some", 3);
|
|
|
|
AddAssert("customisation area not expanded", () => this.ChildrenOfType<ModSettingsArea>().Single().Height == 0);
|
|
|
|
}
|
|
|
|
|
2022-05-06 14:43:24 +00:00
|
|
|
[Test]
|
|
|
|
public void TestSelectDeselectAll()
|
|
|
|
{
|
|
|
|
createFreeModSelect();
|
|
|
|
|
|
|
|
AddStep("click select all button", () =>
|
|
|
|
{
|
2022-05-07 08:25:23 +00:00
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ShearedButton>().ElementAt(1));
|
2022-05-06 14:43:24 +00:00
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
|
|
|
AddUntilStep("all mods selected", assertAllAvailableModsSelected);
|
|
|
|
|
|
|
|
AddStep("click deselect all button", () =>
|
|
|
|
{
|
|
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ShearedButton>().Last());
|
|
|
|
InputManager.Click(MouseButton.Left);
|
|
|
|
});
|
2022-05-10 20:29:57 +00:00
|
|
|
AddUntilStep("all mods deselected", () => !freeModSelectOverlay.SelectedMods.Value.Any());
|
2022-05-06 14:43:24 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 19:35:22 +00:00
|
|
|
private void createFreeModSelect()
|
|
|
|
{
|
2022-05-10 20:29:57 +00:00
|
|
|
AddStep("create free mod select screen", () => Child = freeModSelectOverlay = new FreeModSelectOverlay
|
2022-05-06 19:35:22 +00:00
|
|
|
{
|
|
|
|
State = { Value = Visibility.Visible }
|
|
|
|
});
|
|
|
|
AddUntilStep("all column content loaded",
|
2022-05-10 20:29:57 +00:00
|
|
|
() => freeModSelectOverlay.ChildrenOfType<ModColumn>().Any()
|
|
|
|
&& freeModSelectOverlay.ChildrenOfType<ModColumn>().All(column => column.IsLoaded && column.ItemsLoaded));
|
2022-05-06 19:35:22 +00:00
|
|
|
}
|
2022-05-06 14:43:24 +00: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-10 20:29:57 +00:00
|
|
|
if (freeModSelectOverlay.SelectedMods.Value.All(selectedMod => selectedMod.GetType() != availableMod.GetType()))
|
2022-05-06 14:43:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-04-03 17:53:05 +00:00
|
|
|
}
|
|
|
|
}
|