From 971a67c669e8970c8810f24d17ec88cf26b26494 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 26 Jul 2021 13:31:01 +0900 Subject: [PATCH 1/2] Add failing test coverage for misordered rooms --- .../TestSceneLoungeRoomsContainer.cs | 30 +++++++++++++++++++ .../Visual/OnlinePlay/BasicTestRoomManager.cs | 22 ++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs index 4d5bf8f225..0a23550f5d 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneLoungeRoomsContainer.cs @@ -4,6 +4,8 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Testing; using osu.Game.Online.Rooms; using osu.Game.Rulesets.Catch; using osu.Game.Rulesets.Osu; @@ -62,6 +64,31 @@ namespace osu.Game.Tests.Visual.Multiplayer AddAssert("last room selected", () => checkRoomSelected(RoomManager.Rooms.Last())); } + [Test] + public void TestKeyboardNavigationAfterOrderChange() + { + AddStep("add rooms", () => RoomManager.AddRooms(3)); + + AddStep("reorder rooms", () => + { + var room = RoomManager.Rooms[1]; + + RoomManager.RemoveRoom(room); + RoomManager.AddRoom(room); + }); + + 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))); + } + [Test] public void TestClickDeselection() { @@ -121,5 +148,8 @@ namespace osu.Game.Tests.Visual.Multiplayer } private bool checkRoomSelected(Room room) => SelectedRoom.Value == room; + + private Room getRoomInFlow(int index) => + (container.ChildrenOfType>().First().FlowingChildren.ElementAt(index) as DrawableRoom)?.Room; } } diff --git a/osu.Game/Tests/Visual/OnlinePlay/BasicTestRoomManager.cs b/osu.Game/Tests/Visual/OnlinePlay/BasicTestRoomManager.cs index 82c7266598..d37a64fa4b 100644 --- a/osu.Game/Tests/Visual/OnlinePlay/BasicTestRoomManager.cs +++ b/osu.Game/Tests/Visual/OnlinePlay/BasicTestRoomManager.cs @@ -18,11 +18,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay /// public class BasicTestRoomManager : IRoomManager { - public event Action RoomsUpdated - { - add { } - remove { } - } + public event Action RoomsUpdated; public readonly BindableList Rooms = new BindableList(); @@ -35,8 +31,21 @@ namespace osu.Game.Tests.Visual.OnlinePlay public void CreateRoom(Room room, Action onSuccess = null, Action onError = null) { room.RoomID.Value ??= Rooms.Select(r => r.RoomID.Value).Where(id => id != null).Select(id => id.Value).DefaultIfEmpty().Max() + 1; - Rooms.Add(room); onSuccess?.Invoke(room); + + AddRoom(room); + } + + public void AddRoom(Room room) + { + Rooms.Add(room); + RoomsUpdated?.Invoke(); + } + + public void RemoveRoom(Room room) + { + Rooms.Remove(room); + RoomsUpdated?.Invoke(); } public void JoinRoom(Room room, string password, Action onSuccess = null, Action onError = null) @@ -56,6 +65,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay var room = new Room { RoomID = { Value = i }, + Position = { Value = i }, Name = { Value = $"Room {i}" }, Host = { Value = new User { Username = "Host" } }, EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) }, From 3770193edee3bf4ca6449dccc6d4c3b8e8c08b49 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 26 Jul 2021 13:22:11 +0900 Subject: [PATCH 2/2] Fix keyboard navigation at multiplayer lounge not iterating in correct order --- .../Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs index 07e412ee75..d2253b2d2c 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/Components/RoomsContainer.cs @@ -27,7 +27,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components private readonly IBindableList rooms = new BindableList(); private readonly FillFlowContainer roomFlow; - public IReadOnlyList Rooms => roomFlow; + + public IReadOnlyList Rooms => roomFlow.FlowingChildren.Cast().ToArray(); [Resolved(CanBeNull = true)] private Bindable filter { get; set; }