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

Simplify lounge implementation

This commit is contained in:
smoogipoo 2021-08-20 21:33:21 +09:00
parent b1a732b9b7
commit 5c8ca32ea4
3 changed files with 11 additions and 25 deletions

View File

@ -14,33 +14,24 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
{
public class LoungeBackgroundScreen : OnlinePlayBackgroundScreen
{
public readonly Bindable<Room> SelectedRoom = new Bindable<Room>();
private readonly BindableList<PlaylistItem> playlist = new BindableList<PlaylistItem>();
public LoungeBackgroundScreen()
{
SelectedRoom.BindValueChanged(onSelectedRoomChanged);
playlist.BindCollectionChanged((_, __) => PlaylistItem = playlist.FirstOrDefault());
}
private Room? selectedRoom;
public Room? SelectedRoom
private void onSelectedRoomChanged(ValueChangedEvent<Room> room)
{
get => selectedRoom;
set
{
if (selectedRoom == value)
return;
if (room.OldValue != null)
playlist.UnbindFrom(room.OldValue.Playlist);
if (selectedRoom != null)
playlist.UnbindFrom(selectedRoom.Playlist);
selectedRoom = value;
if (selectedRoom != null)
playlist.BindTo(selectedRoom.Playlist);
else
playlist.Clear();
}
if (room.NewValue != null)
playlist.BindTo(room.NewValue.Playlist);
else
playlist.Clear();
}
public override bool OnExiting(IScreen next)

View File

@ -36,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
{
public override string Title => "Lounge";
protected override BackgroundScreen CreateBackground() => new LoungeBackgroundScreen();
protected override BackgroundScreen CreateBackground() => new LoungeBackgroundScreen { SelectedRoom = { BindTarget = selectedRoom } };
protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby();
@ -166,8 +166,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
var drawable = roomsContainer.Rooms.FirstOrDefault(r => r.Room == val.NewValue);
if (drawable != null)
scrollContainer.ScrollIntoView(drawable);
ApplyToBackground(b => ((LoungeBackgroundScreen)b).SelectedRoom = val.NewValue);
});
}

View File

@ -29,10 +29,7 @@ namespace osu.Game.Screens.OnlinePlay.Match
[Cached(typeof(IBindable<PlaylistItem>))]
protected readonly Bindable<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
protected override BackgroundScreen CreateBackground() => new RoomBackgroundScreen
{
SelectedItem = { BindTarget = SelectedItem }
};
protected override BackgroundScreen CreateBackground() => new RoomBackgroundScreen { SelectedItem = { BindTarget = SelectedItem } };
public override bool DisallowExternalBeatmapRulesetChanges => true;