From 2871001cc294da01f2db8e8c35d84a86ab1503ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 22 Oct 2020 18:21:28 +0200 Subject: [PATCH 01/32] Add BackgroundSource.Seasonal --- osu.Game/Configuration/BackgroundSource.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Configuration/BackgroundSource.cs b/osu.Game/Configuration/BackgroundSource.cs index 5726e96eb1..beef9ef1de 100644 --- a/osu.Game/Configuration/BackgroundSource.cs +++ b/osu.Game/Configuration/BackgroundSource.cs @@ -6,6 +6,7 @@ namespace osu.Game.Configuration public enum BackgroundSource { Skin, - Beatmap + Beatmap, + Seasonal } } From cdb2d23578e6de7ca266a23a51b5fac2ed15b8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 22 Oct 2020 18:23:03 +0200 Subject: [PATCH 02/32] Set BackgroundSource.Seasonal as default setting --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 7d601c0cb9..5c5af701bb 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -130,7 +130,7 @@ namespace osu.Game.Configuration Set(OsuSetting.IntroSequence, IntroSequence.Triangles); - Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin); + Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Seasonal); } public OsuConfigManager(Storage storage) From 09d49aa0f7b2d953370e02897ef382bd3ea04f92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 22 Oct 2020 18:25:01 +0200 Subject: [PATCH 03/32] Add GetSeasonalBackgroundsRequest --- .../Requests/GetSeasonalBackgroundsRequest.cs | 12 +++++++++++ .../Responses/APISeasonalBackgrounds.cs | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 osu.Game/Online/API/Requests/GetSeasonalBackgroundsRequest.cs create mode 100644 osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs diff --git a/osu.Game/Online/API/Requests/GetSeasonalBackgroundsRequest.cs b/osu.Game/Online/API/Requests/GetSeasonalBackgroundsRequest.cs new file mode 100644 index 0000000000..941b47244a --- /dev/null +++ b/osu.Game/Online/API/Requests/GetSeasonalBackgroundsRequest.cs @@ -0,0 +1,12 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Online.API.Requests +{ + public class GetSeasonalBackgroundsRequest : APIRequest + { + protected override string Target => @"seasonal-backgrounds"; + } +} diff --git a/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs b/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs new file mode 100644 index 0000000000..6996ac4d9b --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs @@ -0,0 +1,20 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class APISeasonalBackgrounds + { + [JsonProperty("backgrounds")] + public List Backgrounds { get; set; } + } + + public class APISeasonalBackground + { + [JsonProperty("url")] + public string Url { get; set; } + } +} From c1d03a5baceb23be78f0d55458a9085ad5b652ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 23 Oct 2020 13:40:13 +0200 Subject: [PATCH 04/32] Add SeasonalBackgroundLoader and SeasonalBackground --- .../Backgrounds/SeasonalBackgroundLoader.cs | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs new file mode 100644 index 0000000000..af81b25cee --- /dev/null +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -0,0 +1,68 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using JetBrains.Annotations; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Textures; +using osu.Framework.Utils; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Graphics.Backgrounds +{ + [LongRunningLoad] + public class SeasonalBackgroundLoader : Component + { + private List backgrounds = new List(); + private int current; + + [BackgroundDependencyLoader] + private void load(IAPIProvider api) + { + var request = new GetSeasonalBackgroundsRequest(); + request.Success += response => + { + backgrounds = response.Backgrounds ?? backgrounds; + current = RNG.Next(0, backgrounds.Count); + }; + + api.PerformAsync(request); + } + + public SeasonalBackground LoadBackground(string fallbackTextureName) + { + string url = null; + + if (backgrounds.Any()) + { + current = (current + 1) % backgrounds.Count; + url = backgrounds[current].Url; + } + + return new SeasonalBackground(url, fallbackTextureName); + } + } + + [LongRunningLoad] + public class SeasonalBackground : Background + { + private readonly string url; + private readonly string fallbackTextureName; + + public SeasonalBackground([CanBeNull] string url, string fallbackTextureName = @"Backgrounds/bg1") + { + this.url = url; + this.fallbackTextureName = fallbackTextureName; + } + + [BackgroundDependencyLoader] + private void load(LargeTextureStore textures) + { + Sprite.Texture = textures.Get(url) ?? textures.Get(fallbackTextureName); + } + } +} From 81ebcd879668eb13cb28aa11bf4edfb8afb0fb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 23 Oct 2020 13:41:00 +0200 Subject: [PATCH 05/32] Load SeasonalBackgroundLoader asynchronously --- .../Backgrounds/BackgroundScreenDefault.cs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index ef41c5be3d..ec91dcc99f 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -25,6 +25,7 @@ namespace osu.Game.Screens.Backgrounds private Bindable skin; private Bindable mode; private Bindable introSequence; + private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader(); [Resolved] private IBindable beatmap { get; set; } @@ -50,7 +51,7 @@ namespace osu.Game.Screens.Backgrounds currentDisplay = RNG.Next(0, background_count); - display(createBackground()); + LoadComponentAsync(seasonalBackgroundLoader, _ => LoadComponentAsync(createBackground(), display)); } private void display(Background newBackground) @@ -90,6 +91,10 @@ namespace osu.Game.Screens.Backgrounds { switch (mode.Value) { + case BackgroundSource.Seasonal: + newBackground = seasonalBackgroundLoader.LoadBackground(backgroundName); + break; + case BackgroundSource.Beatmap: newBackground = new BeatmapBackground(beatmap.Value, backgroundName); break; @@ -100,7 +105,18 @@ namespace osu.Game.Screens.Backgrounds } } else - newBackground = new Background(backgroundName); + { + switch (mode.Value) + { + case BackgroundSource.Seasonal: + newBackground = seasonalBackgroundLoader.LoadBackground(backgroundName); + break; + + default: + newBackground = new Background(backgroundName); + break; + } + } newBackground.Depth = currentDisplay; From 0c540537c9f3dde85e4ac74718be9d71a07c19b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 14:30:50 +0100 Subject: [PATCH 06/32] Revert "Add BackgroundSource.Seasonal" This reverts commit 2871001cc294da01f2db8e8c35d84a86ab1503ac. --- osu.Game/Configuration/BackgroundSource.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Configuration/BackgroundSource.cs b/osu.Game/Configuration/BackgroundSource.cs index beef9ef1de..5726e96eb1 100644 --- a/osu.Game/Configuration/BackgroundSource.cs +++ b/osu.Game/Configuration/BackgroundSource.cs @@ -6,7 +6,6 @@ namespace osu.Game.Configuration public enum BackgroundSource { Skin, - Beatmap, - Seasonal + Beatmap } } From 7d523fee2896c71b7bb919cf99f41e88bb3ed2d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 14:31:07 +0100 Subject: [PATCH 07/32] Revert "Set BackgroundSource.Seasonal as default setting" This reverts commit cdb2d23578e6de7ca266a23a51b5fac2ed15b8f4. --- osu.Game/Configuration/OsuConfigManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 5c5af701bb..7d601c0cb9 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -130,7 +130,7 @@ namespace osu.Game.Configuration Set(OsuSetting.IntroSequence, IntroSequence.Triangles); - Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Seasonal); + Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin); } public OsuConfigManager(Storage storage) From b189e0b7cfd8e761b313ab3b1c27371ff270a056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 16:01:22 +0100 Subject: [PATCH 08/32] Revert "Load SeasonalBackgroundLoader asynchronously" This reverts commit 81ebcd879668eb13cb28aa11bf4edfb8afb0fb99. --- .../Backgrounds/BackgroundScreenDefault.cs | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index ec91dcc99f..ef41c5be3d 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -25,7 +25,6 @@ namespace osu.Game.Screens.Backgrounds private Bindable skin; private Bindable mode; private Bindable introSequence; - private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader(); [Resolved] private IBindable beatmap { get; set; } @@ -51,7 +50,7 @@ namespace osu.Game.Screens.Backgrounds currentDisplay = RNG.Next(0, background_count); - LoadComponentAsync(seasonalBackgroundLoader, _ => LoadComponentAsync(createBackground(), display)); + display(createBackground()); } private void display(Background newBackground) @@ -91,10 +90,6 @@ namespace osu.Game.Screens.Backgrounds { switch (mode.Value) { - case BackgroundSource.Seasonal: - newBackground = seasonalBackgroundLoader.LoadBackground(backgroundName); - break; - case BackgroundSource.Beatmap: newBackground = new BeatmapBackground(beatmap.Value, backgroundName); break; @@ -105,18 +100,7 @@ namespace osu.Game.Screens.Backgrounds } } else - { - switch (mode.Value) - { - case BackgroundSource.Seasonal: - newBackground = seasonalBackgroundLoader.LoadBackground(backgroundName); - break; - - default: - newBackground = new Background(backgroundName); - break; - } - } + newBackground = new Background(backgroundName); newBackground.Depth = currentDisplay; From 76c0a790b404ef1afd65e30078473126a8b677c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 17:28:04 +0100 Subject: [PATCH 09/32] Add separate Seasonal Backgrounds setting (Always, Sometimes, Never) --- osu.Game/Configuration/OsuConfigManager.cs | 2 ++ osu.Game/Configuration/SeasonalBackgrounds.cs | 12 ++++++++++++ .../Settings/Sections/Audio/MainMenuSettings.cs | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 osu.Game/Configuration/SeasonalBackgrounds.cs diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 7d601c0cb9..9f7280eef4 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -131,6 +131,7 @@ namespace osu.Game.Configuration Set(OsuSetting.IntroSequence, IntroSequence.Triangles); Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin); + Set(OsuSetting.SeasonalBackgrounds, SeasonalBackgrounds.Sometimes); } public OsuConfigManager(Storage storage) @@ -239,5 +240,6 @@ namespace osu.Game.Configuration HitLighting, MenuBackgroundSource, GameplayDisableWinKey, + SeasonalBackgrounds } } diff --git a/osu.Game/Configuration/SeasonalBackgrounds.cs b/osu.Game/Configuration/SeasonalBackgrounds.cs new file mode 100644 index 0000000000..7708ae584f --- /dev/null +++ b/osu.Game/Configuration/SeasonalBackgrounds.cs @@ -0,0 +1,12 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Configuration +{ + public enum SeasonalBackgrounds + { + Always, + Sometimes, + Never + } +} diff --git a/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs index d5de32ed05..ee57c0cfa6 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs @@ -39,6 +39,12 @@ namespace osu.Game.Overlays.Settings.Sections.Audio LabelText = "Background source", Current = config.GetBindable(OsuSetting.MenuBackgroundSource), Items = Enum.GetValues(typeof(BackgroundSource)).Cast() + }, + new SettingsDropdown + { + LabelText = "Seasonal backgrounds", + Current = config.GetBindable(OsuSetting.SeasonalBackgrounds), + Items = Enum.GetValues(typeof(SeasonalBackgrounds)).Cast() } }; } From 907e1921c720fc99cf9d76d135744fdf3d52fbeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 17:31:42 +0100 Subject: [PATCH 10/32] Make SeasonalBackgroundLoader read from SessionStatics --- osu.Game/Configuration/SessionStatics.cs | 7 ++++++- .../Backgrounds/SeasonalBackgroundLoader.cs | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 40b2adb867..326abed8fe 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -1,6 +1,9 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // 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 { /// @@ -12,12 +15,14 @@ namespace osu.Game.Configuration { Set(Static.LoginOverlayDisplayed, false); Set(Static.MutedAudioNotificationShownOnce, false); + Set(Static.SeasonalBackgrounds, new List()); } } public enum Static { LoginOverlayDisplayed, - MutedAudioNotificationShownOnce + MutedAudioNotificationShownOnce, + SeasonalBackgrounds } } diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index af81b25cee..72785be3b4 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -5,9 +5,11 @@ using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Textures; using osu.Framework.Utils; +using osu.Game.Configuration; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; @@ -17,17 +19,20 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { - private List backgrounds = new List(); + private Bindable> backgrounds; private int current; [BackgroundDependencyLoader] - private void load(IAPIProvider api) + private void load(SessionStatics sessionStatics, IAPIProvider api) { + backgrounds = sessionStatics.GetBindable>(Static.SeasonalBackgrounds); + if (backgrounds.Value.Any()) return; + var request = new GetSeasonalBackgroundsRequest(); request.Success += response => { - backgrounds = response.Backgrounds ?? backgrounds; - current = RNG.Next(0, backgrounds.Count); + backgrounds.Value = response.Backgrounds ?? backgrounds.Value; + current = RNG.Next(0, backgrounds.Value.Count); }; api.PerformAsync(request); @@ -37,10 +42,10 @@ namespace osu.Game.Graphics.Backgrounds { string url = null; - if (backgrounds.Any()) + if (backgrounds.Value.Any()) { - current = (current + 1) % backgrounds.Count; - url = backgrounds[current].Url; + current = (current + 1) % backgrounds.Value.Count; + url = backgrounds.Value[current].Url; } return new SeasonalBackground(url, fallbackTextureName); From bf4d99dfe7aa3ad5a4422430ae2079e4ef93d7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 17:43:10 +0100 Subject: [PATCH 11/32] Load SeasonalBackgroundLoader asynchronously --- osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index ef41c5be3d..98552dda71 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -25,6 +25,7 @@ namespace osu.Game.Screens.Backgrounds private Bindable skin; private Bindable mode; private Bindable introSequence; + private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader(); [Resolved] private IBindable beatmap { get; set; } @@ -50,7 +51,7 @@ namespace osu.Game.Screens.Backgrounds currentDisplay = RNG.Next(0, background_count); - display(createBackground()); + LoadComponentAsync(seasonalBackgroundLoader, _ => LoadComponentAsync(createBackground(), display)); } private void display(Background newBackground) From 34371b8888980ec2de400b16924657449263ea1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 17:44:23 +0100 Subject: [PATCH 12/32] Show next Background on showSeasonalBackgrounds.ValueChanged --- osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 98552dda71..1be19c5854 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -25,6 +25,7 @@ namespace osu.Game.Screens.Backgrounds private Bindable skin; private Bindable mode; private Bindable introSequence; + private Bindable showSeasonalBackgrounds; private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader(); [Resolved] @@ -42,12 +43,14 @@ namespace osu.Game.Screens.Backgrounds skin = skinManager.CurrentSkin.GetBoundCopy(); mode = config.GetBindable(OsuSetting.MenuBackgroundSource); introSequence = config.GetBindable(OsuSetting.IntroSequence); + showSeasonalBackgrounds = config.GetBindable(OsuSetting.SeasonalBackgrounds); user.ValueChanged += _ => Next(); skin.ValueChanged += _ => Next(); mode.ValueChanged += _ => Next(); beatmap.ValueChanged += _ => Next(); introSequence.ValueChanged += _ => Next(); + showSeasonalBackgrounds.ValueChanged += _ => Next(); currentDisplay = RNG.Next(0, background_count); From d9846fad37d4d2b9453621c2b225b9a3cf12cc8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 18:03:36 +0100 Subject: [PATCH 13/32] Remove fallback texture parameter When there isn't a seasonal event, we don't want to fall back to the basic background here, but rather to the user selected background source. --- .../Backgrounds/SeasonalBackgroundLoader.cs | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index 72785be3b4..abd9664106 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; -using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -38,17 +37,14 @@ namespace osu.Game.Graphics.Backgrounds api.PerformAsync(request); } - public SeasonalBackground LoadBackground(string fallbackTextureName) + public SeasonalBackground LoadBackground() { - string url = null; + if (!backgrounds.Value.Any()) return null; - if (backgrounds.Value.Any()) - { - current = (current + 1) % backgrounds.Value.Count; - url = backgrounds.Value[current].Url; - } + current = (current + 1) % backgrounds.Value.Count; + string url = backgrounds.Value[current].Url; - return new SeasonalBackground(url, fallbackTextureName); + return new SeasonalBackground(url); } } @@ -56,18 +52,17 @@ namespace osu.Game.Graphics.Backgrounds public class SeasonalBackground : Background { private readonly string url; - private readonly string fallbackTextureName; + private const string fallback_texture_name = @"Backgrounds/bg1"; - public SeasonalBackground([CanBeNull] string url, string fallbackTextureName = @"Backgrounds/bg1") + public SeasonalBackground(string url) { this.url = url; - this.fallbackTextureName = fallbackTextureName; } [BackgroundDependencyLoader] private void load(LargeTextureStore textures) { - Sprite.Texture = textures.Get(url) ?? textures.Get(fallbackTextureName); + Sprite.Texture = textures.Get(url) ?? textures.Get(fallback_texture_name); } } } From fb1e09b3e793fae71caada4ad754d586ce7f5a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Thu, 29 Oct 2020 18:04:48 +0100 Subject: [PATCH 14/32] Load seasonal backgrounds according to setting --- .../Screens/Backgrounds/BackgroundScreenDefault.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 1be19c5854..70eafd4aff 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -106,6 +106,18 @@ namespace osu.Game.Screens.Backgrounds else newBackground = new Background(backgroundName); + switch (showSeasonalBackgrounds.Value) + { + case SeasonalBackgrounds.Sometimes: + if (RNG.NextBool()) + goto case SeasonalBackgrounds.Always; + break; + + case SeasonalBackgrounds.Always: + newBackground = seasonalBackgroundLoader.LoadBackground() ?? newBackground; + break; + } + newBackground.Depth = currentDisplay; return newBackground; From f27ce7521d69295e7af78478118e436db6f400ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 10:27:43 +0100 Subject: [PATCH 15/32] Make "Sometimes" setting depend on season end date, rather than chance --- osu.Game/Configuration/SessionStatics.cs | 5 ++++- osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 8 ++++++++ .../API/Requests/Responses/APISeasonalBackgrounds.cs | 4 ++++ osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 326abed8fe..8100e0fb12 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using osu.Game.Online.API.Requests.Responses; @@ -15,6 +16,7 @@ namespace osu.Game.Configuration { Set(Static.LoginOverlayDisplayed, false); Set(Static.MutedAudioNotificationShownOnce, false); + Set(Static.SeasonEndDate, DateTimeOffset.MinValue); Set(Static.SeasonalBackgrounds, new List()); } } @@ -23,6 +25,7 @@ namespace osu.Game.Configuration { LoginOverlayDisplayed, MutedAudioNotificationShownOnce, - SeasonalBackgrounds + SeasonEndDate, + SeasonalBackgrounds, } } diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index abd9664106..d806c62650 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; @@ -18,19 +19,24 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { + private Bindable endDate; private Bindable> backgrounds; private int current; [BackgroundDependencyLoader] private void load(SessionStatics sessionStatics, IAPIProvider api) { + endDate = sessionStatics.GetBindable(Static.SeasonEndDate); backgrounds = sessionStatics.GetBindable>(Static.SeasonalBackgrounds); + if (backgrounds.Value.Any()) return; var request = new GetSeasonalBackgroundsRequest(); request.Success += response => { + endDate.Value = response.EndDate; backgrounds.Value = response.Backgrounds ?? backgrounds.Value; + current = RNG.Next(0, backgrounds.Value.Count); }; @@ -46,6 +52,8 @@ namespace osu.Game.Graphics.Backgrounds return new SeasonalBackground(url); } + + public bool IsInSeason() => DateTimeOffset.Now < endDate.Value; } [LongRunningLoad] diff --git a/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs b/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs index 6996ac4d9b..8e395f7397 100644 --- a/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs +++ b/osu.Game/Online/API/Requests/Responses/APISeasonalBackgrounds.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using Newtonsoft.Json; @@ -8,6 +9,9 @@ namespace osu.Game.Online.API.Requests.Responses { public class APISeasonalBackgrounds { + [JsonProperty("ends_at")] + public DateTimeOffset EndDate; + [JsonProperty("backgrounds")] public List Backgrounds { get; set; } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 70eafd4aff..de73c82d5c 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -109,7 +109,7 @@ namespace osu.Game.Screens.Backgrounds switch (showSeasonalBackgrounds.Value) { case SeasonalBackgrounds.Sometimes: - if (RNG.NextBool()) + if (seasonalBackgroundLoader.IsInSeason()) goto case SeasonalBackgrounds.Always; break; From 4e3fb615d25c6a2edfbec009401ec73f925840f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 15:54:10 +0100 Subject: [PATCH 16/32] Rename "SeasonalBackgrounds" to "SeasonalBackgroundMode" --- osu.Game/Configuration/OsuConfigManager.cs | 4 ++-- ...nalBackgrounds.cs => SeasonalBackgroundMode.cs} | 2 +- .../Settings/Sections/Audio/MainMenuSettings.cs | 6 +++--- .../Screens/Backgrounds/BackgroundScreenDefault.cs | 14 +++++++------- 4 files changed, 13 insertions(+), 13 deletions(-) rename osu.Game/Configuration/{SeasonalBackgrounds.cs => SeasonalBackgroundMode.cs} (86%) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index e579898c05..e0971d238a 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -131,7 +131,7 @@ namespace osu.Game.Configuration Set(OsuSetting.IntroSequence, IntroSequence.Triangles); Set(OsuSetting.MenuBackgroundSource, BackgroundSource.Skin); - Set(OsuSetting.SeasonalBackgrounds, SeasonalBackgrounds.Sometimes); + Set(OsuSetting.SeasonalBackgroundMode, SeasonalBackgroundMode.Sometimes); } public OsuConfigManager(Storage storage) @@ -241,6 +241,6 @@ namespace osu.Game.Configuration HitLighting, MenuBackgroundSource, GameplayDisableWinKey, - SeasonalBackgrounds + SeasonalBackgroundMode } } diff --git a/osu.Game/Configuration/SeasonalBackgrounds.cs b/osu.Game/Configuration/SeasonalBackgroundMode.cs similarity index 86% rename from osu.Game/Configuration/SeasonalBackgrounds.cs rename to osu.Game/Configuration/SeasonalBackgroundMode.cs index 7708ae584f..406736b2a4 100644 --- a/osu.Game/Configuration/SeasonalBackgrounds.cs +++ b/osu.Game/Configuration/SeasonalBackgroundMode.cs @@ -3,7 +3,7 @@ namespace osu.Game.Configuration { - public enum SeasonalBackgrounds + public enum SeasonalBackgroundMode { Always, Sometimes, diff --git a/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs index ee57c0cfa6..7682967d10 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/MainMenuSettings.cs @@ -40,11 +40,11 @@ namespace osu.Game.Overlays.Settings.Sections.Audio Current = config.GetBindable(OsuSetting.MenuBackgroundSource), Items = Enum.GetValues(typeof(BackgroundSource)).Cast() }, - new SettingsDropdown + new SettingsDropdown { LabelText = "Seasonal backgrounds", - Current = config.GetBindable(OsuSetting.SeasonalBackgrounds), - Items = Enum.GetValues(typeof(SeasonalBackgrounds)).Cast() + Current = config.GetBindable(OsuSetting.SeasonalBackgroundMode), + Items = Enum.GetValues(typeof(SeasonalBackgroundMode)).Cast() } }; } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index de73c82d5c..a5bdcee8d4 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -25,7 +25,7 @@ namespace osu.Game.Screens.Backgrounds private Bindable skin; private Bindable mode; private Bindable introSequence; - private Bindable showSeasonalBackgrounds; + private Bindable seasonalBackgroundMode; private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader(); [Resolved] @@ -43,14 +43,14 @@ namespace osu.Game.Screens.Backgrounds skin = skinManager.CurrentSkin.GetBoundCopy(); mode = config.GetBindable(OsuSetting.MenuBackgroundSource); introSequence = config.GetBindable(OsuSetting.IntroSequence); - showSeasonalBackgrounds = config.GetBindable(OsuSetting.SeasonalBackgrounds); + seasonalBackgroundMode = config.GetBindable(OsuSetting.SeasonalBackgroundMode); user.ValueChanged += _ => Next(); skin.ValueChanged += _ => Next(); mode.ValueChanged += _ => Next(); beatmap.ValueChanged += _ => Next(); introSequence.ValueChanged += _ => Next(); - showSeasonalBackgrounds.ValueChanged += _ => Next(); + seasonalBackgroundMode.ValueChanged += _ => Next(); currentDisplay = RNG.Next(0, background_count); @@ -106,14 +106,14 @@ namespace osu.Game.Screens.Backgrounds else newBackground = new Background(backgroundName); - switch (showSeasonalBackgrounds.Value) + switch (seasonalBackgroundMode.Value) { - case SeasonalBackgrounds.Sometimes: + case SeasonalBackgroundMode.Sometimes: if (seasonalBackgroundLoader.IsInSeason()) - goto case SeasonalBackgrounds.Always; + goto case SeasonalBackgroundMode.Always; break; - case SeasonalBackgrounds.Always: + case SeasonalBackgroundMode.Always: newBackground = seasonalBackgroundLoader.LoadBackground() ?? newBackground; break; } From d19dd4eef6ba621616f684b5b07d41d154d68f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 15:56:19 +0100 Subject: [PATCH 17/32] IsInSeason() -> IsInSeason --- osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 2 +- osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index d806c62650..ff1a2c9f37 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -53,7 +53,7 @@ namespace osu.Game.Graphics.Backgrounds return new SeasonalBackground(url); } - public bool IsInSeason() => DateTimeOffset.Now < endDate.Value; + public bool IsInSeason => DateTimeOffset.Now < endDate.Value; } [LongRunningLoad] diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index a5bdcee8d4..5fa4ddc041 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -109,7 +109,7 @@ namespace osu.Game.Screens.Backgrounds switch (seasonalBackgroundMode.Value) { case SeasonalBackgroundMode.Sometimes: - if (seasonalBackgroundLoader.IsInSeason()) + if (seasonalBackgroundLoader.IsInSeason) goto case SeasonalBackgroundMode.Always; break; From 6f6a8e2a8fe09581630728d0e347b48e91c3f80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 16:06:48 +0100 Subject: [PATCH 18/32] Convert switch to if --- .../Screens/Backgrounds/BackgroundScreenDefault.cs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 5fa4ddc041..39ecd70084 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -106,16 +106,10 @@ namespace osu.Game.Screens.Backgrounds else newBackground = new Background(backgroundName); - switch (seasonalBackgroundMode.Value) + if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always + || seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason) { - case SeasonalBackgroundMode.Sometimes: - if (seasonalBackgroundLoader.IsInSeason) - goto case SeasonalBackgroundMode.Always; - break; - - case SeasonalBackgroundMode.Always: - newBackground = seasonalBackgroundLoader.LoadBackground() ?? newBackground; - break; + newBackground = seasonalBackgroundLoader.LoadBackground() ?? newBackground; } newBackground.Depth = currentDisplay; From f6eb5680ec53626707452cf08c0926713fbf2ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 16:43:18 +0100 Subject: [PATCH 19/32] Save full api response in SessionStatics --- osu.Game/Configuration/SessionStatics.cs | 8 ++----- .../Backgrounds/SeasonalBackgroundLoader.cs | 24 ++++++++----------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 8100e0fb12..199889391b 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -1,8 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; -using System.Collections.Generic; using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Configuration @@ -16,8 +14,7 @@ namespace osu.Game.Configuration { Set(Static.LoginOverlayDisplayed, false); Set(Static.MutedAudioNotificationShownOnce, false); - Set(Static.SeasonEndDate, DateTimeOffset.MinValue); - Set(Static.SeasonalBackgrounds, new List()); + Set(Static.SeasonalBackgroundsResponse, null); } } @@ -25,7 +22,6 @@ namespace osu.Game.Configuration { LoginOverlayDisplayed, MutedAudioNotificationShownOnce, - SeasonEndDate, - SeasonalBackgrounds, + SeasonalBackgroundsResponse, } } diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index ff1a2c9f37..c884756c80 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -2,7 +2,6 @@ // See the LICENCE file in the repository root for full licence text. using System; -using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; @@ -19,25 +18,21 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { - private Bindable endDate; - private Bindable> backgrounds; + private Bindable cachedResponse; private int current; [BackgroundDependencyLoader] private void load(SessionStatics sessionStatics, IAPIProvider api) { - endDate = sessionStatics.GetBindable(Static.SeasonEndDate); - backgrounds = sessionStatics.GetBindable>(Static.SeasonalBackgrounds); + cachedResponse = sessionStatics.GetBindable(Static.SeasonalBackgroundsResponse); - if (backgrounds.Value.Any()) return; + if (cachedResponse.Value != null) return; var request = new GetSeasonalBackgroundsRequest(); request.Success += response => { - endDate.Value = response.EndDate; - backgrounds.Value = response.Backgrounds ?? backgrounds.Value; - - current = RNG.Next(0, backgrounds.Value.Count); + cachedResponse.Value = response; + current = RNG.Next(0, cachedResponse.Value.Backgrounds.Count); }; api.PerformAsync(request); @@ -45,15 +40,16 @@ namespace osu.Game.Graphics.Backgrounds public SeasonalBackground LoadBackground() { - if (!backgrounds.Value.Any()) return null; + var backgrounds = cachedResponse.Value.Backgrounds; + if (!backgrounds.Any()) return null; - current = (current + 1) % backgrounds.Value.Count; - string url = backgrounds.Value[current].Url; + current = (current + 1) % backgrounds.Count; + string url = backgrounds[current].Url; return new SeasonalBackground(url); } - public bool IsInSeason => DateTimeOffset.Now < endDate.Value; + public bool IsInSeason => DateTimeOffset.Now < cachedResponse.Value.EndDate; } [LongRunningLoad] From 0b46c19b23995f42e35b82877b41404200f109ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 17:16:51 +0100 Subject: [PATCH 20/32] Move seasonalBackgroundMode check up and early return if available --- .../Backgrounds/BackgroundScreenDefault.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index 39ecd70084..b65b45060f 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -79,6 +79,18 @@ namespace osu.Game.Screens.Backgrounds Background newBackground; string backgroundName; + if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always + || seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason) + { + var seasonalBackground = seasonalBackgroundLoader.LoadBackground(); + + if (seasonalBackground != null) + { + seasonalBackground.Depth = currentDisplay; + return seasonalBackground; + } + } + switch (introSequence.Value) { case IntroSequence.Welcome: @@ -106,12 +118,6 @@ namespace osu.Game.Screens.Backgrounds else newBackground = new Background(backgroundName); - if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always - || seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason) - { - newBackground = seasonalBackgroundLoader.LoadBackground() ?? newBackground; - } - newBackground.Depth = currentDisplay; return newBackground; From 51a58269add518f7ea68f590fceeff11612cc5c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 17:57:29 +0100 Subject: [PATCH 21/32] Fix nullref in case of successfull request but no backgrounds available --- osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index c884756c80..daceb05fd7 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -32,7 +32,7 @@ namespace osu.Game.Graphics.Backgrounds request.Success += response => { cachedResponse.Value = response; - current = RNG.Next(0, cachedResponse.Value.Backgrounds.Count); + current = RNG.Next(0, response.Backgrounds?.Count ?? 0); }; api.PerformAsync(request); @@ -41,7 +41,7 @@ namespace osu.Game.Graphics.Backgrounds public SeasonalBackground LoadBackground() { var backgrounds = cachedResponse.Value.Backgrounds; - if (!backgrounds.Any()) return null; + if (backgrounds == null || !backgrounds.Any()) return null; current = (current + 1) % backgrounds.Count; string url = backgrounds[current].Url; From d5dfd1dffeee753cb47d70afc87a1b3055e1962e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Max=20H=C3=BCbner?= Date: Fri, 30 Oct 2020 18:07:07 +0100 Subject: [PATCH 22/32] Insert optional parentheses --- osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index b65b45060f..45374e1223 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -80,7 +80,7 @@ namespace osu.Game.Screens.Backgrounds string backgroundName; if (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Always - || seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason) + || (seasonalBackgroundMode.Value == SeasonalBackgroundMode.Sometimes && seasonalBackgroundLoader.IsInSeason)) { var seasonalBackground = seasonalBackgroundLoader.LoadBackground(); From 82ef85569bffe30e64a00414ddb8465348d645d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 19:35:08 +0100 Subject: [PATCH 23/32] Fix nullref when querying IsInSeason before request completion --- osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index daceb05fd7..2963d57a97 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -49,7 +49,7 @@ namespace osu.Game.Graphics.Backgrounds return new SeasonalBackground(url); } - public bool IsInSeason => DateTimeOffset.Now < cachedResponse.Value.EndDate; + public bool IsInSeason => cachedResponse.Value != null && DateTimeOffset.Now < cachedResponse.Value.EndDate; } [LongRunningLoad] From 20c27c69431eb680781338c4e0deba1f2a1658ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 19:55:17 +0100 Subject: [PATCH 24/32] Rename lookup & field --- osu.Game/Configuration/SessionStatics.cs | 4 ++-- .../Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 199889391b..c470058ae8 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -14,7 +14,7 @@ namespace osu.Game.Configuration { Set(Static.LoginOverlayDisplayed, false); Set(Static.MutedAudioNotificationShownOnce, false); - Set(Static.SeasonalBackgroundsResponse, null); + Set(Static.SeasonalBackgrounds, null); } } @@ -22,6 +22,6 @@ namespace osu.Game.Configuration { LoginOverlayDisplayed, MutedAudioNotificationShownOnce, - SeasonalBackgroundsResponse, + SeasonalBackgrounds, } } diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index 2963d57a97..1c38e67451 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -18,20 +18,20 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { - private Bindable cachedResponse; + private Bindable seasonalBackgrounds; private int current; [BackgroundDependencyLoader] private void load(SessionStatics sessionStatics, IAPIProvider api) { - cachedResponse = sessionStatics.GetBindable(Static.SeasonalBackgroundsResponse); + seasonalBackgrounds = sessionStatics.GetBindable(Static.SeasonalBackgrounds); - if (cachedResponse.Value != null) return; + if (seasonalBackgrounds.Value != null) return; var request = new GetSeasonalBackgroundsRequest(); request.Success += response => { - cachedResponse.Value = response; + seasonalBackgrounds.Value = response; current = RNG.Next(0, response.Backgrounds?.Count ?? 0); }; @@ -40,7 +40,7 @@ namespace osu.Game.Graphics.Backgrounds public SeasonalBackground LoadBackground() { - var backgrounds = cachedResponse.Value.Backgrounds; + var backgrounds = seasonalBackgrounds.Value.Backgrounds; if (backgrounds == null || !backgrounds.Any()) return null; current = (current + 1) % backgrounds.Count; @@ -49,7 +49,7 @@ namespace osu.Game.Graphics.Backgrounds return new SeasonalBackground(url); } - public bool IsInSeason => cachedResponse.Value != null && DateTimeOffset.Now < cachedResponse.Value.EndDate; + public bool IsInSeason => seasonalBackgrounds.Value != null && DateTimeOffset.Now < seasonalBackgrounds.Value.EndDate; } [LongRunningLoad] From aeab2be5d1968c7a1a6a712afc2897033891bb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 19:56:52 +0100 Subject: [PATCH 25/32] Add xmldoc to SeasonalBackgroundMode --- osu.Game/Configuration/SeasonalBackgroundMode.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/osu.Game/Configuration/SeasonalBackgroundMode.cs b/osu.Game/Configuration/SeasonalBackgroundMode.cs index 406736b2a4..6ef835ce5f 100644 --- a/osu.Game/Configuration/SeasonalBackgroundMode.cs +++ b/osu.Game/Configuration/SeasonalBackgroundMode.cs @@ -5,8 +5,19 @@ namespace osu.Game.Configuration { public enum SeasonalBackgroundMode { + /// + /// Seasonal backgrounds are shown regardless of season, if at all available. + /// Always, + + /// + /// Seasonal backgrounds are shown only during their corresponding season. + /// Sometimes, + + /// + /// Seasonal backgrounds are never shown. + /// Never } } From cf0e8e0a620faaa77ba490ab3e71b9901eabd658 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 19:59:52 +0100 Subject: [PATCH 26/32] Document nullability of seasonal backgrounds --- osu.Game/Configuration/SessionStatics.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index c470058ae8..03bc434aac 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -22,6 +22,11 @@ namespace osu.Game.Configuration { LoginOverlayDisplayed, MutedAudioNotificationShownOnce, + + /// + /// Info about seasonal backgrounds available fetched from API - see . + /// Value under this lookup can be null if there are no backgrounds available (or API is not reachable). + /// SeasonalBackgrounds, } } 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 27/32] 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 @@ namespace osu.Game.Graphics.Backgrounds 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 @@ namespace osu.Game.Graphics.Backgrounds 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 @@ namespace osu.Game.Screens.Backgrounds 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) From 8632f0d77f18b6fb65aee838bced622aba6bdc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 21:24:20 +0100 Subject: [PATCH 28/32] Add test coverage --- .../TestSceneSeasonalBackgroundLoader.cs | 200 ++++++++++++++++++ 1 file changed, 200 insertions(+) create mode 100644 osu.Game.Tests/Visual/Background/TestSceneSeasonalBackgroundLoader.cs diff --git a/osu.Game.Tests/Visual/Background/TestSceneSeasonalBackgroundLoader.cs b/osu.Game.Tests/Visual/Background/TestSceneSeasonalBackgroundLoader.cs new file mode 100644 index 0000000000..8f5990aeb1 --- /dev/null +++ b/osu.Game.Tests/Visual/Background/TestSceneSeasonalBackgroundLoader.cs @@ -0,0 +1,200 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using System.Linq; +using NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.OpenGL.Textures; +using osu.Framework.Graphics.Textures; +using osu.Game.Configuration; +using osu.Game.Graphics.Backgrounds; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Tests.Visual.Background +{ + public class TestSceneSeasonalBackgroundLoader : ScreenTestScene + { + [Resolved] + private OsuConfigManager config { get; set; } + + [Resolved] + private SessionStatics statics { get; set; } + + [Cached(typeof(LargeTextureStore))] + private LookupLoggingTextureStore textureStore = new LookupLoggingTextureStore(); + + private DummyAPIAccess dummyAPI => (DummyAPIAccess)API; + + private SeasonalBackgroundLoader backgroundLoader; + private Container backgroundContainer; + + // in real usages these would be online URLs, but correct execution of this test + // shouldn't be coupled to existence of online assets. + private static readonly List seasonal_background_urls = new List + { + "Backgrounds/bg2", + "Backgrounds/bg4", + "Backgrounds/bg3" + }; + + [BackgroundDependencyLoader] + private void load(LargeTextureStore wrappedStore) + { + textureStore.AddStore(wrappedStore); + + Add(backgroundContainer = new Container + { + RelativeSizeAxes = Axes.Both + }); + } + + [SetUp] + public void SetUp() => Schedule(() => + { + // reset API response in statics to avoid test crosstalk. + statics.Set(Static.SeasonalBackgrounds, null); + textureStore.PerformedLookups.Clear(); + dummyAPI.SetState(APIState.Online); + + backgroundContainer.Clear(); + }); + + [TestCase(-5)] + [TestCase(5)] + public void TestAlwaysSeasonal(int daysOffset) + { + registerBackgroundsResponse(DateTimeOffset.Now.AddDays(daysOffset)); + setSeasonalBackgroundMode(SeasonalBackgroundMode.Always); + + createLoader(); + + for (int i = 0; i < 4; ++i) + loadNextBackground(); + + AddAssert("all backgrounds cycled", () => new HashSet(textureStore.PerformedLookups).SetEquals(seasonal_background_urls)); + } + + [TestCase(-5)] + [TestCase(5)] + public void TestNeverSeasonal(int daysOffset) + { + registerBackgroundsResponse(DateTimeOffset.Now.AddDays(daysOffset)); + setSeasonalBackgroundMode(SeasonalBackgroundMode.Never); + + createLoader(); + + assertNoBackgrounds(); + } + + [Test] + public void TestSometimesInSeason() + { + registerBackgroundsResponse(DateTimeOffset.Now.AddDays(5)); + setSeasonalBackgroundMode(SeasonalBackgroundMode.Sometimes); + + createLoader(); + + assertAnyBackground(); + } + + [Test] + public void TestSometimesOutOfSeason() + { + registerBackgroundsResponse(DateTimeOffset.Now.AddDays(-10)); + setSeasonalBackgroundMode(SeasonalBackgroundMode.Sometimes); + + createLoader(); + + assertNoBackgrounds(); + } + + [Test] + public void TestDelayedConnectivity() + { + registerBackgroundsResponse(DateTimeOffset.Now.AddDays(30)); + setSeasonalBackgroundMode(SeasonalBackgroundMode.Always); + AddStep("go offline", () => dummyAPI.SetState(APIState.Offline)); + + createLoader(); + assertNoBackgrounds(); + + AddStep("go online", () => dummyAPI.SetState(APIState.Online)); + + assertAnyBackground(); + } + + private void registerBackgroundsResponse(DateTimeOffset endDate) + => AddStep("setup request handler", () => + { + dummyAPI.HandleRequest = request => + { + if (dummyAPI.State.Value != APIState.Online || !(request is GetSeasonalBackgroundsRequest backgroundsRequest)) + return; + + backgroundsRequest.TriggerSuccess(new APISeasonalBackgrounds + { + Backgrounds = seasonal_background_urls.Select(url => new APISeasonalBackground { Url = url }).ToList(), + EndDate = endDate + }); + }; + }); + + private void setSeasonalBackgroundMode(SeasonalBackgroundMode mode) + => AddStep($"set seasonal mode to {mode}", () => config.Set(OsuSetting.SeasonalBackgroundMode, mode)); + + private void createLoader() + { + AddStep("create loader", () => + { + if (backgroundLoader != null) + Remove(backgroundLoader); + + LoadComponentAsync(backgroundLoader = new SeasonalBackgroundLoader(), Add); + }); + + AddUntilStep("wait for loaded", () => backgroundLoader.IsLoaded); + } + + private void loadNextBackground() + { + SeasonalBackground background = null; + + AddStep("create next background", () => + { + background = backgroundLoader.LoadNextBackground(); + LoadComponentAsync(background, bg => backgroundContainer.Child = bg); + }); + + AddUntilStep("background loaded", () => background.IsLoaded); + } + + private void assertAnyBackground() + { + loadNextBackground(); + AddAssert("background looked up", () => textureStore.PerformedLookups.Any()); + } + + private void assertNoBackgrounds() + { + AddAssert("no background available", () => backgroundLoader.LoadNextBackground() == null); + AddAssert("no lookups performed", () => !textureStore.PerformedLookups.Any()); + } + + private class LookupLoggingTextureStore : LargeTextureStore + { + public List PerformedLookups { get; } = new List(); + + public override Texture Get(string name, WrapMode wrapModeS, WrapMode wrapModeT) + { + PerformedLookups.Add(name); + return base.Get(name, wrapModeS, wrapModeT); + } + } + } +} From 29ad09990259245b8b828a49add4411a90d5f88a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 21:49:14 +0100 Subject: [PATCH 29/32] Allow to fetch if going online after launch --- .../Backgrounds/SeasonalBackgroundLoader.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index a9b9929c79..ff290dd99e 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -18,17 +18,29 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { + [Resolved] + private IAPIProvider api { get; set; } + + private readonly IBindable apiState = new Bindable(); private Bindable seasonalBackgroundMode; private Bindable seasonalBackgrounds; + private int current; [BackgroundDependencyLoader] - private void load(OsuConfigManager config, SessionStatics sessionStatics, IAPIProvider api) + private void load(OsuConfigManager config, SessionStatics sessionStatics) { seasonalBackgroundMode = config.GetBindable(OsuSetting.SeasonalBackgroundMode); seasonalBackgrounds = sessionStatics.GetBindable(Static.SeasonalBackgrounds); - if (seasonalBackgrounds.Value != null) return; + apiState.BindTo(api.State); + apiState.BindValueChanged(fetchSeasonalBackgrounds, true); + } + + private void fetchSeasonalBackgrounds(ValueChangedEvent stateChanged) + { + if (seasonalBackgrounds.Value != null || stateChanged.NewValue != APIState.Online) + return; var request = new GetSeasonalBackgroundsRequest(); request.Success += response => @@ -48,7 +60,7 @@ namespace osu.Game.Graphics.Backgrounds return null; } - var backgrounds = seasonalBackgrounds.Value.Backgrounds; + var backgrounds = seasonalBackgrounds.Value?.Backgrounds; if (backgrounds == null || !backgrounds.Any()) return null; From 38cf90a69b8734343b68fce3646b618f4d3ad6a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 22:03:26 +0100 Subject: [PATCH 30/32] Change background to seasonal right after login --- .../Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 9 +++++++++ osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 4 +--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index ff290dd99e..b439d98083 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -18,6 +18,12 @@ namespace osu.Game.Graphics.Backgrounds [LongRunningLoad] public class SeasonalBackgroundLoader : Component { + /// + /// Fired when background change should be changed due to receiving backgrounds from API + /// or when the user setting is changed (as it might require unloading the seasonal background). + /// + public event Action SeasonalBackgroundChanged; + [Resolved] private IAPIProvider api { get; set; } @@ -31,7 +37,10 @@ namespace osu.Game.Graphics.Backgrounds private void load(OsuConfigManager config, SessionStatics sessionStatics) { seasonalBackgroundMode = config.GetBindable(OsuSetting.SeasonalBackgroundMode); + seasonalBackgroundMode.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke()); + seasonalBackgrounds = sessionStatics.GetBindable(Static.SeasonalBackgrounds); + seasonalBackgrounds.BindValueChanged(_ => SeasonalBackgroundChanged?.Invoke()); apiState.BindTo(api.State); apiState.BindValueChanged(fetchSeasonalBackgrounds, true); diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index cbe0841537..f392386bf9 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -25,7 +25,6 @@ namespace osu.Game.Screens.Backgrounds private Bindable skin; private Bindable mode; private Bindable introSequence; - private Bindable seasonalBackgroundMode; private readonly SeasonalBackgroundLoader seasonalBackgroundLoader = new SeasonalBackgroundLoader(); [Resolved] @@ -43,14 +42,13 @@ namespace osu.Game.Screens.Backgrounds skin = skinManager.CurrentSkin.GetBoundCopy(); mode = config.GetBindable(OsuSetting.MenuBackgroundSource); introSequence = config.GetBindable(OsuSetting.IntroSequence); - seasonalBackgroundMode = config.GetBindable(OsuSetting.SeasonalBackgroundMode); user.ValueChanged += _ => Next(); skin.ValueChanged += _ => Next(); mode.ValueChanged += _ => Next(); beatmap.ValueChanged += _ => Next(); introSequence.ValueChanged += _ => Next(); - seasonalBackgroundMode.ValueChanged += _ => Next(); + seasonalBackgroundLoader.SeasonalBackgroundChanged += Next; currentDisplay = RNG.Next(0, background_count); From 391dd73843b52fcf559b6b23eb56171c89e7c37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 22:39:34 +0100 Subject: [PATCH 31/32] Fix typo in comment --- osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index b439d98083..03b7300011 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -19,7 +19,7 @@ namespace osu.Game.Graphics.Backgrounds public class SeasonalBackgroundLoader : Component { /// - /// Fired when background change should be changed due to receiving backgrounds from API + /// Fired when background should be changed due to receiving backgrounds from API /// or when the user setting is changed (as it might require unloading the seasonal background). /// public event Action SeasonalBackgroundChanged; From 78842ab95ae90862c704ee3c350cd08b8c6126e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 30 Oct 2020 22:40:24 +0100 Subject: [PATCH 32/32] Improve look & behaviour of background transitions --- .../Graphics/Backgrounds/SeasonalBackgroundLoader.cs | 2 ++ osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs index 03b7300011..99f3a8a6e8 100644 --- a/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs +++ b/osu.Game/Graphics/Backgrounds/SeasonalBackgroundLoader.cs @@ -97,6 +97,8 @@ namespace osu.Game.Graphics.Backgrounds private void load(LargeTextureStore textures) { Sprite.Texture = textures.Get(url) ?? textures.Get(fallback_texture_name); + // ensure we're not loading in without a transition. + this.FadeInFromZero(200, Easing.InOutSine); } } } diff --git a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs index f392386bf9..3f6210310f 100644 --- a/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs +++ b/osu.Game/Screens/Backgrounds/BackgroundScreenDefault.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Threading; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -52,7 +53,8 @@ namespace osu.Game.Screens.Backgrounds currentDisplay = RNG.Next(0, background_count); - LoadComponentAsync(seasonalBackgroundLoader, _ => LoadComponentAsync(createBackground(), display)); + LoadComponentAsync(seasonalBackgroundLoader); + Next(); } private void display(Background newBackground) @@ -65,11 +67,14 @@ namespace osu.Game.Screens.Backgrounds } private ScheduledDelegate nextTask; + private CancellationTokenSource cancellationTokenSource; public void Next() { nextTask?.Cancel(); - nextTask = Scheduler.AddDelayed(() => { LoadComponentAsync(createBackground(), display); }, 100); + cancellationTokenSource?.Cancel(); + cancellationTokenSource = new CancellationTokenSource(); + nextTask = Scheduler.AddDelayed(() => LoadComponentAsync(createBackground(), display, cancellationTokenSource.Token), 100); } private Background createBackground()