mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 12:33:01 +08:00
Merge pull request #14018 from peppy/fix-keyboard-navigation-room-container
Fix keyboard navigation at multiplayer lounge not iterating in correct order
This commit is contained in:
commit
5e2222cc05
@ -4,6 +4,8 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Rulesets.Catch;
|
using osu.Game.Rulesets.Catch;
|
||||||
using osu.Game.Rulesets.Osu;
|
using osu.Game.Rulesets.Osu;
|
||||||
@ -62,6 +64,31 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
AddAssert("last room selected", () => checkRoomSelected(RoomManager.Rooms.Last()));
|
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]
|
[Test]
|
||||||
public void TestClickDeselection()
|
public void TestClickDeselection()
|
||||||
{
|
{
|
||||||
@ -121,5 +148,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
private bool checkRoomSelected(Room room) => SelectedRoom.Value == room;
|
private bool checkRoomSelected(Room room) => SelectedRoom.Value == room;
|
||||||
|
|
||||||
|
private Room getRoomInFlow(int index) =>
|
||||||
|
(container.ChildrenOfType<FillFlowContainer<DrawableRoom>>().First().FlowingChildren.ElementAt(index) as DrawableRoom)?.Room;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,8 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
|||||||
private readonly IBindableList<Room> rooms = new BindableList<Room>();
|
private readonly IBindableList<Room> rooms = new BindableList<Room>();
|
||||||
|
|
||||||
private readonly FillFlowContainer<DrawableRoom> roomFlow;
|
private readonly FillFlowContainer<DrawableRoom> roomFlow;
|
||||||
public IReadOnlyList<DrawableRoom> Rooms => roomFlow;
|
|
||||||
|
public IReadOnlyList<DrawableRoom> Rooms => roomFlow.FlowingChildren.Cast<DrawableRoom>().ToArray();
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private Bindable<FilterCriteria> filter { get; set; }
|
private Bindable<FilterCriteria> filter { get; set; }
|
||||||
|
@ -18,11 +18,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class BasicTestRoomManager : IRoomManager
|
public class BasicTestRoomManager : IRoomManager
|
||||||
{
|
{
|
||||||
public event Action RoomsUpdated
|
public event Action RoomsUpdated;
|
||||||
{
|
|
||||||
add { }
|
|
||||||
remove { }
|
|
||||||
}
|
|
||||||
|
|
||||||
public readonly BindableList<Room> Rooms = new BindableList<Room>();
|
public readonly BindableList<Room> Rooms = new BindableList<Room>();
|
||||||
|
|
||||||
@ -35,8 +31,21 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
{
|
{
|
||||||
room.RoomID.Value ??= Rooms.Select(r => r.RoomID.Value).Where(id => id != null).Select(id => id.Value).DefaultIfEmpty().Max() + 1;
|
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);
|
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<Room> onSuccess = null, Action<string> onError = null)
|
public void JoinRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
@ -56,6 +65,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
|||||||
var room = new Room
|
var room = new Room
|
||||||
{
|
{
|
||||||
RoomID = { Value = i },
|
RoomID = { Value = i },
|
||||||
|
Position = { Value = i },
|
||||||
Name = { Value = $"Room {i}" },
|
Name = { Value = $"Room {i}" },
|
||||||
Host = { Value = new User { Username = "Host" } },
|
Host = { Value = new User { Username = "Host" } },
|
||||||
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
EndDate = { Value = DateTimeOffset.Now + TimeSpan.FromSeconds(10) },
|
||||||
|
Loading…
Reference in New Issue
Block a user