mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 16:47:24 +08:00
119 lines
4.4 KiB
C#
119 lines
4.4 KiB
C#
// 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.Collections.Generic;
|
|
using System.Linq;
|
|
using NUnit.Framework;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Input;
|
|
using osu.Framework.Testing;
|
|
using osu.Game.Graphics.UserInterface;
|
|
using osu.Game.Overlays.Mods;
|
|
using osu.Game.Rulesets.Osu.Mods;
|
|
using osu.Game.Rulesets.Mods;
|
|
using osu.Game.Screens.OnlinePlay;
|
|
using osuTK.Input;
|
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
|
{
|
|
public class TestSceneFreeModSelectOverlay : MultiplayerTestScene
|
|
{
|
|
private FreeModSelectOverlay freeModSelectOverlay;
|
|
private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load(OsuGameBase osuGameBase)
|
|
{
|
|
availableMods.BindTo(osuGameBase.AvailableMods);
|
|
}
|
|
|
|
[Test]
|
|
public void TestFreeModSelect()
|
|
{
|
|
createFreeModSelect();
|
|
|
|
AddUntilStep("all visible mods are playable",
|
|
() => this.ChildrenOfType<ModPanel>()
|
|
.Where(panel => panel.IsPresent)
|
|
.All(panel => panel.Mod.HasImplementation && panel.Mod.UserPlayable));
|
|
|
|
AddToggleStep("toggle visibility", visible =>
|
|
{
|
|
if (freeModSelectOverlay != null)
|
|
freeModSelectOverlay.State.Value = visible ? Visibility.Visible : Visibility.Hidden;
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void TestCustomisationNotAvailable()
|
|
{
|
|
createFreeModSelect();
|
|
|
|
AddStep("select difficulty adjust", () => freeModSelectOverlay.SelectedMods.Value = new[] { new OsuModDifficultyAdjust() });
|
|
AddWaitStep("wait some", 3);
|
|
AddAssert("customisation area not expanded", () => this.ChildrenOfType<ModSettingsArea>().Single().Height == 0);
|
|
}
|
|
|
|
[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());
|
|
}
|
|
|
|
[Test]
|
|
public void TestSelectDeselectAll()
|
|
{
|
|
createFreeModSelect();
|
|
|
|
AddStep("click select all button", () =>
|
|
{
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ShearedButton>().ElementAt(1));
|
|
InputManager.Click(MouseButton.Left);
|
|
});
|
|
AddUntilStep("all mods selected", assertAllAvailableModsSelected);
|
|
|
|
AddStep("click deselect all button", () =>
|
|
{
|
|
InputManager.MoveMouseTo(this.ChildrenOfType<ShearedButton>().Last());
|
|
InputManager.Click(MouseButton.Left);
|
|
});
|
|
AddUntilStep("all mods deselected", () => !freeModSelectOverlay.SelectedMods.Value.Any());
|
|
}
|
|
|
|
private void createFreeModSelect()
|
|
{
|
|
AddStep("create free mod select screen", () => Child = freeModSelectOverlay = new FreeModSelectOverlay
|
|
{
|
|
State = { Value = Visibility.Visible }
|
|
});
|
|
AddUntilStep("all column content loaded",
|
|
() => freeModSelectOverlay.ChildrenOfType<ModColumn>().Any()
|
|
&& freeModSelectOverlay.ChildrenOfType<ModColumn>().All(column => column.IsLoaded && column.ItemsLoaded));
|
|
}
|
|
|
|
private bool assertAllAvailableModsSelected()
|
|
{
|
|
var allAvailableMods = availableMods.Value
|
|
.SelectMany(pair => pair.Value)
|
|
.Where(mod => mod.UserPlayable && mod.HasImplementation)
|
|
.ToList();
|
|
|
|
foreach (var availableMod in allAvailableMods)
|
|
{
|
|
if (freeModSelectOverlay.SelectedMods.Value.All(selectedMod => selectedMod.GetType() != availableMod.GetType()))
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|