1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +08:00

Use Clear to trigger async disposal

This commit is contained in:
Salman Ahmed 2024-02-05 18:39:04 +03:00
parent 9923c1b6e6
commit 858f2fc749

View File

@ -126,7 +126,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null); Debug.Assert(args.OldItems != null);
if (args.OldItems.Count == roomFlow.Count)
clearRooms();
else
removeRooms(args.OldItems.Cast<Room>()); removeRooms(args.OldItems.Cast<Room>());
break; break;
} }
} }
@ -141,18 +145,9 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
private void removeRooms(IEnumerable<Room> rooms) private void removeRooms(IEnumerable<Room> rooms)
{ {
foreach (var room in rooms) foreach (var r in rooms)
{ {
var drawableRoom = roomFlow.SingleOrDefault(d => d.Room == room); roomFlow.RemoveAll(d => d.Room == r, true);
if (drawableRoom == null)
continue;
// expire to trigger async disposal. the room still has to exist somewhere so we move it to internal content of RoomsContainer until next frame.
drawableRoom.Hide();
drawableRoom.Expire();
roomFlow.Remove(drawableRoom, false);
AddInternal(drawableRoom);
// selection may have a lease due to being in a sub screen. // selection may have a lease due to being in a sub screen.
if (!SelectedRoom.Disabled) if (!SelectedRoom.Disabled)
@ -160,6 +155,15 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
} }
} }
private void clearRooms()
{
roomFlow.Clear();
// selection may have a lease due to being in a sub screen.
if (!SelectedRoom.Disabled)
SelectedRoom.Value = null;
}
private void updateSorting() private void updateSorting()
{ {
foreach (var room in roomFlow) foreach (var room in roomFlow)