mirror of
https://github.com/ppy/osu
synced 2025-01-29 09:13:14 +00:00
Add session-wide storage as a safer alternative to statics (#6216)
Add session-wide storage as a safer alternative to statics Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
bbb38e0394
22
osu.Game/Configuration/InMemoryConfigManager.cs
Normal file
22
osu.Game/Configuration/InMemoryConfigManager.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
using osu.Framework.Configuration;
|
||||||
|
|
||||||
|
namespace osu.Game.Configuration
|
||||||
|
{
|
||||||
|
public class InMemoryConfigManager<T> : ConfigManager<T>
|
||||||
|
where T : struct
|
||||||
|
{
|
||||||
|
public InMemoryConfigManager()
|
||||||
|
{
|
||||||
|
InitialiseDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void PerformLoad()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool PerformSave() => true;
|
||||||
|
}
|
||||||
|
}
|
21
osu.Game/Configuration/SessionStatics.cs
Normal file
21
osu.Game/Configuration/SessionStatics.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace osu.Game.Configuration
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Stores global per-session statics. These will not be stored after exiting the game.
|
||||||
|
/// </summary>
|
||||||
|
public class SessionStatics : InMemoryConfigManager<Static>
|
||||||
|
{
|
||||||
|
protected override void InitialiseDefaults()
|
||||||
|
{
|
||||||
|
Set(Static.LoginOverlayDisplayed, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Static
|
||||||
|
{
|
||||||
|
LoginOverlayDisplayed,
|
||||||
|
}
|
||||||
|
}
|
@ -191,6 +191,7 @@ namespace osu.Game
|
|||||||
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory, RulesetStore));
|
||||||
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
dependencies.Cache(SettingsStore = new SettingsStore(contextFactory));
|
||||||
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
dependencies.Cache(RulesetConfigCache = new RulesetConfigCache(SettingsStore));
|
||||||
|
dependencies.Cache(new SessionStatics());
|
||||||
dependencies.Cache(new OsuColour());
|
dependencies.Cache(new OsuColour());
|
||||||
|
|
||||||
fileImporters.Add(BeatmapManager);
|
fileImporters.Add(BeatmapManager);
|
||||||
|
@ -63,13 +63,15 @@ namespace osu.Game.Screens.Menu
|
|||||||
protected override BackgroundScreen CreateBackground() => background;
|
protected override BackgroundScreen CreateBackground() => background;
|
||||||
|
|
||||||
private Bindable<int> holdDelay;
|
private Bindable<int> holdDelay;
|
||||||
|
private Bindable<bool> loginDisplayed;
|
||||||
|
|
||||||
private ExitConfirmOverlay exitConfirmOverlay;
|
private ExitConfirmOverlay exitConfirmOverlay;
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[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<int>(OsuSetting.UIHoldActivationDelay);
|
holdDelay = config.GetBindable<int>(OsuSetting.UIHoldActivationDelay);
|
||||||
|
loginDisplayed = statics.GetBindable<bool>(Static.LoginOverlayDisplayed);
|
||||||
|
|
||||||
if (host.CanExit)
|
if (host.CanExit)
|
||||||
{
|
{
|
||||||
@ -170,7 +172,6 @@ namespace osu.Game.Screens.Menu
|
|||||||
Beatmap.ValueChanged += beatmap_ValueChanged;
|
Beatmap.ValueChanged += beatmap_ValueChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool loginDisplayed;
|
|
||||||
private bool exitConfirmed;
|
private bool exitConfirmed;
|
||||||
|
|
||||||
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
protected override void LogoArriving(OsuLogo logo, bool resuming)
|
||||||
@ -198,10 +199,10 @@ namespace osu.Game.Screens.Menu
|
|||||||
|
|
||||||
bool displayLogin()
|
bool displayLogin()
|
||||||
{
|
{
|
||||||
if (!loginDisplayed)
|
if (!loginDisplayed.Value)
|
||||||
{
|
{
|
||||||
Scheduler.AddDelayed(() => login?.Show(), 500);
|
Scheduler.AddDelayed(() => login?.Show(), 500);
|
||||||
loginDisplayed = true;
|
loginDisplayed.Value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user