2021-08-19 18:10:54 +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.
|
|
|
|
|
|
|
|
using System.Threading;
|
2021-08-20 16:05:46 +08:00
|
|
|
using osu.Framework.Allocation;
|
2021-08-19 18:10:54 +08:00
|
|
|
using osu.Framework.Graphics;
|
2021-08-23 14:26:39 +08:00
|
|
|
using osu.Framework.Graphics.Colour;
|
2021-08-20 16:50:49 +08:00
|
|
|
using osu.Framework.Screens;
|
2021-11-01 16:30:19 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2021-08-19 18:10:54 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
|
|
|
using osuTK;
|
2021-08-23 14:26:39 +08:00
|
|
|
using osuTK.Graphics;
|
2021-08-19 18:10:54 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.Components
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
public abstract partial class OnlinePlayBackgroundScreen : BackgroundScreen
|
2021-08-19 18:10:54 +08:00
|
|
|
{
|
|
|
|
private CancellationTokenSource? cancellationSource;
|
|
|
|
private PlaylistItemBackground? background;
|
|
|
|
|
2021-08-20 16:05:46 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2021-08-20 17:14:12 +08:00
|
|
|
switchBackground(new PlaylistItemBackground(playlistItem));
|
2021-08-20 16:05:46 +08:00
|
|
|
}
|
|
|
|
|
2021-08-20 17:14:12 +08:00
|
|
|
private PlaylistItem? playlistItem;
|
2021-08-19 18:10:54 +08:00
|
|
|
|
2021-08-20 17:14:12 +08:00
|
|
|
protected PlaylistItem? PlaylistItem
|
2021-08-19 18:10:54 +08:00
|
|
|
{
|
2021-08-20 17:14:12 +08:00
|
|
|
get => playlistItem;
|
2021-08-19 18:10:54 +08:00
|
|
|
set
|
|
|
|
{
|
2021-08-20 17:14:12 +08:00
|
|
|
if (playlistItem == value)
|
2021-08-19 18:10:54 +08:00
|
|
|
return;
|
|
|
|
|
2021-08-20 17:14:12 +08:00
|
|
|
playlistItem = value;
|
2021-08-19 18:10:54 +08:00
|
|
|
|
2021-08-20 17:14:12 +08:00
|
|
|
if (LoadState > LoadState.Ready)
|
|
|
|
updateBackground();
|
2021-08-19 18:10:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateBackground()
|
|
|
|
{
|
|
|
|
Schedule(() =>
|
|
|
|
{
|
2022-02-15 22:33:26 +08:00
|
|
|
var beatmap = playlistItem?.Beatmap;
|
2021-11-04 14:35:32 +08:00
|
|
|
|
2021-11-01 16:30:19 +08:00
|
|
|
string? lastCover = (background?.Beatmap?.BeatmapSet as IBeatmapSetOnlineInfo)?.Covers.Cover;
|
2021-11-04 14:35:32 +08:00
|
|
|
string? newCover = (beatmap?.BeatmapSet as IBeatmapSetOnlineInfo)?.Covers.Cover;
|
2021-11-01 16:30:19 +08:00
|
|
|
|
|
|
|
if (lastCover == newCover)
|
2021-08-19 18:10:54 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
cancellationSource?.Cancel();
|
|
|
|
LoadComponentAsync(new PlaylistItemBackground(playlistItem), switchBackground, (cancellationSource = new CancellationTokenSource()).Token);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void switchBackground(PlaylistItemBackground newBackground)
|
|
|
|
{
|
|
|
|
float newDepth = 0;
|
|
|
|
|
|
|
|
if (background != null)
|
|
|
|
{
|
|
|
|
newDepth = background.Depth + 1;
|
|
|
|
background.FinishTransforms();
|
|
|
|
background.FadeOut(250);
|
|
|
|
background.Expire();
|
|
|
|
}
|
|
|
|
|
|
|
|
newBackground.Depth = newDepth;
|
2024-08-17 05:59:44 +08:00
|
|
|
newBackground.Colour = ColourInfo.GradientVertical(new Color4(0.1f, 0.1f, 0.1f, 1f), new Color4(0.4f, 0.4f, 0.4f, 1f));
|
2021-08-19 18:10:54 +08:00
|
|
|
newBackground.BlurTo(new Vector2(10));
|
|
|
|
|
|
|
|
AddInternal(background = newBackground);
|
|
|
|
}
|
2021-08-20 16:50:49 +08:00
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
2021-08-20 16:50:49 +08:00
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
base.OnSuspending(e);
|
2021-08-20 16:50:49 +08:00
|
|
|
this.MoveToX(0, TRANSITION_LENGTH);
|
|
|
|
}
|
|
|
|
|
2022-04-21 23:52:44 +08:00
|
|
|
public override bool OnExiting(ScreenExitEvent e)
|
2021-08-20 16:50:49 +08:00
|
|
|
{
|
2022-04-21 23:52:44 +08:00
|
|
|
bool result = base.OnExiting(e);
|
2021-08-20 16:50:49 +08:00
|
|
|
this.MoveToX(0);
|
|
|
|
return result;
|
|
|
|
}
|
2021-08-19 18:10:54 +08:00
|
|
|
}
|
|
|
|
}
|