2019-01-24 16:43:03 +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.
|
2018-12-25 10:45:50 +08:00
|
|
|
|
2018-12-25 10:59:08 +08:00
|
|
|
using System.Linq;
|
2020-02-06 11:17:05 +08:00
|
|
|
using NUnit.Framework;
|
2018-12-25 10:45:50 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-02-06 12:03:15 +08:00
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2020-12-25 23:50:00 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
2018-12-25 10:45:50 +08:00
|
|
|
using osuTK.Graphics;
|
2020-07-09 17:55:18 +08:00
|
|
|
using osuTK.Input;
|
2018-12-25 10:45:50 +08:00
|
|
|
|
2019-03-25 00:02:36 +08:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
2020-07-09 17:07:34 +08:00
|
|
|
public class TestSceneLoungeRoomsContainer : RoomManagerTestScene
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
2020-02-06 11:17:05 +08:00
|
|
|
private RoomsContainer container;
|
|
|
|
|
2019-03-26 12:16:46 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
2018-12-25 10:59:08 +08:00
|
|
|
Child = container = new RoomsContainer
|
2018-12-25 10:45:50 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f,
|
|
|
|
JoinRequested = joinRequested
|
|
|
|
};
|
2020-02-06 11:17:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBasicListChanges()
|
2020-02-06 11:26:08 +08:00
|
|
|
{
|
2020-07-09 17:07:34 +08:00
|
|
|
AddRooms(3);
|
2020-02-06 11:26:08 +08:00
|
|
|
|
|
|
|
AddAssert("has 3 rooms", () => container.Rooms.Count == 3);
|
2020-07-09 17:07:34 +08:00
|
|
|
AddStep("remove first room", () => RoomManager.Rooms.Remove(RoomManager.Rooms.FirstOrDefault()));
|
2020-02-06 11:26:08 +08:00
|
|
|
AddAssert("has 2 rooms", () => container.Rooms.Count == 2);
|
|
|
|
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
|
|
|
|
|
|
|
|
AddStep("select first room", () => container.Rooms.First().Action?.Invoke());
|
2020-07-09 17:55:18 +08:00
|
|
|
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
|
2020-02-06 11:26:08 +08:00
|
|
|
|
|
|
|
AddStep("join first room", () => container.Rooms.First().Action?.Invoke());
|
2020-07-09 17:07:34 +08:00
|
|
|
AddAssert("first room joined", () => RoomManager.Rooms.First().Status.Value is JoinedRoomStatus);
|
2020-02-06 11:26:08 +08:00
|
|
|
}
|
|
|
|
|
2020-07-09 17:55:18 +08:00
|
|
|
[Test]
|
|
|
|
public void TestKeyboardNavigation()
|
|
|
|
{
|
|
|
|
AddRooms(3);
|
|
|
|
|
|
|
|
AddAssert("no selection", () => checkRoomSelected(null));
|
|
|
|
|
|
|
|
press(Key.Down);
|
|
|
|
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
|
|
|
|
|
|
|
|
press(Key.Up);
|
|
|
|
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
|
|
|
|
|
|
|
|
press(Key.Down);
|
|
|
|
press(Key.Down);
|
|
|
|
AddAssert("last room selected", () => checkRoomSelected(RoomManager.Rooms.Last()));
|
|
|
|
|
|
|
|
press(Key.Enter);
|
|
|
|
AddAssert("last room joined", () => RoomManager.Rooms.Last().Status.Value is JoinedRoomStatus);
|
|
|
|
}
|
|
|
|
|
2021-02-16 12:44:36 +08:00
|
|
|
[Test]
|
|
|
|
public void TestClickDeselection()
|
|
|
|
{
|
|
|
|
AddRooms(1);
|
|
|
|
|
|
|
|
AddAssert("no selection", () => checkRoomSelected(null));
|
|
|
|
|
|
|
|
press(Key.Down);
|
|
|
|
AddAssert("first room selected", () => checkRoomSelected(RoomManager.Rooms.First()));
|
|
|
|
|
|
|
|
AddStep("click away", () => InputManager.Click(MouseButton.Left));
|
|
|
|
AddAssert("no selection", () => checkRoomSelected(null));
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:55:18 +08:00
|
|
|
private void press(Key down)
|
|
|
|
{
|
2020-11-05 22:41:56 +08:00
|
|
|
AddStep($"press {down}", () => InputManager.Key(down));
|
2020-07-09 17:55:18 +08:00
|
|
|
}
|
|
|
|
|
2020-02-06 11:26:08 +08:00
|
|
|
[Test]
|
|
|
|
public void TestStringFiltering()
|
|
|
|
{
|
2020-07-09 17:07:34 +08:00
|
|
|
AddRooms(4);
|
2020-02-06 11:26:08 +08:00
|
|
|
|
|
|
|
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
|
|
|
|
|
|
|
AddStep("filter one room", () => container.Filter(new FilterCriteria { SearchString = "1" }));
|
|
|
|
|
|
|
|
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
|
|
|
|
|
|
|
|
AddStep("remove filter", () => container.Filter(null));
|
|
|
|
|
|
|
|
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
|
|
|
}
|
|
|
|
|
2020-02-06 12:03:15 +08:00
|
|
|
[Test]
|
|
|
|
public void TestRulesetFiltering()
|
|
|
|
{
|
2020-07-09 17:07:34 +08:00
|
|
|
AddRooms(2, new OsuRuleset().RulesetInfo);
|
|
|
|
AddRooms(3, new CatchRuleset().RulesetInfo);
|
2020-02-06 12:03:15 +08:00
|
|
|
|
|
|
|
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
|
|
|
|
|
|
|
|
AddStep("filter osu! rooms", () => container.Filter(new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo }));
|
|
|
|
|
|
|
|
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
|
|
|
|
|
|
|
AddStep("filter catch rooms", () => container.Filter(new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo }));
|
|
|
|
|
|
|
|
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
|
|
|
|
}
|
|
|
|
|
2020-07-09 17:55:18 +08:00
|
|
|
private bool checkRoomSelected(Room room) => Room == room;
|
|
|
|
|
2018-12-25 10:45:50 +08:00
|
|
|
private void joinRequested(Room room) => room.Status.Value = new JoinedRoomStatus();
|
|
|
|
|
|
|
|
private class JoinedRoomStatus : RoomStatus
|
|
|
|
{
|
|
|
|
public override string Message => "Joined";
|
|
|
|
|
|
|
|
public override Color4 GetAppropriateColour(OsuColour colours) => colours.Yellow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|