2019-01-24 08:43:03 +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.
|
2018-12-25 02:45:50 +00:00
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2018-12-25 02:59:08 +00:00
|
|
|
using System.Linq;
|
2020-02-06 03:17:05 +00:00
|
|
|
using NUnit.Framework;
|
2018-12-25 02:45:50 +00:00
|
|
|
using osu.Framework.Graphics;
|
2021-07-26 04:31:01 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-10-19 05:39:21 +00:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2021-07-26 04:31:01 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-12-25 04:38:11 +00:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-02-06 04:03:15 +00:00
|
|
|
using osu.Game.Rulesets.Catch;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2021-08-18 11:53:17 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge;
|
2020-12-25 15:50:00 +00:00
|
|
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
2021-06-24 10:09:31 +00:00
|
|
|
using osu.Game.Tests.Visual.OnlinePlay;
|
2020-07-09 09:55:18 +00:00
|
|
|
using osuTK.Input;
|
2018-12-25 02:45:50 +00:00
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
namespace osu.Game.Tests.Visual.Multiplayer
|
2018-12-25 02:45:50 +00:00
|
|
|
{
|
2021-06-25 04:02:19 +00:00
|
|
|
public partial class TestSceneLoungeRoomsContainer : OnlinePlayTestScene
|
2018-12-25 02:45:50 +00:00
|
|
|
{
|
2021-10-27 07:10:22 +00:00
|
|
|
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;
|
2021-06-24 10:13:50 +00:00
|
|
|
|
2020-02-06 03:17:05 +00:00
|
|
|
private RoomsContainer container;
|
|
|
|
|
2022-07-29 06:27:39 +00:00
|
|
|
public override void SetUpSteps()
|
2018-12-25 02:45:50 +00:00
|
|
|
{
|
2022-07-29 06:27:39 +00:00
|
|
|
base.SetUpSteps();
|
2021-10-19 05:39:21 +00:00
|
|
|
|
2022-07-29 06:27:39 +00:00
|
|
|
AddStep("create container", () =>
|
|
|
|
{
|
|
|
|
Child = new PopoverContainer
|
2021-10-19 05:39:21 +00:00
|
|
|
{
|
2022-07-29 06:27:39 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Width = 0.5f,
|
|
|
|
|
|
|
|
Child = container = new RoomsContainer
|
|
|
|
{
|
|
|
|
SelectedRoom = { BindTarget = SelectedRoom }
|
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2020-02-06 03:17:05 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestBasicListChanges()
|
2020-02-06 03:26:08 +00:00
|
|
|
{
|
2022-02-21 10:48:39 +00:00
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(5, withSpotlightRooms: true));
|
2020-02-06 03:26:08 +00:00
|
|
|
|
2022-02-21 08:59:51 +00:00
|
|
|
AddAssert("has 5 rooms", () => container.Rooms.Count == 5);
|
|
|
|
|
|
|
|
AddAssert("all spotlights at top", () => container.Rooms
|
|
|
|
.SkipWhile(r => r.Room.Category.Value == RoomCategory.Spotlight)
|
|
|
|
.All(r => r.Room.Category.Value == RoomCategory.Normal));
|
|
|
|
|
2024-02-02 10:48:13 +00:00
|
|
|
AddStep("remove first room", () => RoomManager.RemoveRoom(RoomManager.Rooms.First(r => r.RoomID.Value == 0)));
|
2022-02-21 08:59:51 +00:00
|
|
|
AddAssert("has 4 rooms", () => container.Rooms.Count == 4);
|
2020-02-06 03:26:08 +00:00
|
|
|
AddAssert("first room removed", () => container.Rooms.All(r => r.Room.RoomID.Value != 0));
|
|
|
|
|
2021-08-04 08:27:44 +00:00
|
|
|
AddStep("select first room", () => container.Rooms.First().TriggerClick());
|
2022-02-21 08:59:51 +00:00
|
|
|
AddAssert("first spotlight selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category.Value == RoomCategory.Spotlight)));
|
2024-02-05 18:53:19 +00:00
|
|
|
|
|
|
|
AddStep("remove last room", () => RoomManager.RemoveRoom(RoomManager.Rooms.MinBy(r => r.RoomID?.Value)));
|
|
|
|
AddAssert("first spotlight still selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category.Value == RoomCategory.Spotlight)));
|
|
|
|
|
|
|
|
AddStep("remove spotlight room", () => RoomManager.RemoveRoom(RoomManager.Rooms.Single(r => r.Category.Value == RoomCategory.Spotlight)));
|
|
|
|
AddAssert("selection vacated", () => checkRoomSelected(null));
|
2020-02-06 03:26:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-09 09:55:18 +00:00
|
|
|
[Test]
|
|
|
|
public void TestKeyboardNavigation()
|
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(3));
|
2020-07-09 09:55:18 +00:00
|
|
|
|
|
|
|
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()));
|
|
|
|
}
|
|
|
|
|
2021-07-26 04:31:01 +00:00
|
|
|
[Test]
|
|
|
|
public void TestKeyboardNavigationAfterOrderChange()
|
|
|
|
{
|
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(3));
|
|
|
|
|
|
|
|
AddStep("reorder rooms", () =>
|
|
|
|
{
|
|
|
|
var room = RoomManager.Rooms[1];
|
|
|
|
|
|
|
|
RoomManager.RemoveRoom(room);
|
2021-08-13 08:39:09 +00:00
|
|
|
RoomManager.AddOrUpdateRoom(room);
|
2021-07-26 04:31:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("no selection", () => checkRoomSelected(null));
|
|
|
|
|
|
|
|
press(Key.Down);
|
|
|
|
AddAssert("first room selected", () => checkRoomSelected(getRoomInFlow(0)));
|
|
|
|
|
|
|
|
press(Key.Down);
|
|
|
|
AddAssert("second room selected", () => checkRoomSelected(getRoomInFlow(1)));
|
|
|
|
|
|
|
|
press(Key.Down);
|
|
|
|
AddAssert("third room selected", () => checkRoomSelected(getRoomInFlow(2)));
|
|
|
|
}
|
|
|
|
|
2021-02-16 04:44:36 +00:00
|
|
|
[Test]
|
|
|
|
public void TestClickDeselection()
|
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
AddStep("add room", () => RoomManager.AddRooms(1));
|
2021-02-16 04:44:36 +00:00
|
|
|
|
|
|
|
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 09:55:18 +00:00
|
|
|
private void press(Key down)
|
|
|
|
{
|
2020-11-05 14:41:56 +00:00
|
|
|
AddStep($"press {down}", () => InputManager.Key(down));
|
2020-07-09 09:55:18 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 03:26:08 +00:00
|
|
|
[Test]
|
|
|
|
public void TestStringFiltering()
|
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(4));
|
2020-02-06 03:26:08 +00:00
|
|
|
|
|
|
|
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
|
|
|
|
2021-08-17 00:36:43 +00:00
|
|
|
AddStep("filter one room", () => container.Filter.Value = new FilterCriteria { SearchString = "1" });
|
2020-02-06 03:26:08 +00:00
|
|
|
|
|
|
|
AddUntilStep("1 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 1);
|
|
|
|
|
2021-08-17 00:36:43 +00:00
|
|
|
AddStep("remove filter", () => container.Filter.Value = null);
|
2020-02-06 03:26:08 +00:00
|
|
|
|
|
|
|
AddUntilStep("4 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 4);
|
|
|
|
}
|
|
|
|
|
2020-02-06 04:03:15 +00:00
|
|
|
[Test]
|
|
|
|
public void TestRulesetFiltering()
|
|
|
|
{
|
2021-06-24 10:09:31 +00:00
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(2, new OsuRuleset().RulesetInfo));
|
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(3, new CatchRuleset().RulesetInfo));
|
2020-02-06 04:03:15 +00:00
|
|
|
|
2021-06-25 06:00:10 +00:00
|
|
|
// Todo: What even is this case...?
|
2021-08-17 00:36:43 +00:00
|
|
|
AddStep("set empty filter criteria", () => container.Filter.Value = null);
|
2020-02-06 04:03:15 +00:00
|
|
|
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);
|
|
|
|
|
2021-08-17 00:36:43 +00:00
|
|
|
AddStep("filter osu! rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo });
|
2020-02-06 04:03:15 +00:00
|
|
|
AddUntilStep("2 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
|
|
|
|
2021-08-17 00:36:43 +00:00
|
|
|
AddStep("filter catch rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new CatchRuleset().RulesetInfo });
|
2020-02-06 04:03:15 +00:00
|
|
|
AddUntilStep("3 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 3);
|
|
|
|
}
|
|
|
|
|
2022-06-22 21:01:42 +00:00
|
|
|
[Test]
|
2022-06-23 16:04:38 +00:00
|
|
|
public void TestAccessTypeFiltering()
|
2022-06-22 21:01:42 +00:00
|
|
|
{
|
|
|
|
AddStep("add rooms", () =>
|
|
|
|
{
|
|
|
|
RoomManager.AddRooms(1, withPassword: true);
|
|
|
|
RoomManager.AddRooms(1, withPassword: false);
|
|
|
|
});
|
|
|
|
|
2022-06-23 15:24:28 +00:00
|
|
|
AddStep("apply default filter", () => container.Filter.SetDefault());
|
|
|
|
|
|
|
|
AddUntilStep("both rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 2);
|
|
|
|
|
2022-07-01 08:26:40 +00:00
|
|
|
AddStep("filter public rooms", () => container.Filter.Value = new FilterCriteria { Permissions = RoomPermissionsFilter.Public });
|
2022-06-22 21:01:42 +00:00
|
|
|
|
2022-06-23 15:02:27 +00:00
|
|
|
AddUntilStep("private room hidden", () => container.Rooms.All(r => !r.Room.HasPassword.Value));
|
2022-06-22 21:01:42 +00:00
|
|
|
|
2022-07-01 08:26:40 +00:00
|
|
|
AddStep("filter private rooms", () => container.Filter.Value = new FilterCriteria { Permissions = RoomPermissionsFilter.Private });
|
2022-06-22 21:01:42 +00:00
|
|
|
|
2022-06-23 15:02:27 +00:00
|
|
|
AddUntilStep("public room hidden", () => container.Rooms.All(r => r.Room.HasPassword.Value));
|
2022-06-22 21:01:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-10 05:14:58 +00:00
|
|
|
[Test]
|
|
|
|
public void TestPasswordProtectedRooms()
|
|
|
|
{
|
|
|
|
AddStep("add rooms", () => RoomManager.AddRooms(3, withPassword: true));
|
|
|
|
}
|
|
|
|
|
2021-06-24 10:09:31 +00:00
|
|
|
private bool checkRoomSelected(Room room) => SelectedRoom.Value == room;
|
2021-07-26 04:31:01 +00:00
|
|
|
|
|
|
|
private Room getRoomInFlow(int index) =>
|
2021-08-18 11:53:17 +00:00
|
|
|
(container.ChildrenOfType<FillFlowContainer<DrawableLoungeRoom>>().First().FlowingChildren.ElementAt(index) as DrawableRoom)?.Room;
|
2018-12-25 02:45:50 +00:00
|
|
|
}
|
|
|
|
}
|