diff --git a/osu.Game/Screens/OnlinePlay/Components/RoomBackgroundScreen.cs b/osu.Game/Screens/OnlinePlay/Components/OnlinePlayBackgroundScreen.cs similarity index 74% rename from osu.Game/Screens/OnlinePlay/Components/RoomBackgroundScreen.cs rename to osu.Game/Screens/OnlinePlay/Components/OnlinePlayBackgroundScreen.cs index 393cf49bb7..5077979bf0 100644 --- a/osu.Game/Screens/OnlinePlay/Components/RoomBackgroundScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Components/OnlinePlayBackgroundScreen.cs @@ -1,57 +1,47 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -#nullable enable - -using System.Linq; using System.Threading; using osu.Framework.Allocation; -using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Screens; using osu.Game.Online.Rooms; using osuTK; +#nullable enable + namespace osu.Game.Screens.OnlinePlay.Components { - public class RoomBackgroundScreen : BackgroundScreen + public abstract class OnlinePlayBackgroundScreen : BackgroundScreen { private CancellationTokenSource? cancellationSource; private PlaylistItemBackground? background; - private readonly BindableList playlist = new BindableList(); - - public RoomBackgroundScreen() + protected OnlinePlayBackgroundScreen() : base(false) { - playlist.BindCollectionChanged((_, __) => updateBackground()); } [BackgroundDependencyLoader] private void load() { - switchBackground(new PlaylistItemBackground(null)); + switchBackground(new PlaylistItemBackground(playlistItem)); } - private Room? room; + private PlaylistItem? playlistItem; - public Room? Room + protected PlaylistItem? PlaylistItem { - get => room; + get => playlistItem; set { - if (room == value) + if (playlistItem == value) return; - if (room != null) - playlist.UnbindFrom(room.Playlist); + playlistItem = value; - room = value; - - if (room != null) - playlist.BindTo(room.Playlist); - else - playlist.Clear(); + if (LoadState > LoadState.Ready) + updateBackground(); } } @@ -59,7 +49,6 @@ namespace osu.Game.Screens.OnlinePlay.Components { Schedule(() => { - var playlistItem = playlist.FirstOrDefault(); var beatmap = playlistItem?.Beatmap.Value; if (background?.BeatmapInfo?.BeatmapSet?.OnlineInfo?.Covers?.Cover == beatmap?.BeatmapSet?.OnlineInfo?.Covers?.Cover) diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeBackgroundScreen.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeBackgroundScreen.cs new file mode 100644 index 0000000000..7d38e220d3 --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeBackgroundScreen.cs @@ -0,0 +1,45 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +#nullable enable + +using System.Linq; +using osu.Framework.Bindables; +using osu.Game.Online.Rooms; +using osu.Game.Screens.OnlinePlay.Components; +using PlaylistItem = osu.Game.Online.Rooms.PlaylistItem; + +namespace osu.Game.Screens.OnlinePlay.Lounge +{ + public class LoungeBackgroundScreen : OnlinePlayBackgroundScreen + { + private readonly BindableList playlist = new BindableList(); + + public LoungeBackgroundScreen() + { + playlist.BindCollectionChanged((_, __) => PlaylistItem = playlist.FirstOrDefault()); + } + + private Room? selectedRoom; + + public Room? SelectedRoom + { + get => selectedRoom; + set + { + if (selectedRoom == value) + return; + + if (selectedRoom != null) + playlist.UnbindFrom(selectedRoom.Playlist); + + selectedRoom = value; + + if (selectedRoom != null) + playlist.BindTo(selectedRoom.Playlist); + else + playlist.Clear(); + } + } + } +} diff --git a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs index 34beba923f..90e5a62d7e 100644 --- a/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Lounge/LoungeSubScreen.cs @@ -36,7 +36,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge { public override string Title => "Lounge"; - protected override BackgroundScreen CreateBackground() => new RoomBackgroundScreen(); + protected override BackgroundScreen CreateBackground() => new LoungeBackgroundScreen(); protected override UserActivity InitialActivity => new UserActivity.SearchingForLobby(); @@ -169,7 +169,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge if (drawable != null) scrollContainer.ScrollIntoView(drawable); - ApplyToBackground(b => ((RoomBackgroundScreen)b).Room = val.NewValue); + ApplyToBackground(b => ((LoungeBackgroundScreen)b).SelectedRoom = val.NewValue); }); } diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomBackgroundScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomBackgroundScreen.cs new file mode 100644 index 0000000000..cacc3864c2 --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Match/RoomBackgroundScreen.cs @@ -0,0 +1,19 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Bindables; +using osu.Game.Online.Rooms; +using osu.Game.Screens.OnlinePlay.Components; + +namespace osu.Game.Screens.OnlinePlay.Match +{ + public class RoomBackgroundScreen : OnlinePlayBackgroundScreen + { + public readonly Bindable SelectedItem = new Bindable(); + + public RoomBackgroundScreen() + { + SelectedItem.BindValueChanged(item => PlaylistItem = item.NewValue); + } + } +} diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index d6a23ff708..8097e91c2e 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -29,6 +29,11 @@ namespace osu.Game.Screens.OnlinePlay.Match [Cached(typeof(IBindable))] protected readonly Bindable SelectedItem = new Bindable(); + protected override BackgroundScreen CreateBackground() => new RoomBackgroundScreen + { + SelectedItem = { BindTarget = SelectedItem } + }; + public override bool DisallowExternalBeatmapRulesetChanges => true; ///