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
|
|
|
|
|
|
|
|
|
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;
|
2018-09-21 01:55:24 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Threading;
|
|
|
|
|
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
|
|
|
|
{
|
|
|
|
|
private int currentDisplay;
|
|
|
|
|
private const int background_count = 5;
|
|
|
|
|
|
|
|
|
|
private string backgroundName => $@"Menu/menu-background-{currentDisplay % background_count + 1}";
|
|
|
|
|
|
2018-12-27 16:25:28 +08:00
|
|
|
|
private Bindable<User> user;
|
|
|
|
|
private Bindable<Skin> skin;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2018-12-27 16:25:28 +08:00
|
|
|
|
private void load(IAPIProvider api, SkinManager skinManager)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-12-27 16:25:28 +08:00
|
|
|
|
user = api.LocalUser.GetBoundCopy();
|
|
|
|
|
skin = skinManager.CurrentSkin.GetBoundCopy();
|
|
|
|
|
|
|
|
|
|
user.ValueChanged += _ => Next();
|
|
|
|
|
skin.ValueChanged += _ => Next();
|
|
|
|
|
|
2018-09-21 01:55:24 +08:00
|
|
|
|
currentDisplay = RNG.Next(0, background_count);
|
2018-12-27 16:25:28 +08:00
|
|
|
|
|
|
|
|
|
Next();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void display(Background newBackground)
|
|
|
|
|
{
|
2018-09-21 02:13:34 +08:00
|
|
|
|
Background?.FadeOut(800, Easing.InOutSine);
|
|
|
|
|
Background?.Expire();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-01-23 19:52:00 +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(() =>
|
|
|
|
|
{
|
2018-12-27 16:25:28 +08:00
|
|
|
|
Background background;
|
|
|
|
|
|
|
|
|
|
if (user.Value?.IsSupporter ?? false)
|
|
|
|
|
background = new SkinnedBackground(skin.Value, backgroundName);
|
|
|
|
|
else
|
|
|
|
|
background = new Background(backgroundName);
|
|
|
|
|
|
|
|
|
|
background.Depth = currentDisplay;
|
|
|
|
|
|
|
|
|
|
LoadComponentAsync(background, display);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}, 100);
|
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
}
|