From 67a325f47dd608f625711a4e38b8968ee514716e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 20:32:14 +0100 Subject: [PATCH] Move config setting logic to background loader --- .../Backgrounds/SeasonalBackgroundLoader.cs | 17 +++++++++++++---- .../Backgrounds/BackgroundScreenDefault.cs | 14 +++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index 1c38e67451..a9b9929c79 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -18,12 +18,14 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { + private Bindable seasonalBackgroundMode; private Bindable seasonalBackgrounds; private int current; [BackgroundDependencyLoader] - private void load(SessionStatics sessionStatics, IAPIProvider api) + private void load(OsuConfigManager config, SessionStatics sessionStatics, IAPIProvider api) { + seasonalBackgroundMode = config.GetBindable(OsuSetting.SeasonalBackgroundMode); seasonalBackgrounds = sessionStatics.GetBindable(Static.SeasonalBackgrounds); if (seasonalBackgrounds.Value != null) return; @@ -38,10 +40,17 @@ private void load(SessionStatics sessionStatics, IAPIProvider api) api.PerformAsync(request); } - public SeasonalBackground LoadBackground() + public SeasonalBackground LoadNextBackground() { + if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Never + || (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && !isInSeason)) + { + return null; + } + var backgrounds = seasonalBackgrounds.Value.Backgrounds; - if (backgrounds == null || !backgrounds.Any()) return null; + if (backgrounds == null || !backgrounds.Any()) + return null; current = (current + 1) % backgrounds.Count; string url = backgrounds[current].Url; @@ -49,7 +58,7 @@ public SeasonalBackground LoadBackground() return new SeasonalBackground(url); } - public bool IsInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate; + private bool isInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate; } [LongRunningLoad] diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 45374e1223..cbe0841537 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -79,16 +79,12 @@ private Background createBackground() Background newBackground; string backgroundName; - if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always - || (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason)) - { - var seasonalBackground = seasonalBackgroundLoader.LoadBackground(); + var seasonalBackground = seasonalBackgroundLoader.LoadNextBackground(); - if (seasonalBackground != null) - { - seasonalBackground.Depth = currentDisplay; - return seasonalBackground; - } + if (seasonalBackground != null) + { + seasonalBackground.Depth = currentDisplay; + return seasonalBackground; } switch (introSequence.Value)