1
0
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:
Dean Herbert 2018-12-28 14:22:25 +09:00 committed by GitHub
commit 1b35eae1ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 2 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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;

View File

@ -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>

View File

@ -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;
}
}
}

View File

@ -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);
};