2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-31 05:40:24 +08:00
|
|
|
|
using System.Threading;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2020-01-09 12:43:44 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2019-09-24 17:42:06 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Configuration;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2018-12-27 16:25:28 +08:00
|
|
|
|
using osu.Game.Online.API;
|
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
|
using osu.Game.Users;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Backgrounds
|
|
|
|
|
{
|
2019-03-14 15:09:17 +08:00
|
|
|
|
public class BackgroundScreenDefault : BackgroundScreen
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-03-20 13:17:35 +08:00
|
|
|
|
private Background background;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private int currentDisplay;
|
2019-07-02 16:57:23 +08:00
|
|
|
|
private const int background_count = 7;
|
2020-12-18 14:16:36 +08:00
|
|
|
|
private IBindable<User> user;
|
2018-12-27 16:25:28 +08:00
|
|
|
|
private Bindable<Skin> skin;
|
2019-11-22 01:38:31 +08:00
|
|
|
|
private Bindable<BackgroundSource> mode;
|
2020-07-03 01:12:45 +08:00
|
|
|
|
private Bindable<IntroSequence> introSequence;
|
2020-10-30 00:43:10 +08: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 16:25:28 +08:00
|
|
|
|
|
2019-08-09 19:05:28 +08:00
|
|
|
|
public BackgroundScreenDefault(bool animateOnEnter = true)
|
|
|
|
|
: base(animateOnEnter)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2019-09-24 17:42:06 +08:00
|
|
|
|
private void load(IAPIProvider api, SkinManager skinManager, OsuConfigManager config)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-12-27 16:25:28 +08:00
|
|
|
|
user = api.LocalUser.GetBoundCopy();
|
|
|
|
|
skin = skinManager.CurrentSkin.GetBoundCopy();
|
2019-11-22 01:38:31 +08:00
|
|
|
|
mode = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
|
2020-07-03 01:12:45 +08:00
|
|
|
|
introSequence = config.GetBindable<IntroSequence>(OsuSetting.IntroSequence);
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
2020-10-31 21:51:31 +08:00
|
|
|
|
AddInternal(seasonalBackgroundLoader);
|
|
|
|
|
|
2018-12-27 16:25:28 +08:00
|
|
|
|
user.ValueChanged += _ => Next();
|
|
|
|
|
skin.ValueChanged += _ => Next();
|
2019-09-24 17:42:06 +08:00
|
|
|
|
mode.ValueChanged += _ => Next();
|
2019-11-22 01:32:02 +08:00
|
|
|
|
beatmap.ValueChanged += _ => Next();
|
2020-07-03 01:12:45 +08:00
|
|
|
|
introSequence.ValueChanged += _ => Next();
|
2020-10-31 05:03:26 +08:00
|
|
|
|
seasonalBackgroundLoader.SeasonalBackgroundChanged += Next;
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
2018-09-21 01:55:24 +08:00
|
|
|
|
currentDisplay = RNG.Next(0, background_count);
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
2020-10-31 05:40:24 +08:00
|
|
|
|
Next();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void display(Background newBackground)
|
|
|
|
|
{
|
2019-03-20 13:17:35 +08:00
|
|
|
|
background?.FadeOut(800, Easing.InOutSine);
|
|
|
|
|
background?.Expire();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-03-20 13:17:35 +08:00
|
|
|
|
AddInternal(background = newBackground);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
currentDisplay++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private ScheduledDelegate nextTask;
|
2020-10-31 05:40:24 +08:00
|
|
|
|
private CancellationTokenSource cancellationTokenSource;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
public void Next()
|
|
|
|
|
{
|
|
|
|
|
nextTask?.Cancel();
|
2020-10-31 05:40:24 +08:00
|
|
|
|
cancellationTokenSource?.Cancel();
|
|
|
|
|
cancellationTokenSource = new CancellationTokenSource();
|
|
|
|
|
nextTask = Scheduler.AddDelayed(() => LoadComponentAsync(createBackground(), display, cancellationTokenSource.Token), 100);
|
2019-03-11 23:05:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Background createBackground()
|
|
|
|
|
{
|
2019-03-20 14:13:59 +08:00
|
|
|
|
Background newBackground;
|
2020-07-03 01:45:18 +08:00
|
|
|
|
string backgroundName;
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
2020-10-31 03:32:14 +08:00
|
|
|
|
var seasonalBackground = seasonalBackgroundLoader.LoadNextBackground();
|
2020-10-31 00:16:51 +08:00
|
|
|
|
|
2020-10-31 03:32:14 +08:00
|
|
|
|
if (seasonalBackground != null)
|
|
|
|
|
{
|
|
|
|
|
seasonalBackground.Depth = currentDisplay;
|
|
|
|
|
return seasonalBackground;
|
2020-10-31 00:16:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-03 01:12:45 +08:00
|
|
|
|
switch (introSequence.Value)
|
|
|
|
|
{
|
|
|
|
|
case IntroSequence.Welcome:
|
2020-07-03 17:36:03 +08:00
|
|
|
|
backgroundName = "Intro/Welcome/menu-background";
|
2020-07-03 01:12:45 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
backgroundName = $@"Menu/menu-background-{currentDisplay % background_count + 1}";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-11 23:05:05 +08:00
|
|
|
|
if (user.Value?.IsSupporter ?? false)
|
2019-09-24 17:42:06 +08:00
|
|
|
|
{
|
|
|
|
|
switch (mode.Value)
|
|
|
|
|
{
|
2019-11-22 01:38:31 +08:00
|
|
|
|
case BackgroundSource.Beatmap:
|
2019-09-24 17:42:06 +08:00
|
|
|
|
newBackground = new BeatmapBackground(beatmap.Value, backgroundName);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
newBackground = new SkinnedBackground(skin.Value, backgroundName);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-11 23:05:05 +08:00
|
|
|
|
else
|
2020-10-29 23:01:22 +08:00
|
|
|
|
newBackground = new Background(backgroundName);
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
2019-03-20 14:13:59 +08:00
|
|
|
|
newBackground.Depth = currentDisplay;
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
2019-03-20 14:13:59 +08:00
|
|
|
|
return newBackground;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
|
|
|
|
private class SkinnedBackground : Background
|
|
|
|
|
{
|
|
|
|
|
private readonly Skin skin;
|
|
|
|
|
|
2019-02-28 12:31:40 +08:00
|
|
|
|
public SkinnedBackground(Skin skin, string fallbackTextureName)
|
|
|
|
|
: base(fallbackTextureName)
|
2018-12-27 16:25:28 +08:00
|
|
|
|
{
|
|
|
|
|
this.skin = skin;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
Sprite.Texture = skin.GetTexture("menu-background") ?? Sprite.Texture;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|