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

Initial room background implementation

This commit is contained in:
smoogipoo 2021-08-20 18:14:12 +09:00
parent 258ba4674c
commit c22c6f3a49
5 changed files with 83 additions and 25 deletions

View File

@ -1,57 +1,47 @@
// 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.
#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<PlaylistItem> playlist = new BindableList<PlaylistItem>();
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)

View File

@ -0,0 +1,45 @@
// 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.
#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<PlaylistItem> playlist = new BindableList<PlaylistItem>();
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();
}
}
}
}

View File

@ -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);
});
}

View File

@ -0,0 +1,19 @@
// 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.
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<PlaylistItem> SelectedItem = new Bindable<PlaylistItem>();
public RoomBackgroundScreen()
{
SelectedItem.BindValueChanged(item => PlaylistItem = item.NewValue);
}
}
}

View File

@ -29,6 +29,11 @@ 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 }
};
public override bool DisallowExternalBeatmapRulesetChanges => true;
/// <summary>