1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-12 01:07:25 +08:00
osu-lazer/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs

144 lines
4.8 KiB
C#
Raw Normal View History

// 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
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;
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
{
public class BackgroundScreenDefault : BackgroundScreen
2018-04-13 17:19:50 +08:00
{
private Background background;
2018-04-13 17:19:50 +08:00
private int currentDisplay;
private const int background_count = 7;
private Bindable<User> user;
private Bindable<Skin> skin;
2019-11-22 01:38:31 +08:00
private Bindable<BackgroundSource> mode;
private Bindable<IntroSequence> introSequence;
private Bindable<SeasonalBackgroundMode> seasonalBackgroundMode;
private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader();
2019-09-24 17:42:06 +08:00
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; }
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
{
user = api.LocalUser.GetBoundCopy();
skin = skinManager.CurrentSkin.GetBoundCopy();
2019-11-22 01:38:31 +08:00
mode = config.GetBindable<BackgroundSource>(OsuSetting.MenuBackgroundSource);
introSequence = config.GetBindable<IntroSequence>(OsuSetting.IntroSequence);
seasonalBackgroundMode = config.GetBindable<SeasonalBackgroundMode>(OsuSetting.SeasonalBackgroundMode);
user.ValueChanged += _ => Next();
skin.ValueChanged += _ => Next();
2019-09-24 17:42:06 +08:00
mode.ValueChanged += _ => Next();
beatmap.ValueChanged += _ => Next();
introSequence.ValueChanged += _ => Next();
seasonalBackgroundMode.ValueChanged += _ => Next();
currentDisplay = RNG.Next(0, background_count);
LoadComponentAsync(seasonalBackgroundLoader, _ => LoadComponentAsync(createBackground(), display));
2018-04-13 17:19:50 +08:00
}
private void display(Background newBackground)
{
background?.FadeOut(800, Easing.InOutSine);
background?.Expire();
2018-04-13 17:19:50 +08:00
AddInternal(background = newBackground);
2018-04-13 17:19:50 +08:00
currentDisplay++;
}
private ScheduledDelegate nextTask;
public void Next()
{
nextTask?.Cancel();
nextTask = Scheduler.AddDelayed(() => { LoadComponentAsync(createBackground(), display); }, 100);
}
private Background createBackground()
{
2019-03-20 14:13:59 +08:00
Background newBackground;
2020-07-03 01:45:18 +08:00
string backgroundName;
if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always
2020-10-31 01:07:07 +08:00
|| (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason))
{
var seasonalBackground = seasonalBackgroundLoader.LoadBackground();
if (seasonalBackground != null)
{
seasonalBackground.Depth = currentDisplay;
return seasonalBackground;
}
}
switch (introSequence.Value)
{
case IntroSequence.Welcome:
backgroundName = "Intro/Welcome/menu-background";
break;
default:
backgroundName = $@"Menu/menu-background-{currentDisplay % background_count + 1}";
break;
}
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;
}
}
else
newBackground = new Background(backgroundName);
2019-03-20 14:13:59 +08:00
newBackground.Depth = currentDisplay;
2019-03-20 14:13:59 +08:00
return newBackground;
2018-04-13 17:19:50 +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)
{
this.skin = skin;
}
[BackgroundDependencyLoader]
private void load()
{
Sprite.Texture = skin.GetTexture("menu-background") ?? Sprite.Texture;
}
}
2018-04-13 17:19:50 +08:00
}
}