2021-08-20 17:14:12 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2024-11-14 16:57:32 +08:00
|
|
|
using System.ComponentModel;
|
2021-08-20 17:14:12 +08:00
|
|
|
using osu.Framework.Bindables;
|
2021-08-20 20:02:25 +08:00
|
|
|
using osu.Framework.Screens;
|
2021-08-20 17:14:12 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osu.Game.Screens.OnlinePlay.Components;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Lounge
|
|
|
|
{
|
|
|
|
public partial class LoungeBackgroundScreen : OnlinePlayBackgroundScreen
|
|
|
|
{
|
2022-11-16 17:47:58 +08:00
|
|
|
public readonly Bindable<Room?> SelectedRoom = new Bindable<Room?>();
|
2021-08-20 17:14:12 +08:00
|
|
|
private readonly BindableList<PlaylistItem> playlist = new BindableList<PlaylistItem>();
|
|
|
|
|
|
|
|
public LoungeBackgroundScreen()
|
|
|
|
{
|
2021-08-20 20:33:21 +08:00
|
|
|
SelectedRoom.BindValueChanged(onSelectedRoomChanged);
|
2022-06-24 20:25:23 +08:00
|
|
|
playlist.BindCollectionChanged((_, _) => PlaylistItem = playlist.GetCurrentItem());
|
2021-08-20 17:14:12 +08:00
|
|
|
}
|
|
|
|
|
2024-11-14 16:57:32 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
SelectedRoom.BindValueChanged(onSelectedRoomChanged, true);
|
|
|
|
}
|
|
|
|
|
2022-11-16 17:47:58 +08:00
|
|
|
private void onSelectedRoomChanged(ValueChangedEvent<Room?> room)
|
2021-08-20 17:14:12 +08:00
|
|
|
{
|
2021-08-20 20:33:21 +08:00
|
|
|
if (room.OldValue != null)
|
2024-11-14 16:57:32 +08:00
|
|
|
room.OldValue.PropertyChanged -= onRoomPropertyChanged;
|
2021-08-20 17:14:12 +08:00
|
|
|
|
2021-08-20 20:33:21 +08:00
|
|
|
if (room.NewValue != null)
|
2024-11-14 16:57:32 +08:00
|
|
|
room.NewValue.PropertyChanged += onRoomPropertyChanged;
|
|
|
|
|
|
|
|
updateCurrentItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
if (e.PropertyName == nameof(Room.Playlist))
|
|
|
|
updateCurrentItem();
|
2021-08-20 17:14:12 +08:00
|
|
|
}
|
2021-08-20 20:02:25 +08:00
|
|
|
|
2024-11-14 16:57:32 +08:00
|
|
|
private void updateCurrentItem()
|
|
|
|
=> PlaylistItem = SelectedRoom.Value?.Playlist.GetCurrentItem();
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-08-20 20:02:25 +08:00
|
|
|
{
|
|
|
|
// This screen never exits.
|
|
|
|
return true;
|
|
|
|
}
|
2024-11-14 16:57:32 +08:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (SelectedRoom.Value != null)
|
|
|
|
SelectedRoom.Value.PropertyChanged -= onRoomPropertyChanged;
|
|
|
|
}
|
2021-08-20 17:14:12 +08:00
|
|
|
}
|
|
|
|
}
|