Files
osukey/osu.Game/Screens/OnlinePlay/Components/OnlinePlayBackgroundScreen.cs
Dean Herbert 58fb0c042b Remove background scale altogether
I'm not sure why this is required. Seems like something which was meant
to exist to handle parallax, but that is already handled elsewhere now.
2021-08-23 14:34:27 +09:00

94 lines
2.6 KiB
C#

// 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;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Screens;
using osu.Game.Online.Rooms;
using osuTK;
#nullable enable
namespace osu.Game.Screens.OnlinePlay.Components
{
public abstract class OnlinePlayBackgroundScreen : BackgroundScreen
{
private CancellationTokenSource? cancellationSource;
private PlaylistItemBackground? background;
protected OnlinePlayBackgroundScreen()
: base(false)
{
}
[BackgroundDependencyLoader]
private void load()
{
switchBackground(new PlaylistItemBackground(playlistItem));
}
private PlaylistItem? playlistItem;
protected PlaylistItem? PlaylistItem
{
get => playlistItem;
set
{
if (playlistItem == value)
return;
playlistItem = value;
if (LoadState > LoadState.Ready)
updateBackground();
}
}
private void updateBackground()
{
Schedule(() =>
{
var beatmap = playlistItem?.Beatmap.Value;
if (background?.BeatmapInfo?.BeatmapSet?.OnlineInfo?.Covers?.Cover == beatmap?.BeatmapSet?.OnlineInfo?.Covers?.Cover)
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;
newBackground.BlurTo(new Vector2(10));
AddInternal(background = newBackground);
}
public override void OnSuspending(IScreen next)
{
base.OnSuspending(next);
this.MoveToX(0, TRANSITION_LENGTH);
}
public override bool OnExiting(IScreen next)
{
var result = base.OnExiting(next);
this.MoveToX(0);
return result;
}
}
}