mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 18:23:04 +08:00
Make SeasonalBackgroundLoader read from SessionStatics
This commit is contained in:
parent
76c0a790b4
commit
907e1921c7
@ -1,6 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
|
||||||
namespace osu.Game.Configuration
|
namespace osu.Game.Configuration
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -12,12 +15,14 @@ namespace osu.Game.Configuration
|
|||||||
{
|
{
|
||||||
Set(Static.LoginOverlayDisplayed, false);
|
Set(Static.LoginOverlayDisplayed, false);
|
||||||
Set(Static.MutedAudioNotificationShownOnce, false);
|
Set(Static.MutedAudioNotificationShownOnce, false);
|
||||||
|
Set(Static.SeasonalBackgrounds, new List<APISeasonalBackground>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Static
|
public enum Static
|
||||||
{
|
{
|
||||||
LoginOverlayDisplayed,
|
LoginOverlayDisplayed,
|
||||||
MutedAudioNotificationShownOnce
|
MutedAudioNotificationShownOnce,
|
||||||
|
SeasonalBackgrounds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,11 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
|
using osu.Game.Configuration;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
@ -17,17 +19,20 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
[LongRunningLoad]
|
[LongRunningLoad]
|
||||||
public class SeasonalBackgroundLoader : Component
|
public class SeasonalBackgroundLoader : Component
|
||||||
{
|
{
|
||||||
private List<APISeasonalBackground> backgrounds = new List<APISeasonalBackground>();
|
private Bindable<List<APISeasonalBackground>> backgrounds;
|
||||||
private int current;
|
private int current;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(IAPIProvider api)
|
private void load(SessionStatics sessionStatics, IAPIProvider api)
|
||||||
{
|
{
|
||||||
|
backgrounds = sessionStatics.GetBindable<List<APISeasonalBackground>>(Static.SeasonalBackgrounds);
|
||||||
|
if (backgrounds.Value.Any()) return;
|
||||||
|
|
||||||
var request = new GetSeasonalBackgroundsRequest();
|
var request = new GetSeasonalBackgroundsRequest();
|
||||||
request.Success += response =>
|
request.Success += response =>
|
||||||
{
|
{
|
||||||
backgrounds = response.Backgrounds ?? backgrounds;
|
backgrounds.Value = response.Backgrounds ?? backgrounds.Value;
|
||||||
current = RNG.Next(0, backgrounds.Count);
|
current = RNG.Next(0, backgrounds.Value.Count);
|
||||||
};
|
};
|
||||||
|
|
||||||
api.PerformAsync(request);
|
api.PerformAsync(request);
|
||||||
@ -37,10 +42,10 @@ namespace osu.Game.Graphics.Backgrounds
|
|||||||
{
|
{
|
||||||
string url = null;
|
string url = null;
|
||||||
|
|
||||||
if (backgrounds.Any())
|
if (backgrounds.Value.Any())
|
||||||
{
|
{
|
||||||
current = (current + 1) % backgrounds.Count;
|
current = (current + 1) % backgrounds.Value.Count;
|
||||||
url = backgrounds[current].Url;
|
url = backgrounds.Value[current].Url;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new SeasonalBackground(url, fallbackTextureName);
|
return new SeasonalBackground(url, fallbackTextureName);
|
||||||
|
Loading…
Reference in New Issue
Block a user