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