From e3e245ab20456afd2cf5a4b700a103c73ff9b79f Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Mon, 23 Sep 2019 08:15:27 +0300 Subject: [PATCH 1/7] Introduce SessionStatics --- osu.Game/Configuration/SessionStatics.cs | 21 +++++++++++++++++++++ osu.Game/OsuGameBase.cs | 1 + 2 files changed, 22 insertions(+) create mode 100644 osu.Game/Configuration/SessionStatics.cs diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs new file mode 100644 index 0000000000..9afb1bda36 --- /dev/null +++ b/osu.Game/Configuration/SessionStatics.cs @@ -0,0 +1,21 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Configuration; + +namespace osu.Game.Configuration +{ + public class SessionStatics : ConfigManager + { + // This is an in-memory store. + protected override void PerformLoad() + { + } + + protected override bool PerformSave() => true; + } + + public enum Statics + { + } +} diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index d6b8ad3e67..b79de0aa94 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -189,6 +189,7 @@ namespace osu.Game dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore)); dependencies.Cache(SettingsStore = new SettingsStore(contextFactory)); dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore)); + dependencies.Cache(new SessionStatics()); dependencies.Cache(new OsuColour()); fileImporters.Add(BeatmapManager); From 267e12ce3c0d88cab712d562a1c3f27dd6321fe3 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Tue, 24 Sep 2019 05:45:47 +0300 Subject: [PATCH 2/7] Add sample usage to the session statics --- osu.Game/Configuration/SessionStatics.cs | 1 + osu.Game/Screens/Menu/MainMenu.cs | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 9afb1bda36..0c1ea1e568 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -17,5 +17,6 @@ namespace osu.Game.Configuration public enum Statics { + LoginOverlayDisplayed, } } diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index dd81569e26..1834221d35 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -52,6 +52,9 @@ namespace osu.Game.Screens.Menu [Resolved(canBeNull: true)] private LoginOverlay login { get; set; } + [Resolved] + private SessionStatics statics { get; set; } + [Resolved] private IAPIProvider api { get; set; } @@ -170,7 +173,6 @@ namespace osu.Game.Screens.Menu Beatmap.ValueChanged += beatmap_ValueChanged; } - private bool loginDisplayed; private bool exitConfirmed; protected override void LogoArriving(OsuLogo logo, bool resuming) @@ -198,10 +200,12 @@ namespace osu.Game.Screens.Menu bool displayLogin() { - if (!loginDisplayed) + var loginDisplayed = statics.GetBindable(Statics.LoginOverlayDisplayed); + + if (!loginDisplayed.Value) { Scheduler.AddDelayed(() => login?.Show(), 500); - loginDisplayed = true; + loginDisplayed.Value = true; } return true; From d013b73d33082c3f1471bc922c4d77147122c81d Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Wed, 25 Sep 2019 01:25:05 +0300 Subject: [PATCH 3/7] Move in-memory logic to a base class --- .../Configuration/InMemoryConfigManager.cs | 22 +++++++++++++++++++ osu.Game/Configuration/SessionStatics.cs | 10 +++------ 2 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 osu.Game/Configuration/InMemoryConfigManager.cs diff --git a/osu.Game/Configuration/InMemoryConfigManager.cs b/osu.Game/Configuration/InMemoryConfigManager.cs new file mode 100644 index 0000000000..b0dc6b0e9c --- /dev/null +++ b/osu.Game/Configuration/InMemoryConfigManager.cs @@ -0,0 +1,22 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Configuration; + +namespace osu.Game.Configuration +{ + public class InMemoryConfigManager : ConfigManager + where T : struct + { + public InMemoryConfigManager() + { + InitialiseDefaults(); + } + + protected override void PerformLoad() + { + } + + protected override bool PerformSave() => true; + } +} diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index 0c1ea1e568..b4b5e914bb 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -1,18 +1,14 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using osu.Framework.Configuration; - namespace osu.Game.Configuration { - public class SessionStatics : ConfigManager + public class SessionStatics : InMemoryConfigManager { - // This is an in-memory store. - protected override void PerformLoad() + protected override void InitialiseDefaults() { + Set(Statics.LoginOverlayDisplayed, false); } - - protected override bool PerformSave() => true; } public enum Statics From cde7f49db1b37d3325b64f0ceddd312476e3f2c8 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Wed, 25 Sep 2019 01:26:02 +0300 Subject: [PATCH 4/7] Use direct get and set instead --- osu.Game/Screens/Menu/MainMenu.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 1834221d35..98ceb315a2 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -200,12 +200,10 @@ namespace osu.Game.Screens.Menu bool displayLogin() { - var loginDisplayed = statics.GetBindable(Statics.LoginOverlayDisplayed); - - if (!loginDisplayed.Value) + if (!statics.Get(Statics.LoginOverlayDisplayed)) { Scheduler.AddDelayed(() => login?.Show(), 500); - loginDisplayed.Value = true; + statics.Set(Statics.LoginOverlayDisplayed, true); } return true; From 8844d567cb1220dfe1b261ff30108dea5ae1c527 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Wed, 25 Sep 2019 15:56:47 +0300 Subject: [PATCH 5/7] Use bindable setting instead --- osu.Game/Screens/Menu/MainMenu.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 98ceb315a2..004bba20d4 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -52,9 +52,6 @@ namespace osu.Game.Screens.Menu [Resolved(canBeNull: true)] private LoginOverlay login { get; set; } - [Resolved] - private SessionStatics statics { get; set; } - [Resolved] private IAPIProvider api { get; set; } @@ -66,13 +63,15 @@ namespace osu.Game.Screens.Menu protected override BackgroundScreen CreateBackground() => background; private Bindable holdDelay; + private Bindable loginDisplayed; private ExitConfirmOverlay exitConfirmOverlay; [BackgroundDependencyLoader(true)] - private void load(DirectOverlay direct, SettingsOverlay settings, OsuConfigManager config) + private void load(DirectOverlay direct, SettingsOverlay settings, OsuConfigManager config, SessionStatics statics) { holdDelay = config.GetBindable(OsuSetting.UIHoldActivationDelay); + loginDisplayed = statics.GetBindable(Statics.LoginOverlayDisplayed); if (host.CanExit) { @@ -200,10 +199,10 @@ namespace osu.Game.Screens.Menu bool displayLogin() { - if (!statics.Get(Statics.LoginOverlayDisplayed)) + if (!loginDisplayed.Value) { Scheduler.AddDelayed(() => login?.Show(), 500); - statics.Set(Statics.LoginOverlayDisplayed, true); + loginDisplayed.Value = true; } return true; From fb9f21237ebb66b2e0631975d12d65b4f877c8e7 Mon Sep 17 00:00:00 2001 From: iiSaLMaN Date: Sat, 28 Sep 2019 04:18:16 +0300 Subject: [PATCH 6/7] Reset track adjustments on resuming from another screen --- osu.Game/Overlays/MusicController.cs | 6 +++--- osu.Game/Screens/Select/SongSelect.cs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index db94b0278f..172ae4e5cb 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -57,7 +57,7 @@ namespace osu.Game.Overlays protected override void LoadComplete() { beatmap.BindValueChanged(beatmapChanged, true); - mods.BindValueChanged(_ => updateAudioAdjustments(), true); + mods.BindValueChanged(_ => ResetTrackAdjustments(), true); base.LoadComplete(); } @@ -213,12 +213,12 @@ namespace osu.Game.Overlays current = beatmap.NewValue; TrackChanged?.Invoke(current, direction); - updateAudioAdjustments(); + ResetTrackAdjustments(); queuedDirection = null; } - private void updateAudioAdjustments() + public void ResetTrackAdjustments() { var track = current?.Track; if (track == null) diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index fca801ce78..d40dd9414a 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -490,6 +490,7 @@ namespace osu.Game.Screens.Select BeatmapDetails.Leaderboard.RefreshScores(); Beatmap.Value.Track.Looping = true; + music?.ResetTrackAdjustments(); if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending) { From a45f8c968b4669ca345089670455ce740afeb7a6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 28 Sep 2019 20:21:51 +0800 Subject: [PATCH 7/7] Rename and add simple xmldoc --- osu.Game/Configuration/SessionStatics.cs | 9 ++++++--- osu.Game/Screens/Menu/MainMenu.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Configuration/SessionStatics.cs b/osu.Game/Configuration/SessionStatics.cs index b4b5e914bb..818a95c0be 100644 --- a/osu.Game/Configuration/SessionStatics.cs +++ b/osu.Game/Configuration/SessionStatics.cs @@ -3,15 +3,18 @@ namespace osu.Game.Configuration { - public class SessionStatics : InMemoryConfigManager + /// + /// Stores global per-session statics. These will not be stored after exiting the game. + /// + public class SessionStatics : InMemoryConfigManager { protected override void InitialiseDefaults() { - Set(Statics.LoginOverlayDisplayed, false); + Set(Static.LoginOverlayDisplayed, false); } } - public enum Statics + public enum Static { LoginOverlayDisplayed, } diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 004bba20d4..16e9d67cc3 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -71,7 +71,7 @@ namespace osu.Game.Screens.Menu private void load(DirectOverlay direct, SettingsOverlay settings, OsuConfigManager config, SessionStatics statics) { holdDelay = config.GetBindable(OsuSetting.UIHoldActivationDelay); - loginDisplayed = statics.GetBindable(Statics.LoginOverlayDisplayed); + loginDisplayed = statics.GetBindable(Static.LoginOverlayDisplayed); if (host.CanExit) {