mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 02:32:59 +08:00
Merge pull request #3945 from smoogipoo/fix-room-ordering
Sort rooms based on their API position
This commit is contained in:
commit
1b35eae1ba
@ -71,6 +71,8 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
private class TestRoomManager : IRoomManager
|
||||
{
|
||||
public event Action RoomsUpdated;
|
||||
|
||||
public readonly BindableCollection<Room> Rooms = new BindableCollection<Room>();
|
||||
IBindableCollection<Room> IRoomManager.Rooms => Rooms;
|
||||
|
||||
|
@ -136,6 +136,8 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
public Func<Room, bool> CreateRequested;
|
||||
|
||||
public event Action RoomsUpdated;
|
||||
|
||||
public IBindableCollection<Room> Rooms { get; } = null;
|
||||
|
||||
public void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||
|
@ -79,6 +79,12 @@ namespace osu.Game.Online.Multiplayer
|
||||
set => MaxAttempts.Value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The position of this <see cref="Room"/> in the list. This is not read from or written to the API.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public int Position = -1;
|
||||
|
||||
public void CopyFrom(Room other)
|
||||
{
|
||||
RoomID.Value = other.RoomID;
|
||||
@ -103,6 +109,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
Playlist.AddRange(other.Playlist);
|
||||
else if (other.Playlist.Count > 0)
|
||||
Playlist.First().ID = other.Playlist.First().ID;
|
||||
|
||||
Position = other.Position;
|
||||
}
|
||||
|
||||
public bool ShouldSerializeRoomID() => false;
|
||||
|
@ -10,6 +10,11 @@ namespace osu.Game.Screens.Multi
|
||||
{
|
||||
public interface IRoomManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when the <see cref="Room"/>s have been updated.
|
||||
/// </summary>
|
||||
event Action RoomsUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// All the active <see cref="Room"/>s.
|
||||
/// </summary>
|
||||
|
@ -52,6 +52,8 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
rooms.ItemsAdded += addRooms;
|
||||
rooms.ItemsRemoved += removeRooms;
|
||||
|
||||
roomManager.RoomsUpdated += updateSorting;
|
||||
|
||||
addRooms(rooms);
|
||||
}
|
||||
|
||||
@ -104,6 +106,12 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSorting()
|
||||
{
|
||||
foreach (var room in roomFlow)
|
||||
roomFlow.SetLayoutPosition(room, room.Room.Position);
|
||||
}
|
||||
|
||||
private void selectRoom(Room room)
|
||||
{
|
||||
var drawable = roomFlow.FirstOrDefault(r => r.Room == room);
|
||||
@ -115,5 +123,13 @@ namespace osu.Game.Screens.Multi.Lounge.Components
|
||||
|
||||
selectedRoom.Value = room;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (roomManager != null)
|
||||
roomManager.RoomsUpdated -= updateSorting;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ namespace osu.Game.Screens.Multi
|
||||
{
|
||||
public class RoomManager : PollingComponent, IRoomManager
|
||||
{
|
||||
public event Action RoomsUpdated;
|
||||
|
||||
private readonly BindableCollection<Room> rooms = new BindableCollection<Room>();
|
||||
public IBindableCollection<Room> Rooms => rooms;
|
||||
|
||||
@ -52,6 +54,8 @@ namespace osu.Game.Screens.Multi
|
||||
update(room, result);
|
||||
addRoom(room);
|
||||
|
||||
RoomsUpdated?.Invoke();
|
||||
|
||||
onSuccess?.Invoke(room);
|
||||
};
|
||||
|
||||
@ -125,13 +129,17 @@ namespace osu.Game.Screens.Multi
|
||||
rooms.Remove(r);
|
||||
}
|
||||
|
||||
// Add new matches, or update existing
|
||||
foreach (var r in result)
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
{
|
||||
var r = result[i];
|
||||
r.Position = i;
|
||||
|
||||
update(r, r);
|
||||
addRoom(r);
|
||||
}
|
||||
|
||||
RoomsUpdated?.Invoke();
|
||||
|
||||
tcs.SetResult(true);
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user