2019-01-24 17:43:03 +09: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.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2023-11-08 06:37:29 +03:00
|
|
|
|
using System.Diagnostics;
|
2020-10-30 22:40:24 +01:00
|
|
|
|
using System.Threading;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 19:04:31 +09:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Graphics;
|
2022-07-08 01:39:09 +09:00
|
|
|
|
using osu.Framework.Logging;
|
2023-11-16 15:37:53 +09:00
|
|
|
|
using osu.Framework.Platform;
|
2023-11-08 06:37:29 +03:00
|
|
|
|
using osu.Framework.Screens;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Framework.Threading;
|
2021-06-07 17:22:30 +09:00
|
|
|
|
using osu.Framework.Utils;
|
2019-09-24 17:42:06 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Configuration;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2018-12-27 17:25:28 +09:00
|
|
|
|
using osu.Game.Online.API;
|
2021-11-04 18:02:44 +09:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-12-27 17:25:28 +09:00
|
|
|
|
using osu.Game.Skinning;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Backgrounds
|
|
|
|
|
{
|
2022-11-24 14:32:20 +09:00
|
|
|
|
public partial class BackgroundScreenDefault : BackgroundScreen
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2019-03-20 14:17:35 +09:00
|
|
|
|
private Background background;
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
private int currentDisplay;
|
2024-01-29 19:33:07 +09:00
|
|
|
|
private const int background_count = 8;
|
2021-11-04 18:02:44 +09:00
|
|
|
|
private IBindable<APIUser> user;
|
2018-12-27 17:25:28 +09:00
|
|
|
|
private Bindable<Skin> skin;
|
2022-07-08 01:39:09 +09:00
|
|
|
|
private Bindable<BackgroundSource> source;
|
2020-07-02 19:12:45 +02:00
|
|
|
|
private Bindable<IntroSequence> introSequence;
|
2020-10-29 17:43:10 +01:00
|
|
|
|
private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader();
|
2019-09-24 17:42:06 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
2018-12-27 17:25:28 +09:00
|
|
|
|
|
2023-11-16 15:37:53 +09:00
|
|
|
|
[Resolved]
|
|
|
|
|
private GameHost gameHost { get; set; }
|
|
|
|
|
|
2021-06-03 13:24:21 +08:00
|
|
|
|
protected virtual bool AllowStoryboardBackground => true;
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
[BackgroundDependencyLoader]
|
2019-09-24 17:42:06 +08:00
|
|
|
|
private void load(IAPIProvider api, SkinManager skinManager, OsuConfigManager config)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2018-12-27 17:25:28 +09:00
|
|
|
|
user = api.LocalUser.GetBoundCopy();
|
|
|
|
|
skin = skinManager.CurrentSkin.GetBoundCopy();
|
2022-07-08 01:39:09 +09:00
|
|
|
|
source = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
|
2020-07-02 19:12:45 +02:00
|
|
|
|
introSequence = config.GetBindable<IntroSequence>(OsuSetting.IntroSequence);
|
2018-12-27 17:25:28 +09:00
|
|
|
|
|
2020-10-31 22:51:31 +09:00
|
|
|
|
AddInternal(seasonalBackgroundLoader);
|
2022-07-08 15:09:16 +09:00
|
|
|
|
}
|
2021-12-14 15:17:01 +09:00
|
|
|
|
|
2022-07-08 15:09:16 +09:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
user.ValueChanged += _ => Scheduler.AddOnce(next);
|
|
|
|
|
skin.ValueChanged += _ => Scheduler.AddOnce(next);
|
|
|
|
|
source.ValueChanged += _ => Scheduler.AddOnce(next);
|
|
|
|
|
beatmap.ValueChanged += _ => Scheduler.AddOnce(next);
|
|
|
|
|
introSequence.ValueChanged += _ => Scheduler.AddOnce(next);
|
|
|
|
|
seasonalBackgroundLoader.SeasonalBackgroundChanged += () => Scheduler.AddOnce(next);
|
2022-07-08 01:39:09 +09:00
|
|
|
|
|
2024-05-01 00:05:14 +08:00
|
|
|
|
currentDisplay = RNG.Next(0, background_count);
|
|
|
|
|
Next();
|
|
|
|
|
|
2022-07-08 15:09:16 +09:00
|
|
|
|
// helper function required for AddOnce usage.
|
|
|
|
|
void next() => Next();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2023-11-11 02:56:16 +03:00
|
|
|
|
private ScheduledDelegate storyboardUnloadDelegate;
|
|
|
|
|
|
2023-11-08 06:37:29 +03:00
|
|
|
|
public override void OnSuspending(ScreenTransitionEvent e)
|
|
|
|
|
{
|
|
|
|
|
var backgroundScreenStack = Parent as BackgroundScreenStack;
|
|
|
|
|
Debug.Assert(backgroundScreenStack != null);
|
|
|
|
|
|
|
|
|
|
if (background is BeatmapBackgroundWithStoryboard storyboardBackground)
|
2023-11-16 15:37:53 +09:00
|
|
|
|
storyboardUnloadDelegate = gameHost.UpdateThread.Scheduler.AddDelayed(storyboardBackground.UnloadStoryboard, TRANSITION_LENGTH);
|
2023-11-08 06:37:29 +03:00
|
|
|
|
|
|
|
|
|
base.OnSuspending(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void OnResuming(ScreenTransitionEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (background is BeatmapBackgroundWithStoryboard storyboardBackground)
|
2023-11-11 02:56:16 +03:00
|
|
|
|
{
|
|
|
|
|
if (storyboardUnloadDelegate?.Completed == false)
|
|
|
|
|
storyboardUnloadDelegate.Cancel();
|
|
|
|
|
else
|
|
|
|
|
storyboardBackground.LoadStoryboard();
|
|
|
|
|
|
|
|
|
|
storyboardUnloadDelegate = null;
|
|
|
|
|
}
|
2023-11-08 06:37:29 +03:00
|
|
|
|
|
|
|
|
|
base.OnResuming(e);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
private ScheduledDelegate nextTask;
|
2020-10-30 22:40:24 +01:00
|
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Request loading the next background.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Whether a new background was queued for load. May return false if the current background is still valid.</returns>
|
2021-12-14 16:10:53 +09:00
|
|
|
|
public virtual bool Next()
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2021-06-07 17:22:30 +09:00
|
|
|
|
var nextBackground = createBackground();
|
|
|
|
|
|
|
|
|
|
// in the case that the background hasn't changed, we want to avoid cancelling any tasks that could still be loading.
|
|
|
|
|
if (nextBackground == background)
|
|
|
|
|
return false;
|
|
|
|
|
|
2023-06-12 17:12:18 +09:00
|
|
|
|
Logger.Log(@"🌅 Global background change queued");
|
2022-07-08 01:39:09 +09:00
|
|
|
|
|
2020-10-30 22:40:24 +01:00
|
|
|
|
cancellationTokenSource?.Cancel();
|
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
2019-03-12 00:05:05 +09:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
nextTask?.Cancel();
|
|
|
|
|
nextTask = Scheduler.AddDelayed(() =>
|
|
|
|
|
{
|
2023-06-12 17:12:18 +09:00
|
|
|
|
Logger.Log(@"🌅 Global background loading");
|
2021-06-07 17:22:30 +09:00
|
|
|
|
LoadComponentAsync(nextBackground, displayNext, cancellationTokenSource.Token);
|
2022-11-04 17:19:03 +09:00
|
|
|
|
}, 500);
|
2018-12-27 17:25:28 +09:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-10-30 17:16:51 +01:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
private void displayNext(Background newBackground)
|
|
|
|
|
{
|
2022-11-04 17:36:11 +09:00
|
|
|
|
background?.FadeOut(800, Easing.OutQuint);
|
2021-06-07 17:22:30 +09:00
|
|
|
|
background?.Expire();
|
2020-10-30 17:16:51 +01:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
AddInternal(background = newBackground);
|
|
|
|
|
currentDisplay++;
|
|
|
|
|
}
|
2020-07-02 19:12:45 +02:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
private Background createBackground()
|
|
|
|
|
{
|
|
|
|
|
// seasonal background loading gets highest priority.
|
|
|
|
|
Background newBackground = seasonalBackgroundLoader.LoadNextBackground();
|
2020-07-02 19:12:45 +02:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
if (newBackground == null && user.Value?.IsSupporter == true)
|
2019-09-24 17:42:06 +08:00
|
|
|
|
{
|
2022-07-08 01:39:09 +09:00
|
|
|
|
switch (source.Value)
|
2019-09-24 17:42:06 +08:00
|
|
|
|
{
|
2019-11-22 02:38:31 +09:00
|
|
|
|
case BackgroundSource.Beatmap:
|
2021-06-02 15:51:43 +08:00
|
|
|
|
case BackgroundSource.BeatmapWithStoryboard:
|
2021-06-07 17:22:30 +09:00
|
|
|
|
{
|
2022-07-08 01:39:09 +09:00
|
|
|
|
if (source.Value == BackgroundSource.BeatmapWithStoryboard && AllowStoryboardBackground)
|
2021-06-07 17:32:04 +09:00
|
|
|
|
newBackground = new BeatmapBackgroundWithStoryboard(beatmap.Value, getBackgroundTextureName());
|
|
|
|
|
newBackground ??= new BeatmapBackground(beatmap.Value, getBackgroundTextureName());
|
|
|
|
|
|
2019-09-24 17:42:06 +08:00
|
|
|
|
break;
|
2021-06-07 17:22:30 +09:00
|
|
|
|
}
|
2021-06-08 22:04:59 +02:00
|
|
|
|
|
|
|
|
|
case BackgroundSource.Skin:
|
2022-09-15 16:02:57 +09:00
|
|
|
|
switch (skin.Value)
|
|
|
|
|
{
|
|
|
|
|
case TrianglesSkin:
|
|
|
|
|
case ArgonSkin:
|
|
|
|
|
case DefaultLegacySkin:
|
|
|
|
|
// default skins should use the default background rotation, which won't be the case if a SkinBackground is created for them.
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
newBackground = new SkinBackground(skin.Value, getBackgroundTextureName());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-06-09 07:59:47 +02:00
|
|
|
|
|
2021-06-08 22:04:59 +02:00
|
|
|
|
break;
|
2019-09-24 17:42:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-12-27 17:25:28 +09:00
|
|
|
|
|
2021-06-08 22:26:15 +02:00
|
|
|
|
// this method is called in many cases where the background might not necessarily need to change.
|
|
|
|
|
// if an equivalent background is currently being shown, we don't want to load it again.
|
|
|
|
|
if (newBackground?.Equals(background) == true)
|
|
|
|
|
return background;
|
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
newBackground ??= new Background(getBackgroundTextureName());
|
2019-03-20 15:13:59 +09:00
|
|
|
|
newBackground.Depth = currentDisplay;
|
2018-12-27 17:25:28 +09:00
|
|
|
|
|
2019-03-20 15:13:59 +09:00
|
|
|
|
return newBackground;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
2018-12-27 17:25:28 +09:00
|
|
|
|
|
2021-06-07 17:22:30 +09:00
|
|
|
|
private string getBackgroundTextureName()
|
|
|
|
|
{
|
|
|
|
|
switch (introSequence.Value)
|
|
|
|
|
{
|
|
|
|
|
case IntroSequence.Welcome:
|
|
|
|
|
return @"Intro/Welcome/menu-background";
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return $@"Menu/menu-background-{currentDisplay % background_count + 1}";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|