1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 12:33:01 +08:00

Directly bind to room updates

Currently doesn't really cause any difference, however it may in the
future if we decide the queueing algorithm shouldn't update PlaylistOrder
when an item has been played.
This commit is contained in:
Dan Balasescu 2021-12-21 18:40:26 +09:00
parent e2f8c71081
commit 4ce61d4260

View File

@ -8,7 +8,6 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osuTK;
@ -54,12 +53,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
[Resolved]
private MultiplayerClient multiplayerClient { get; set; }
[Resolved(typeof(Room), nameof(Room.Host))]
private Bindable<APIUser> host { get; set; }
[Resolved(typeof(Room), nameof(Room.QueueMode))]
private Bindable<QueueMode> queueMode { get; set; }
public QueuePlaylistItem(PlaylistItem item)
: base(item)
{
@ -71,11 +64,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
RequestDeletion = item => multiplayerClient.RemovePlaylistItem(item.ID);
host.BindValueChanged(_ => updateDeleteButtonVisibility());
queueMode.BindValueChanged(_ => updateDeleteButtonVisibility());
SelectedItem.BindValueChanged(_ => updateDeleteButtonVisibility(), true);
multiplayerClient.RoomUpdated += onRoomUpdated;
onRoomUpdated();
}
private void onRoomUpdated() => Scheduler.AddOnce(updateDeleteButtonVisibility);
private void updateDeleteButtonVisibility()
{
if (multiplayerClient.Room == null)
@ -86,6 +80,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
AllowDeletion = isItemOwner && !Item.Expired && Item.ID != multiplayerClient.Room.Settings.PlaylistItemId;
AllowEditing = isItemOwner && !Item.Expired;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (multiplayerClient != null)
multiplayerClient.RoomUpdated -= onRoomUpdated;
}
}
}
}