From 0b7e1ce667dae810a2fc9d7e2d1ad3b3ada05007 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 19:45:18 +0900 Subject: [PATCH 01/27] Add a way to have ruleset-specific configs --- .../Configuration/IRulesetConfigManager.cs | 9 +++++++ .../Configuration/RulesetConfigManager.cs | 24 +++++++++++++++++++ osu.Game/Rulesets/Ruleset.cs | 6 +++++ osu.Game/Screens/Play/Player.cs | 12 +++++++++- osu.Game/osu.Game.csproj | 2 ++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs create mode 100644 osu.Game/Rulesets/Configuration/RulesetConfigManager.cs diff --git a/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs new file mode 100644 index 0000000000..08fb6f53d6 --- /dev/null +++ b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Rulesets.Configuration +{ + public interface IRulesetConfigManager + { + } +} diff --git a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs new file mode 100644 index 0000000000..633d8f3951 --- /dev/null +++ b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Configuration; +using osu.Framework.Platform; + +namespace osu.Game.Rulesets.Configuration +{ + public abstract class RulesetConfigManager : ConfigManager, IRulesetConfigManager + where T : struct + { + protected override string Filename => ruleset?.ShortName; + private readonly Ruleset ruleset; + + protected RulesetConfigManager(Ruleset ruleset, Storage storage) + : base(storage) + { + this.ruleset = ruleset; + + // Re-load with the ruleset + Load(); + } + } +} diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 4f256621fb..c1aba5b403 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -9,6 +9,7 @@ using osu.Framework.Input.Bindings; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; +using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; @@ -89,6 +90,11 @@ namespace osu.Game.Rulesets /// A descriptive name of the variant. public virtual string GetVariantName(int variant) => string.Empty; + /// + /// The that is used for settings specific to this . + /// + public virtual IRulesetConfigManager CreateConfigManager() => null; + /// /// Create a ruleset info based on this ruleset. /// diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 31d9fac2ad..b78f92f6b7 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -24,6 +24,7 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Ranking; using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Cursor; +using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Cursor; @@ -88,8 +89,13 @@ namespace osu.Game.Screens.Play private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true; + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(base.CreateLocalDependencies(parent)); + [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuConfigManager config, APIAccess api) + private void load(AudioManager audio, OsuConfigManager config, APIAccess api, Storage storage) { this.api = api; @@ -129,6 +135,10 @@ namespace osu.Game.Screens.Play if (!RulesetContainer.Objects.Any()) throw new InvalidOperationException("Beatmap contains no hit objects!"); + + var rulesetConfig = rulesetInstance.CreateConfigManager(); + if (rulesetConfig != null) + dependencies.Cache(rulesetConfig); } catch (Exception e) { diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 85da54e317..05728c2b41 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -314,6 +314,8 @@ + + From 9f4ebad6e3c05f25aced5dc2d20538e92466903f Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 20:10:35 +0900 Subject: [PATCH 02/27] Add mania config manager --- .../Configuration/ManiaConfigManager.cs | 21 +++++++++++++++++++ osu.Game.Rulesets.Mania/ManiaRuleset.cs | 5 +++++ .../osu.Game.Rulesets.Mania.csproj | 1 + osu.Game/Rulesets/Ruleset.cs | 3 ++- 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs new file mode 100644 index 0000000000..aa288818c5 --- /dev/null +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs @@ -0,0 +1,21 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Platform; +using osu.Game.Rulesets.Configuration; + +namespace osu.Game.Rulesets.Mania.Configuration +{ + public class ManiaConfigManager : RulesetConfigManager + { + public ManiaConfigManager(Ruleset ruleset, Storage storage) + : base(ruleset, storage) + { + } + } + + public enum ManiaSetting + { + ScrollSpeed + } +} diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index e8b9828bff..2709683eb4 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -9,7 +9,10 @@ using osu.Game.Rulesets.UI; using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; +using osu.Framework.Platform; using osu.Game.Graphics; +using osu.Game.Rulesets.Configuration; +using osu.Game.Rulesets.Mania.Configuration; namespace osu.Game.Rulesets.Mania { @@ -154,5 +157,7 @@ namespace osu.Game.Rulesets.Mania } public override string GetVariantName(int variant) => $"{variant}K"; + + public override IRulesetConfigManager CreateConfigManager(Storage storage) => new ManiaConfigManager(this, storage); } } diff --git a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj index 39f8333413..3c4e843dff 100644 --- a/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj +++ b/osu.Game.Rulesets.Mania/osu.Game.Rulesets.Mania.csproj @@ -58,6 +58,7 @@ + diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index c1aba5b403..e736e0ac27 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; +using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; @@ -93,7 +94,7 @@ namespace osu.Game.Rulesets /// /// The that is used for settings specific to this . /// - public virtual IRulesetConfigManager CreateConfigManager() => null; + public virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null; /// /// Create a ruleset info based on this ruleset. From 92da02db8731b2b9eeb699481503c1a3c652903a Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 21:07:37 +0900 Subject: [PATCH 03/27] Add extension to filename --- osu.Game/Rulesets/Configuration/RulesetConfigManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs index 633d8f3951..9106485253 100644 --- a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs +++ b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs @@ -9,7 +9,7 @@ namespace osu.Game.Rulesets.Configuration public abstract class RulesetConfigManager : ConfigManager, IRulesetConfigManager where T : struct { - protected override string Filename => ruleset?.ShortName; + protected override string Filename => ruleset?.ShortName == null ? null : $"{ruleset.ShortName}.ini"; private readonly Ruleset ruleset; protected RulesetConfigManager(Ruleset ruleset, Storage storage) From d96234bf4063117ed10e391a7d4bbb98a25cd916 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 21:08:23 +0900 Subject: [PATCH 04/27] Enforce that there's only one configmanager per ruleset --- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 10 +++++++++- osu.Game/Screens/Play/Player.cs | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 2709683eb4..9519de8b53 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -158,6 +158,6 @@ namespace osu.Game.Rulesets.Mania public override string GetVariantName(int variant) => $"{variant}K"; - public override IRulesetConfigManager CreateConfigManager(Storage storage) => new ManiaConfigManager(this, storage); + protected override IRulesetConfigManager CreateConfigManager(Storage storage) => new ManiaConfigManager(this, storage); } } diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index e736e0ac27..faadbd24f7 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -91,10 +91,18 @@ namespace osu.Game.Rulesets /// A descriptive name of the variant. public virtual string GetVariantName(int variant) => string.Empty; + private static readonly Dictionary config_manager_cache = new Dictionary(); + public IRulesetConfigManager GetConfigManager(Storage storage) + { + if (config_manager_cache.TryGetValue(GetType(), out var existing)) + return existing; + return config_manager_cache[GetType()] = CreateConfigManager(storage); + } + /// /// The that is used for settings specific to this . /// - public virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null; + protected virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null; /// /// Create a ruleset info based on this ruleset. diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index b78f92f6b7..0ad2a4a78d 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -136,7 +136,7 @@ namespace osu.Game.Screens.Play if (!RulesetContainer.Objects.Any()) throw new InvalidOperationException("Beatmap contains no hit objects!"); - var rulesetConfig = rulesetInstance.CreateConfigManager(); + var rulesetConfig = rulesetInstance.GetConfigManager(storage); if (rulesetConfig != null) dependencies.Cache(rulesetConfig); } From db27faa4717b0a4e142b09e5c608bd063add07f4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Wed, 17 Jan 2018 21:13:14 +0900 Subject: [PATCH 05/27] Add a ScrollTime config setting to osu!mania --- .../Configuration/ManiaConfigManager.cs | 9 ++++++++- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs index aa288818c5..4972e3092a 100644 --- a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs @@ -12,10 +12,17 @@ namespace osu.Game.Rulesets.Mania.Configuration : base(ruleset, storage) { } + + protected override void InitialiseDefaults() + { + base.InitialiseDefaults(); + + Set(ManiaSetting.ScrollTime, 1500.0, 50.0, 10000.0, 50.0); + } } public enum ManiaSetting { - ScrollSpeed + ScrollTime } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 7d3df6cda7..868f4b143c 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -16,6 +16,7 @@ using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Framework.Graphics.Shapes; using osu.Game.Rulesets.Judgements; +using osu.Game.Rulesets.Mania.Configuration; using osu.Game.Rulesets.UI.Scrolling; namespace osu.Game.Rulesets.Mania.UI @@ -161,8 +162,10 @@ namespace osu.Game.Rulesets.Mania.UI } [BackgroundDependencyLoader] - private void load(OsuColour colours) + private void load(OsuColour colours, ManiaConfigManager maniaConfig) { + maniaConfig.BindWith(ManiaSetting.ScrollTime, VisibleTimeRange); + normalColumnColours = new List { colours.RedDark, From 09dfea7e29bffd26a98c4c9457dd45655a0eabfe Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 18 Jan 2018 15:26:03 +0900 Subject: [PATCH 06/27] Use tracked settings from ConfigManager changes --- osu-framework | 2 +- osu.Game/Overlays/OnScreenDisplay.cs | 72 +++++++++++++++------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/osu-framework b/osu-framework index 8f36ddab94..c0c21831ce 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 8f36ddab946ff538620081ede7719461d4732b79 +Subproject commit c0c21831cef6b2946c5b067f5c4bbd929e89c2ec diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index 65803b477b..354c29531d 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Configuration; -using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -118,43 +117,50 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader] private void load(FrameworkConfigManager frameworkConfig) { - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.FrameSync), v => display(v, "Frame Limiter", v.GetDescription(), "Ctrl+F7")); - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.AudioDevice), v => display(v, "Audio Device", string.IsNullOrEmpty(v) ? "Default" : v, v)); - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.ShowLogOverlay), v => display(v, "Debug Logs", v ? "visible" : "hidden", "Ctrl+F10")); - - void displayResolution() => display(null, "Screen Resolution", frameworkConfig.Get(FrameworkSetting.Width) + "x" + frameworkConfig.Get(FrameworkSetting.Height)); - - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.Width), v => displayResolution()); - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.Height), v => displayResolution()); - - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.CursorSensitivity), v => display(v, "Cursor Sensitivity", v.ToString(@"0.##x"), "Ctrl+Alt+R to reset")); - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.ActiveInputHandlers), - delegate (string v) - { - bool raw = v.Contains("Raw"); - display(raw, "Raw Input", raw ? "enabled" : "disabled", "Ctrl+Alt+R to reset"); - }); - - trackSetting(frameworkConfig.GetBindable(FrameworkSetting.WindowMode), v => display(v, "Screen Mode", v.ToString(), "Alt+Enter")); + Register(frameworkConfig); } - private readonly List references = new List(); + private readonly Dictionary trackedConfigManagers = new Dictionary(); - private void trackSetting(Bindable bindable, Action action) + public void Register(ConfigManager configManager) + where T : struct { - // we need to keep references as we bind - references.Add(bindable); + if (configManager == null) throw new ArgumentNullException(nameof(configManager)); - bindable.ValueChanged += action; + if (trackedConfigManagers.ContainsKey(configManager)) + throw new InvalidOperationException($"{nameof(configManager)} is already registered."); + + var trackedSettings = configManager.CreateTrackedSettings(); + if (trackedSettings == null) + return; + + trackedSettings.LoadFrom(configManager); + trackedSettings.SettingChanged += display; + + trackedConfigManagers.Add(configManager, trackedSettings); } - private void display(object rawValue, string settingName, string settingValue, string shortcut = @"") + public void Unregister(ConfigManager configManager) + where T : struct + { + if (configManager == null) throw new ArgumentNullException(nameof(configManager)); + + if (!trackedConfigManagers.TryGetValue(configManager, out var existing)) + return; + + existing.Unload(); + existing.SettingChanged -= display; + + trackedConfigManagers.Remove(configManager); + } + + private void display(SettingDescription description) { Schedule(() => { - textLine1.Text = settingName.ToUpper(); - textLine2.Text = settingValue; - textLine3.Text = shortcut.ToUpper(); + textLine1.Text = description.Name.ToUpper(); + textLine2.Text = description.Value; + textLine3.Text = description.Shortcut.ToUpper(); box.Animate( b => b.FadeIn(500, Easing.OutQuint), @@ -167,16 +173,16 @@ namespace osu.Game.Overlays int optionCount = 0; int selectedOption = -1; - if (rawValue is bool) + if (description.RawValue is bool) { optionCount = 1; - if ((bool)rawValue) selectedOption = 0; + if ((bool)description.RawValue) selectedOption = 0; } - else if (rawValue is Enum) + else if (description.RawValue is Enum) { - var values = Enum.GetValues(rawValue.GetType()); + var values = Enum.GetValues(description.RawValue.GetType()); optionCount = values.Length; - selectedOption = Convert.ToInt32(rawValue); + selectedOption = Convert.ToInt32(description.RawValue); } textLine2.Origin = optionCount > 0 ? Anchor.BottomCentre : Anchor.Centre; From c2c478750d0a48a84a79c1b9ad81a60ce1824ba9 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 18 Jan 2018 16:57:32 +0900 Subject: [PATCH 07/27] Remove generics from OSD registration methods --- osu.Game/Overlays/OnScreenDisplay.cs | 14 +++++++------- .../Configuration/IRulesetConfigManager.cs | 5 ++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index 354c29531d..cc47f3bfa0 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Configuration; +using osu.Framework.Configuration.Tracking; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; @@ -120,28 +121,27 @@ namespace osu.Game.Overlays Register(frameworkConfig); } - private readonly Dictionary trackedConfigManagers = new Dictionary(); + private readonly Dictionary trackedConfigManagers = new Dictionary(); - public void Register(ConfigManager configManager) - where T : struct + public void Register(ITrackableConfigManager configManager) { if (configManager == null) throw new ArgumentNullException(nameof(configManager)); if (trackedConfigManagers.ContainsKey(configManager)) - throw new InvalidOperationException($"{nameof(configManager)} is already registered."); + return; var trackedSettings = configManager.CreateTrackedSettings(); if (trackedSettings == null) return; - trackedSettings.LoadFrom(configManager); + configManager.LoadInto(trackedSettings); + trackedSettings.SettingChanged += display; trackedConfigManagers.Add(configManager, trackedSettings); } - public void Unregister(ConfigManager configManager) - where T : struct + public void Unregister(ITrackableConfigManager configManager) { if (configManager == null) throw new ArgumentNullException(nameof(configManager)); diff --git a/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs index 08fb6f53d6..8d386242a9 100644 --- a/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs +++ b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs @@ -1,9 +1,12 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Configuration; +using osu.Framework.Configuration.Tracking; + namespace osu.Game.Rulesets.Configuration { - public interface IRulesetConfigManager + public interface IRulesetConfigManager : ITrackableConfigManager, IConfigManager { } } From 7910b47868657dacbf90eacddc01d334a424bae1 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 18 Jan 2018 17:00:23 +0900 Subject: [PATCH 08/27] Move ConfigManager registration/dependency injection to RulesetContainer --- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 5 --- .../UI/ManiaRulesetContainer.cs | 5 +++ osu.Game/OsuGame.cs | 4 +- osu.Game/Rulesets/Ruleset.cs | 15 -------- osu.Game/Rulesets/UI/RulesetContainer.cs | 38 +++++++++++++++++++ osu.Game/Screens/Play/Player.cs | 12 +----- 6 files changed, 47 insertions(+), 32 deletions(-) diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index 9519de8b53..e8b9828bff 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -9,10 +9,7 @@ using osu.Game.Rulesets.UI; using System.Collections.Generic; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; -using osu.Framework.Platform; using osu.Game.Graphics; -using osu.Game.Rulesets.Configuration; -using osu.Game.Rulesets.Mania.Configuration; namespace osu.Game.Rulesets.Mania { @@ -157,7 +154,5 @@ namespace osu.Game.Rulesets.Mania } public override string GetVariantName(int variant) => $"{variant}K"; - - protected override IRulesetConfigManager CreateConfigManager(Storage storage) => new ManiaConfigManager(this, storage); } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index 5bb980adb2..1ffdb55136 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -9,9 +9,12 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.MathUtils; +using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Mania.Beatmaps; +using osu.Game.Rulesets.Mania.Configuration; using osu.Game.Rulesets.Mania.Objects; using osu.Game.Rulesets.Mania.Objects.Drawables; using osu.Game.Rulesets.Mania.Replays; @@ -98,5 +101,7 @@ namespace osu.Game.Rulesets.Mania.UI protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f); protected override FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new ManiaFramedReplayInputHandler(replay, this); + + protected override IRulesetConfigManager CreateConfig(Ruleset ruleset, Storage storage) => new ManiaConfigManager(ruleset, storage); } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index b48e25f1fe..b090cc7927 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -71,6 +71,7 @@ namespace osu.Game private OsuScreen screenStack; private VolumeControl volume; + private OnScreenDisplay onscreenDisplay; private Bindable configRuleset; public Bindable Ruleset = new Bindable(); @@ -195,7 +196,7 @@ namespace osu.Game }, overlayContent.Add); loadComponentSingleFile(volume = new VolumeControl(), Add); - loadComponentSingleFile(new OnScreenDisplay(), Add); + loadComponentSingleFile(onscreenDisplay = new OnScreenDisplay(), Add); //overlay elements loadComponentSingleFile(direct = new DirectOverlay { Depth = -1 }, mainContent.Add); @@ -232,6 +233,7 @@ namespace osu.Game forwardLoggedErrorsToNotifications(); dependencies.Cache(settings); + dependencies.Cache(onscreenDisplay); dependencies.Cache(social); dependencies.Cache(direct); dependencies.Cache(chat); diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index faadbd24f7..4f256621fb 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -6,11 +6,9 @@ using System.Collections.Generic; using System.Linq; using osu.Framework.Graphics; using osu.Framework.Input.Bindings; -using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; -using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Scoring; @@ -91,19 +89,6 @@ namespace osu.Game.Rulesets /// A descriptive name of the variant. public virtual string GetVariantName(int variant) => string.Empty; - private static readonly Dictionary config_manager_cache = new Dictionary(); - public IRulesetConfigManager GetConfigManager(Storage storage) - { - if (config_manager_cache.TryGetValue(GetType(), out var existing)) - return existing; - return config_manager_cache[GetType()] = CreateConfigManager(storage); - } - - /// - /// The that is used for settings specific to this . - /// - protected virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null; - /// /// Create a ruleset info based on this ruleset. /// diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 626b56ad67..5d1c57a7a5 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -15,6 +15,9 @@ using System.Diagnostics; using System.Linq; using osu.Framework.Graphics.Cursor; using osu.Framework.Input; +using osu.Framework.Platform; +using osu.Game.Overlays; +using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Scoring; using OpenTK; @@ -64,6 +67,13 @@ namespace osu.Game.Rulesets.UI protected readonly Ruleset Ruleset; + private IRulesetConfigManager rulesetConfig; + + private DependencyContainer dependencies; + + protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) + => dependencies = new DependencyContainer(base.CreateLocalDependencies(parent)); + /// /// A visual representation of a . /// @@ -76,6 +86,26 @@ namespace osu.Game.Rulesets.UI Cursor = CreateCursor(); } + [BackgroundDependencyLoader] + private void load(Storage storage, OnScreenDisplay onScreenDisplay) + { + rulesetConfig = getConfig(storage); + + if (rulesetConfig != null) + { + dependencies.Cache(rulesetConfig); + onScreenDisplay?.Register(rulesetConfig); + } + } + + private static readonly Dictionary config_cache = new Dictionary(); + private IRulesetConfigManager getConfig(Storage storage) + { + if (config_cache.TryGetValue(GetType(), out var existing)) + return existing; + return config_cache[GetType()] = CreateConfig(Ruleset, storage); + } + public abstract ScoreProcessor CreateScoreProcessor(); /// @@ -107,11 +137,19 @@ namespace osu.Game.Rulesets.UI /// protected virtual CursorContainer CreateCursor() => null; + protected virtual IRulesetConfigManager CreateConfig(Ruleset ruleset, Storage storage) => null; + /// /// Creates a Playfield. /// /// The Playfield. protected abstract Playfield CreatePlayfield(); + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + rulesetConfig.Save(); + } } /// diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 0ad2a4a78d..31d9fac2ad 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -24,7 +24,6 @@ using osu.Game.Rulesets.Scoring; using osu.Game.Screens.Ranking; using osu.Framework.Audio.Sample; using osu.Framework.Graphics.Cursor; -using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Graphics.Cursor; @@ -89,13 +88,8 @@ namespace osu.Game.Screens.Play private bool loadedSuccessfully => RulesetContainer?.Objects.Any() == true; - private DependencyContainer dependencies; - - protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) - => dependencies = new DependencyContainer(base.CreateLocalDependencies(parent)); - [BackgroundDependencyLoader] - private void load(AudioManager audio, OsuConfigManager config, APIAccess api, Storage storage) + private void load(AudioManager audio, OsuConfigManager config, APIAccess api) { this.api = api; @@ -135,10 +129,6 @@ namespace osu.Game.Screens.Play if (!RulesetContainer.Objects.Any()) throw new InvalidOperationException("Beatmap contains no hit objects!"); - - var rulesetConfig = rulesetInstance.GetConfigManager(storage); - if (rulesetConfig != null) - dependencies.Cache(rulesetConfig); } catch (Exception e) { From 89f4bfa7b540d8bf24909bc56498c476de446ddf Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 18 Jan 2018 17:00:41 +0900 Subject: [PATCH 09/27] Track mania scroll speed --- osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs index 4972e3092a..0f062ed72a 100644 --- a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs @@ -1,6 +1,7 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Framework.Configuration.Tracking; using osu.Framework.Platform; using osu.Game.Rulesets.Configuration; @@ -19,6 +20,11 @@ namespace osu.Game.Rulesets.Mania.Configuration Set(ManiaSetting.ScrollTime, 1500.0, 50.0, 10000.0, 50.0); } + + public override TrackedSettings CreateTrackedSettings() => new TrackedSettings + { + new TrackedSetting(ManiaSetting.ScrollTime, v => new SettingDescription(v, "Scroll Time", $"{v}ms")) + }; } public enum ManiaSetting From dee298c395c26e465bca5037bb0924051e32d969 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 18 Jan 2018 17:40:05 +0900 Subject: [PATCH 10/27] No more statics + better unregistration --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 8 +++++++ osu.Game/Overlays/OnScreenDisplay.cs | 16 +++++++------- .../Configuration/IRulesetConfigManager.cs | 3 +-- osu.Game/Rulesets/UI/RulesetContainer.cs | 22 +++++++++---------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 868f4b143c..7af675cc6a 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -161,11 +161,19 @@ namespace osu.Game.Rulesets.Mania.UI judgements.Scale = Scale; } + private Bindable scrollTime; + [BackgroundDependencyLoader] private void load(OsuColour colours, ManiaConfigManager maniaConfig) { maniaConfig.BindWith(ManiaSetting.ScrollTime, VisibleTimeRange); + // Todo: The following two lines shouldn't be required, but is an effect of not having config databased + // 1. ValueChanged is run prior to values being propagated + // 2. We want the config to be saved ASAP, in-case a new ManiaPlayfield is instantiated + scrollTime = maniaConfig.GetBindable(ManiaSetting.ScrollTime); + scrollTime.ValueChanged += v => maniaConfig.Save(); + normalColumnColours = new List { colours.RedDark, diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index cc47f3bfa0..b9d0213aa6 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -118,16 +118,16 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader] private void load(FrameworkConfigManager frameworkConfig) { - Register(frameworkConfig); + Register(this, frameworkConfig); } - private readonly Dictionary trackedConfigManagers = new Dictionary(); + private readonly Dictionary<(IDisposable, IConfigManager), TrackedSettings> trackedConfigManagers = new Dictionary<(IDisposable, IConfigManager), TrackedSettings>(); - public void Register(ITrackableConfigManager configManager) + public void Register(IDisposable source, ITrackableConfigManager configManager) { if (configManager == null) throw new ArgumentNullException(nameof(configManager)); - if (trackedConfigManagers.ContainsKey(configManager)) + if (trackedConfigManagers.ContainsKey((source, configManager))) return; var trackedSettings = configManager.CreateTrackedSettings(); @@ -138,20 +138,20 @@ namespace osu.Game.Overlays trackedSettings.SettingChanged += display; - trackedConfigManagers.Add(configManager, trackedSettings); + trackedConfigManagers.Add((source, configManager), trackedSettings); } - public void Unregister(ITrackableConfigManager configManager) + public void Unregister(IDisposable source, ITrackableConfigManager configManager) { if (configManager == null) throw new ArgumentNullException(nameof(configManager)); - if (!trackedConfigManagers.TryGetValue(configManager, out var existing)) + if (!trackedConfigManagers.TryGetValue((source, configManager), out var existing)) return; existing.Unload(); existing.SettingChanged -= display; - trackedConfigManagers.Remove(configManager); + trackedConfigManagers.Remove((source, configManager)); } private void display(SettingDescription description) diff --git a/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs index 8d386242a9..56eac730b0 100644 --- a/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs +++ b/osu.Game/Rulesets/Configuration/IRulesetConfigManager.cs @@ -1,12 +1,11 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Configuration; using osu.Framework.Configuration.Tracking; namespace osu.Game.Rulesets.Configuration { - public interface IRulesetConfigManager : ITrackableConfigManager, IConfigManager + public interface IRulesetConfigManager : ITrackableConfigManager { } } diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 5d1c57a7a5..d4cfb3a3b3 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -68,6 +68,7 @@ namespace osu.Game.Rulesets.UI protected readonly Ruleset Ruleset; private IRulesetConfigManager rulesetConfig; + private OnScreenDisplay onScreenDisplay; private DependencyContainer dependencies; @@ -89,23 +90,17 @@ namespace osu.Game.Rulesets.UI [BackgroundDependencyLoader] private void load(Storage storage, OnScreenDisplay onScreenDisplay) { - rulesetConfig = getConfig(storage); + this.onScreenDisplay = onScreenDisplay; + + rulesetConfig = CreateConfig(Ruleset, storage); if (rulesetConfig != null) { dependencies.Cache(rulesetConfig); - onScreenDisplay?.Register(rulesetConfig); + onScreenDisplay?.Register(this, rulesetConfig); } } - private static readonly Dictionary config_cache = new Dictionary(); - private IRulesetConfigManager getConfig(Storage storage) - { - if (config_cache.TryGetValue(GetType(), out var existing)) - return existing; - return config_cache[GetType()] = CreateConfig(Ruleset, storage); - } - public abstract ScoreProcessor CreateScoreProcessor(); /// @@ -148,7 +143,12 @@ namespace osu.Game.Rulesets.UI protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); - rulesetConfig.Save(); + + if (rulesetConfig != null) + { + onScreenDisplay?.Unregister(this, rulesetConfig); + rulesetConfig = null; + } } } From a94ea7025e3cf2a48a308097afe208d59e76b523 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 18 Jan 2018 18:45:48 +0900 Subject: [PATCH 11/27] Register/Unregister -> BeginTracking/StopTracking and add exceptions --- osu.Game/Overlays/OnScreenDisplay.cs | 27 ++++++++++++++++++------ osu.Game/Rulesets/UI/RulesetContainer.cs | 4 ++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/osu.Game/Overlays/OnScreenDisplay.cs b/osu.Game/Overlays/OnScreenDisplay.cs index b9d0213aa6..bbb2c476f4 100644 --- a/osu.Game/Overlays/OnScreenDisplay.cs +++ b/osu.Game/Overlays/OnScreenDisplay.cs @@ -118,35 +118,48 @@ namespace osu.Game.Overlays [BackgroundDependencyLoader] private void load(FrameworkConfigManager frameworkConfig) { - Register(this, frameworkConfig); + BeginTracking(this, frameworkConfig); } - private readonly Dictionary<(IDisposable, IConfigManager), TrackedSettings> trackedConfigManagers = new Dictionary<(IDisposable, IConfigManager), TrackedSettings>(); + private readonly Dictionary<(object, IConfigManager), TrackedSettings> trackedConfigManagers = new Dictionary<(object, IConfigManager), TrackedSettings>(); - public void Register(IDisposable source, ITrackableConfigManager configManager) + /// + /// Registers a to have its settings tracked by this . + /// + /// The object that is registering the to be tracked. + /// The to be tracked. + /// If is null. + /// If is already being tracked from the same . + public void BeginTracking(object source, ITrackableConfigManager configManager) { if (configManager == null) throw new ArgumentNullException(nameof(configManager)); if (trackedConfigManagers.ContainsKey((source, configManager))) - return; + throw new InvalidOperationException($"{nameof(configManager)} is already registered."); var trackedSettings = configManager.CreateTrackedSettings(); if (trackedSettings == null) return; configManager.LoadInto(trackedSettings); - trackedSettings.SettingChanged += display; trackedConfigManagers.Add((source, configManager), trackedSettings); } - public void Unregister(IDisposable source, ITrackableConfigManager configManager) + /// + /// Unregisters a from having its settings tracked by this . + /// + /// The object that registered the to be tracked. + /// The that is being tracked. + /// If is null. + /// If is not being tracked from the same . + public void StopTracking(object source, ITrackableConfigManager configManager) { if (configManager == null) throw new ArgumentNullException(nameof(configManager)); if (!trackedConfigManagers.TryGetValue((source, configManager), out var existing)) - return; + throw new InvalidOperationException($"{nameof(configManager)} is not registered."); existing.Unload(); existing.SettingChanged -= display; diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index d4cfb3a3b3..45c112f669 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -97,7 +97,7 @@ namespace osu.Game.Rulesets.UI if (rulesetConfig != null) { dependencies.Cache(rulesetConfig); - onScreenDisplay?.Register(this, rulesetConfig); + onScreenDisplay?.BeginTracking(this, rulesetConfig); } } @@ -146,7 +146,7 @@ namespace osu.Game.Rulesets.UI if (rulesetConfig != null) { - onScreenDisplay?.Unregister(this, rulesetConfig); + onScreenDisplay?.StopTracking(this, rulesetConfig); rulesetConfig = null; } } From 5689e93bedd4390e8e3e783d7b1677fd72804ef6 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Jan 2018 16:24:08 +0900 Subject: [PATCH 12/27] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index c0c21831ce..736a139a74 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit c0c21831cef6b2946c5b067f5c4bbd929e89c2ec +Subproject commit 736a139a748eba7cebea41a09b404d47ca589522 From 1fda45fe1098c6a1ef1aa3067c7d0715978d5819 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Jan 2018 16:40:18 +0900 Subject: [PATCH 13/27] Fix broken formatting --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 3b552629cf..9911be9daa 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -80,7 +80,7 @@ namespace osu.Game.Rulesets.Mania.UI return null; } - private Bindable scrollTime; + private Bindable scrollTime; [BackgroundDependencyLoader] private void load(ManiaConfigManager maniaConfig) From b197cd56af28b58c77eedda97b324d1ca96d39de Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 Jan 2018 16:42:31 +0900 Subject: [PATCH 14/27] Allow DI'd OnScreenDisplay to be null --- osu.Game/Rulesets/UI/RulesetContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 69249c1fe6..f9a7bbe4c8 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -88,7 +88,7 @@ namespace osu.Game.Rulesets.UI Cursor = CreateCursor(); } - [BackgroundDependencyLoader] + [BackgroundDependencyLoader(true)] private void load(Storage storage, OnScreenDisplay onScreenDisplay) { this.onScreenDisplay = onScreenDisplay; From 5a00ae36d124621188096546dfb5b172a7428d4e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Jan 2018 17:35:37 +0900 Subject: [PATCH 15/27] Add database-based configuration for rulesets --- .../Configuration/ManiaConfigManager.cs | 6 +- .../UI/ManiaRulesetContainer.cs | 4 +- .../Configuration/DatabasedConfigManager.cs | 67 ++++ osu.Game/Configuration/DatabasedSetting.cs | 31 ++ osu.Game/Configuration/OsuConfigManager.cs | 2 +- osu.Game/Configuration/Setting.cs | 41 +++ osu.Game/Configuration/SettingsStore.cs | 42 +++ osu.Game/Database/DatabaseBackedStore.cs | 10 +- osu.Game/Database/OsuDbContext.cs | 8 +- .../20180124024000_AddSettings.Designer.cs | 327 ++++++++++++++++++ .../Migrations/20180124024000_AddSettings.cs | 56 +++ .../Migrations/OsuDbContextModelSnapshot.cs | 22 +- osu.Game/OsuGameBase.cs | 3 + .../Configuration/RulesetConfigManager.cs | 15 +- osu.Game/Rulesets/UI/RulesetContainer.cs | 8 +- .../Components/DrawingsConfigManager.cs | 2 +- osu.Game/osu.Game.csproj | 8 + 17 files changed, 624 insertions(+), 28 deletions(-) create mode 100644 osu.Game/Configuration/DatabasedConfigManager.cs create mode 100644 osu.Game/Configuration/DatabasedSetting.cs create mode 100644 osu.Game/Configuration/Setting.cs create mode 100644 osu.Game/Configuration/SettingsStore.cs create mode 100644 osu.Game/Migrations/20180124024000_AddSettings.Designer.cs create mode 100644 osu.Game/Migrations/20180124024000_AddSettings.cs diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs index 0f062ed72a..3167d8300d 100644 --- a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs @@ -2,15 +2,15 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Framework.Configuration.Tracking; -using osu.Framework.Platform; +using osu.Game.Configuration; using osu.Game.Rulesets.Configuration; namespace osu.Game.Rulesets.Mania.Configuration { public class ManiaConfigManager : RulesetConfigManager { - public ManiaConfigManager(Ruleset ruleset, Storage storage) - : base(ruleset, storage) + public ManiaConfigManager(RulesetInfo ruleset, SettingsStore settings) + : base(ruleset, settings) { } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index 109c967ded..f517d6b041 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -8,9 +8,9 @@ using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Input; using osu.Framework.MathUtils; -using osu.Framework.Platform; using osu.Game.Beatmaps; using osu.Game.Beatmaps.ControlPoints; +using osu.Game.Configuration; using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Mania.Beatmaps; using osu.Game.Rulesets.Mania.Mods; @@ -107,6 +107,6 @@ namespace osu.Game.Rulesets.Mania.UI protected override FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new ManiaFramedReplayInputHandler(replay, this); - protected override IRulesetConfigManager CreateConfig(Ruleset ruleset, Storage storage) => new ManiaConfigManager(ruleset, storage); + protected override IRulesetConfigManager CreateConfig(Ruleset ruleset, SettingsStore settings) => new ManiaConfigManager(Ruleset.RulesetInfo, settings); } } diff --git a/osu.Game/Configuration/DatabasedConfigManager.cs b/osu.Game/Configuration/DatabasedConfigManager.cs new file mode 100644 index 0000000000..f982490523 --- /dev/null +++ b/osu.Game/Configuration/DatabasedConfigManager.cs @@ -0,0 +1,67 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Configuration; +using osu.Game.Rulesets; + +namespace osu.Game.Configuration +{ + public abstract class DatabasedConfigManager : ConfigManager + where T : struct + { + private readonly SettingsStore settings; + + private readonly List databasedSettings; + + private readonly RulesetInfo ruleset; + + protected DatabasedConfigManager(SettingsStore settings, RulesetInfo ruleset = null) + { + this.settings = settings; + this.ruleset = ruleset; + + databasedSettings = settings.Query(ruleset?.ID); + + InitialiseDefaults(); + } + + protected override void PerformLoad() + { + } + + protected override bool PerformSave() + { + return true; + } + + protected override void AddBindable(T lookup, Bindable bindable) + { + base.AddBindable(lookup, bindable); + + var setting = databasedSettings.FirstOrDefault(s => (int)s.Key == (int)(object)lookup); + if (setting != null) + { + bindable.Parse(setting.Value); + } + else + { + settings.Update(setting = new DatabasedSetting + { + Key = lookup, + Value = bindable.Value, + RulesetID = ruleset?.ID + }); + + databasedSettings.Add(setting); + } + + bindable.ValueChanged += v => + { + setting.Value = v; + settings.Update(setting); + }; + } + } +} diff --git a/osu.Game/Configuration/DatabasedSetting.cs b/osu.Game/Configuration/DatabasedSetting.cs new file mode 100644 index 0000000000..b1644a3cd3 --- /dev/null +++ b/osu.Game/Configuration/DatabasedSetting.cs @@ -0,0 +1,31 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.ComponentModel.DataAnnotations.Schema; +using osu.Game.Database; + +namespace osu.Game.Configuration +{ + [Table("Settings")] + public class DatabasedSetting : Setting, IHasPrimaryKey + { + [DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int ID { get; set; } + + public int? RulesetID { get; set; } + + [Column("Key")] + public int IntKey + { + get => (int)Key; + private set => Key = value; + } + + [Column("Value")] + public string StringValue + { + get => Value.ToString(); + set => Value = value; + } + } +} diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 23f7fd6ac1..33810c9712 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -8,7 +8,7 @@ using osu.Game.Screens.Select; namespace osu.Game.Configuration { - public class OsuConfigManager : ConfigManager + public class OsuConfigManager : IniConfigManager { protected override void InitialiseDefaults() { diff --git a/osu.Game/Configuration/Setting.cs b/osu.Game/Configuration/Setting.cs new file mode 100644 index 0000000000..8c1d967ad9 --- /dev/null +++ b/osu.Game/Configuration/Setting.cs @@ -0,0 +1,41 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Configuration +{ + /// + /// A binding of a to an action. + /// + public class Setting + { + /// + /// The combination of keys which will trigger this binding. + /// + public object Key; + + /// + /// The resultant action which is triggered by this binding. + /// + public object Value; + + /// + /// Construct a new instance. + /// + /// The combination of keys which will trigger this binding. + /// The resultant action which is triggered by this binding. Usually an enum type. + public Setting(object key, object value) + { + Key = key; + Value = value; + } + + /// + /// Constructor for derived classes that may require serialisation. + /// + public Setting() + { + } + + public override string ToString() => $"{Key}=>{Value}"; + } +} diff --git a/osu.Game/Configuration/SettingsStore.cs b/osu.Game/Configuration/SettingsStore.cs new file mode 100644 index 0000000000..3bcdc05496 --- /dev/null +++ b/osu.Game/Configuration/SettingsStore.cs @@ -0,0 +1,42 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using osu.Game.Database; + +namespace osu.Game.Configuration +{ + public class SettingsStore : DatabaseBackedStore + { + public event Action SettingChanged; + + public SettingsStore(Func createContext) + : base(createContext) + { + } + + /// + /// Retrieve s for a specified ruleset/variant content. + /// + /// The ruleset's internal ID. + /// An optional variant. + /// + public List Query(int? rulesetId = null) => + GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId).ToList(); + + public void Update(Setting setting) + { + var dbSetting = (DatabasedSetting)setting; + + var context = GetContext(); + + Refresh(ref dbSetting); + dbSetting.Value = setting.Value; + context.SaveChanges(); + + SettingChanged?.Invoke(); + } + } +} diff --git a/osu.Game/Database/DatabaseBackedStore.cs b/osu.Game/Database/DatabaseBackedStore.cs index 3184696266..ec9967e097 100644 --- a/osu.Game/Database/DatabaseBackedStore.cs +++ b/osu.Game/Database/DatabaseBackedStore.cs @@ -34,8 +34,14 @@ namespace osu.Game.Database if (context.Entry(obj).State != EntityState.Detached) return; var id = obj.ID; - obj = lookupSource?.SingleOrDefault(t => t.ID == id) ?? context.Find(id); - context.Entry(obj).Reload(); + var foundObject = lookupSource?.SingleOrDefault(t => t.ID == id) ?? context.Find(id); + if (foundObject != null) + { + obj = foundObject; + context.Entry(obj).Reload(); + } + else + context.Add(obj); } /// diff --git a/osu.Game/Database/OsuDbContext.cs b/osu.Game/Database/OsuDbContext.cs index 091ec3487c..be0b4f3543 100644 --- a/osu.Game/Database/OsuDbContext.cs +++ b/osu.Game/Database/OsuDbContext.cs @@ -8,9 +8,10 @@ using Microsoft.EntityFrameworkCore.Diagnostics; using Microsoft.Extensions.Logging; using osu.Framework.Logging; using osu.Game.Beatmaps; -using osu.Game.Input.Bindings; +using osu.Game.Configuration; using osu.Game.IO; using osu.Game.Rulesets; +using DatabasedKeyBinding = osu.Game.Input.Bindings.DatabasedKeyBinding; using LogLevel = Microsoft.Extensions.Logging.LogLevel; namespace osu.Game.Database @@ -22,6 +23,7 @@ namespace osu.Game.Database public DbSet BeatmapMetadata { get; set; } public DbSet BeatmapSetInfo { get; set; } public DbSet DatabasedKeyBinding { get; set; } + public DbSet DatabasedSetting { get; set; } public DbSet FileInfo { get; set; } public DbSet RulesetInfo { get; set; } @@ -86,9 +88,11 @@ namespace osu.Game.Database modelBuilder.Entity().HasIndex(b => b.DeletePending); modelBuilder.Entity().HasIndex(b => b.Hash).IsUnique(); - modelBuilder.Entity().HasIndex(b => b.Variant); + modelBuilder.Entity().HasIndex(b => new { b.RulesetID, b.Variant }); modelBuilder.Entity().HasIndex(b => b.IntAction); + modelBuilder.Entity().HasIndex(b => b.RulesetID); + modelBuilder.Entity().HasIndex(b => b.Hash).IsUnique(); modelBuilder.Entity().HasIndex(b => b.ReferenceCount); diff --git a/osu.Game/Migrations/20180124024000_AddSettings.Designer.cs b/osu.Game/Migrations/20180124024000_AddSettings.Designer.cs new file mode 100644 index 0000000000..5bbf382f7f --- /dev/null +++ b/osu.Game/Migrations/20180124024000_AddSettings.Designer.cs @@ -0,0 +1,327 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage; +using osu.Game.Database; +using System; + +namespace osu.Game.Migrations +{ + [DbContext(typeof(OsuDbContext))] + [Migration("20180124024000_AddSettings")] + partial class AddSettings + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.0.0-rtm-26452"); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapDifficulty", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("ApproachRate"); + + b.Property("CircleSize"); + + b.Property("DrainRate"); + + b.Property("OverallDifficulty"); + + b.Property("SliderMultiplier"); + + b.Property("SliderTickRate"); + + b.HasKey("ID"); + + b.ToTable("BeatmapDifficulty"); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapInfo", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("AudioLeadIn"); + + b.Property("BaseDifficultyID"); + + b.Property("BeatDivisor"); + + b.Property("BeatmapSetInfoID"); + + b.Property("Countdown"); + + b.Property("DistanceSpacing"); + + b.Property("GridSize"); + + b.Property("Hash"); + + b.Property("Hidden"); + + b.Property("LetterboxInBreaks"); + + b.Property("MD5Hash"); + + b.Property("MetadataID"); + + b.Property("OnlineBeatmapID"); + + b.Property("Path"); + + b.Property("RulesetID"); + + b.Property("SpecialStyle"); + + b.Property("StackLeniency"); + + b.Property("StarDifficulty"); + + b.Property("StoredBookmarks"); + + b.Property("TimelineZoom"); + + b.Property("Version"); + + b.Property("WidescreenStoryboard"); + + b.HasKey("ID"); + + b.HasIndex("BaseDifficultyID"); + + b.HasIndex("BeatmapSetInfoID"); + + b.HasIndex("Hash") + .IsUnique(); + + b.HasIndex("MD5Hash") + .IsUnique(); + + b.HasIndex("MetadataID"); + + b.HasIndex("OnlineBeatmapID") + .IsUnique(); + + b.HasIndex("RulesetID"); + + b.ToTable("BeatmapInfo"); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapMetadata", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("Artist"); + + b.Property("ArtistUnicode"); + + b.Property("AudioFile"); + + b.Property("AuthorString") + .HasColumnName("Author"); + + b.Property("BackgroundFile"); + + b.Property("PreviewTime"); + + b.Property("Source"); + + b.Property("Tags"); + + b.Property("Title"); + + b.Property("TitleUnicode"); + + b.HasKey("ID"); + + b.ToTable("BeatmapMetadata"); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetFileInfo", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("BeatmapSetInfoID"); + + b.Property("FileInfoID"); + + b.Property("Filename") + .IsRequired(); + + b.HasKey("ID"); + + b.HasIndex("BeatmapSetInfoID"); + + b.HasIndex("FileInfoID"); + + b.ToTable("BeatmapSetFileInfo"); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetInfo", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("DeletePending"); + + b.Property("Hash"); + + b.Property("MetadataID"); + + b.Property("OnlineBeatmapSetID"); + + b.Property("Protected"); + + b.HasKey("ID"); + + b.HasIndex("DeletePending"); + + b.HasIndex("Hash") + .IsUnique(); + + b.HasIndex("MetadataID"); + + b.HasIndex("OnlineBeatmapSetID") + .IsUnique(); + + b.ToTable("BeatmapSetInfo"); + }); + + modelBuilder.Entity("osu.Game.Configuration.DatabasedSetting", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("IntKey") + .HasColumnName("Key"); + + b.Property("IntValue") + .HasColumnName("Value"); + + b.Property("RulesetID"); + + b.HasKey("ID"); + + b.HasIndex("RulesetID"); + + b.ToTable("Settings"); + }); + + modelBuilder.Entity("osu.Game.Input.Bindings.DatabasedKeyBinding", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("IntAction") + .HasColumnName("Action"); + + b.Property("KeysString") + .HasColumnName("Keys"); + + b.Property("RulesetID"); + + b.Property("Variant"); + + b.HasKey("ID"); + + b.HasIndex("IntAction"); + + b.HasIndex("RulesetID", "Variant"); + + b.ToTable("KeyBinding"); + }); + + modelBuilder.Entity("osu.Game.IO.FileInfo", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("Hash"); + + b.Property("ReferenceCount"); + + b.HasKey("ID"); + + b.HasIndex("Hash") + .IsUnique(); + + b.HasIndex("ReferenceCount"); + + b.ToTable("FileInfo"); + }); + + modelBuilder.Entity("osu.Game.Rulesets.RulesetInfo", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("Available"); + + b.Property("InstantiationInfo"); + + b.Property("Name"); + + b.Property("ShortName"); + + b.HasKey("ID"); + + b.HasIndex("Available"); + + b.HasIndex("ShortName") + .IsUnique(); + + b.ToTable("RulesetInfo"); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapInfo", b => + { + b.HasOne("osu.Game.Beatmaps.BeatmapDifficulty", "BaseDifficulty") + .WithMany() + .HasForeignKey("BaseDifficultyID") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("osu.Game.Beatmaps.BeatmapSetInfo", "BeatmapSet") + .WithMany("Beatmaps") + .HasForeignKey("BeatmapSetInfoID") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("osu.Game.Beatmaps.BeatmapMetadata", "Metadata") + .WithMany("Beatmaps") + .HasForeignKey("MetadataID"); + + b.HasOne("osu.Game.Rulesets.RulesetInfo", "Ruleset") + .WithMany() + .HasForeignKey("RulesetID") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetFileInfo", b => + { + b.HasOne("osu.Game.Beatmaps.BeatmapSetInfo") + .WithMany("Files") + .HasForeignKey("BeatmapSetInfoID") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("osu.Game.IO.FileInfo", "FileInfo") + .WithMany() + .HasForeignKey("FileInfoID") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("osu.Game.Beatmaps.BeatmapSetInfo", b => + { + b.HasOne("osu.Game.Beatmaps.BeatmapMetadata", "Metadata") + .WithMany("BeatmapSets") + .HasForeignKey("MetadataID"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/osu.Game/Migrations/20180124024000_AddSettings.cs b/osu.Game/Migrations/20180124024000_AddSettings.cs new file mode 100644 index 0000000000..63cacc0645 --- /dev/null +++ b/osu.Game/Migrations/20180124024000_AddSettings.cs @@ -0,0 +1,56 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace osu.Game.Migrations +{ + public partial class AddSettings : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropIndex( + name: "IX_KeyBinding_Variant", + table: "KeyBinding"); + + migrationBuilder.CreateTable( + name: "Settings", + columns: table => new + { + ID = table.Column(type: "INTEGER", nullable: false) + .Annotation("Sqlite:Autoincrement", true), + Key = table.Column(type: "INTEGER", nullable: false), + Value = table.Column(type: "INTEGER", nullable: false), + RulesetID = table.Column(type: "INTEGER", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Settings", x => x.ID); + }); + + migrationBuilder.CreateIndex( + name: "IX_KeyBinding_RulesetID_Variant", + table: "KeyBinding", + columns: new[] { "RulesetID", "Variant" }); + + migrationBuilder.CreateIndex( + name: "IX_Settings_RulesetID", + table: "Settings", + column: "RulesetID"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Settings"); + + migrationBuilder.DropIndex( + name: "IX_KeyBinding_RulesetID_Variant", + table: "KeyBinding"); + + migrationBuilder.CreateIndex( + name: "IX_KeyBinding_Variant", + table: "KeyBinding", + column: "Variant"); + } + } +} diff --git a/osu.Game/Migrations/OsuDbContextModelSnapshot.cs b/osu.Game/Migrations/OsuDbContextModelSnapshot.cs index cd4d3c2854..37e2aee3a0 100644 --- a/osu.Game/Migrations/OsuDbContextModelSnapshot.cs +++ b/osu.Game/Migrations/OsuDbContextModelSnapshot.cs @@ -193,6 +193,26 @@ namespace osu.Game.Migrations b.ToTable("BeatmapSetInfo"); }); + modelBuilder.Entity("osu.Game.Configuration.DatabasedSetting", b => + { + b.Property("ID") + .ValueGeneratedOnAdd(); + + b.Property("IntKey") + .HasColumnName("Key"); + + b.Property("IntValue") + .HasColumnName("Value"); + + b.Property("RulesetID"); + + b.HasKey("ID"); + + b.HasIndex("RulesetID"); + + b.ToTable("Settings"); + }); + modelBuilder.Entity("osu.Game.Input.Bindings.DatabasedKeyBinding", b => { b.Property("ID") @@ -212,7 +232,7 @@ namespace osu.Game.Migrations b.HasIndex("IntAction"); - b.HasIndex("Variant"); + b.HasIndex("RulesetID", "Variant"); b.ToTable("KeyBinding"); }); diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 8b317ca59a..d0b9634696 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -44,6 +44,8 @@ namespace osu.Game protected KeyBindingStore KeyBindingStore; + protected SettingsStore SettingsStore; + protected CursorOverrideContainer CursorOverrideContainer; protected override string MainResourceFile => @"osu.Game.Resources.dll"; @@ -109,6 +111,7 @@ namespace osu.Game dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory.GetContext, RulesetStore, API, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory.GetContext, Host, BeatmapManager, RulesetStore)); dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory.GetContext, RulesetStore)); + dependencies.Cache(SettingsStore = new SettingsStore(contextFactory.GetContext)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. diff --git a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs index 9106485253..4f9fbe9830 100644 --- a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs +++ b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs @@ -1,24 +1,15 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using osu.Framework.Configuration; -using osu.Framework.Platform; +using osu.Game.Configuration; namespace osu.Game.Rulesets.Configuration { - public abstract class RulesetConfigManager : ConfigManager, IRulesetConfigManager + public abstract class RulesetConfigManager : DatabasedConfigManager, IRulesetConfigManager where T : struct { - protected override string Filename => ruleset?.ShortName == null ? null : $"{ruleset.ShortName}.ini"; - private readonly Ruleset ruleset; - - protected RulesetConfigManager(Ruleset ruleset, Storage storage) - : base(storage) + protected RulesetConfigManager(RulesetInfo ruleset, SettingsStore settings) : base(settings, ruleset) { - this.ruleset = ruleset; - - // Re-load with the ruleset - Load(); } } } diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index f9a7bbe4c8..08498d48c6 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -16,7 +16,7 @@ using System.Linq; using osu.Framework.Configuration; using osu.Framework.Graphics.Cursor; using osu.Framework.Input; -using osu.Framework.Platform; +using osu.Game.Configuration; using osu.Game.Overlays; using osu.Game.Rulesets.Configuration; using osu.Game.Rulesets.Replays; @@ -89,11 +89,11 @@ namespace osu.Game.Rulesets.UI } [BackgroundDependencyLoader(true)] - private void load(Storage storage, OnScreenDisplay onScreenDisplay) + private void load(OnScreenDisplay onScreenDisplay, SettingsStore settings) { this.onScreenDisplay = onScreenDisplay; - rulesetConfig = CreateConfig(Ruleset, storage); + rulesetConfig = CreateConfig(Ruleset, settings); if (rulesetConfig != null) { @@ -135,7 +135,7 @@ namespace osu.Game.Rulesets.UI /// protected virtual CursorContainer CreateCursor() => null; - protected virtual IRulesetConfigManager CreateConfig(Ruleset ruleset, Storage storage) => null; + protected virtual IRulesetConfigManager CreateConfig(Ruleset ruleset, SettingsStore settings) => null; /// /// Creates a Playfield. diff --git a/osu.Game/Screens/Tournament/Components/DrawingsConfigManager.cs b/osu.Game/Screens/Tournament/Components/DrawingsConfigManager.cs index 0c45729a18..63000d6c54 100644 --- a/osu.Game/Screens/Tournament/Components/DrawingsConfigManager.cs +++ b/osu.Game/Screens/Tournament/Components/DrawingsConfigManager.cs @@ -6,7 +6,7 @@ using osu.Framework.Platform; namespace osu.Game.Screens.Tournament.Components { - public class DrawingsConfigManager : ConfigManager + public class DrawingsConfigManager : IniConfigManager { protected override string Filename => @"drawings.ini"; diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 05728c2b41..56cfe6646c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -265,10 +265,18 @@ + + + + + + + 20180124024000_AddSettings.cs + From 29e98a58f29ea50f6d9efedf246c2caf667ece06 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Jan 2018 17:59:49 +0900 Subject: [PATCH 16/27] Combine Setting and DatabasedSetting --- osu.Game/Configuration/DatabasedSetting.cs | 20 ++++++++++- osu.Game/Configuration/Setting.cs | 42 +--------------------- osu.Game/Configuration/SettingsStore.cs | 9 +++-- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/osu.Game/Configuration/DatabasedSetting.cs b/osu.Game/Configuration/DatabasedSetting.cs index b1644a3cd3..c284c10872 100644 --- a/osu.Game/Configuration/DatabasedSetting.cs +++ b/osu.Game/Configuration/DatabasedSetting.cs @@ -7,7 +7,7 @@ using osu.Game.Database; namespace osu.Game.Configuration { [Table("Settings")] - public class DatabasedSetting : Setting, IHasPrimaryKey + public class DatabasedSetting : IHasPrimaryKey { [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int ID { get; set; } @@ -27,5 +27,23 @@ namespace osu.Game.Configuration get => Value.ToString(); set => Value = value; } + + public object Key; + public object Value; + + public DatabasedSetting(object key, object value) + { + Key = key; + Value = value; + } + + /// + /// Constructor for derived classes that may require serialisation. + /// + public DatabasedSetting() + { + } + + public override string ToString() => $"{Key}=>{Value}"; } } diff --git a/osu.Game/Configuration/Setting.cs b/osu.Game/Configuration/Setting.cs index 8c1d967ad9..5f282702bb 100644 --- a/osu.Game/Configuration/Setting.cs +++ b/osu.Game/Configuration/Setting.cs @@ -1,41 +1 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -namespace osu.Game.Configuration -{ - /// - /// A binding of a to an action. - /// - public class Setting - { - /// - /// The combination of keys which will trigger this binding. - /// - public object Key; - - /// - /// The resultant action which is triggered by this binding. - /// - public object Value; - - /// - /// Construct a new instance. - /// - /// The combination of keys which will trigger this binding. - /// The resultant action which is triggered by this binding. Usually an enum type. - public Setting(object key, object value) - { - Key = key; - Value = value; - } - - /// - /// Constructor for derived classes that may require serialisation. - /// - public Setting() - { - } - - public override string ToString() => $"{Key}=>{Value}"; - } -} + \ No newline at end of file diff --git a/osu.Game/Configuration/SettingsStore.cs b/osu.Game/Configuration/SettingsStore.cs index 3bcdc05496..6bb186604f 100644 --- a/osu.Game/Configuration/SettingsStore.cs +++ b/osu.Game/Configuration/SettingsStore.cs @@ -26,14 +26,13 @@ namespace osu.Game.Configuration public List Query(int? rulesetId = null) => GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId).ToList(); - public void Update(Setting setting) + public void Update(DatabasedSetting setting) { - var dbSetting = (DatabasedSetting)setting; - var context = GetContext(); - Refresh(ref dbSetting); - dbSetting.Value = setting.Value; + Refresh(ref setting); + + setting.Value = setting.Value; context.SaveChanges(); SettingChanged?.Invoke(); From 72df2c681b6c63a32b9d3da4c23bbed9c0613f6c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Jan 2018 18:01:39 +0900 Subject: [PATCH 17/27] Remove game-wise settings store for the time being --- osu.Game/OsuGameBase.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index d0b9634696..8b317ca59a 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -44,8 +44,6 @@ namespace osu.Game protected KeyBindingStore KeyBindingStore; - protected SettingsStore SettingsStore; - protected CursorOverrideContainer CursorOverrideContainer; protected override string MainResourceFile => @"osu.Game.Resources.dll"; @@ -111,7 +109,6 @@ namespace osu.Game dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory.GetContext, RulesetStore, API, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory.GetContext, Host, BeatmapManager, RulesetStore)); dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory.GetContext, RulesetStore)); - dependencies.Cache(SettingsStore = new SettingsStore(contextFactory.GetContext)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. From 53c6526b22e77eecf5f6ff5c9c045422fbb31f20 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Jan 2018 18:04:54 +0900 Subject: [PATCH 18/27] Remove unused code file --- osu.Game/Configuration/Setting.cs | 1 - osu.Game/osu.Game.csproj | 1 - 2 files changed, 2 deletions(-) delete mode 100644 osu.Game/Configuration/Setting.cs diff --git a/osu.Game/Configuration/Setting.cs b/osu.Game/Configuration/Setting.cs deleted file mode 100644 index 5f282702bb..0000000000 --- a/osu.Game/Configuration/Setting.cs +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 56cfe6646c..2a09521727 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -266,7 +266,6 @@ - From c2a58223c55134223ea573d6f1a6e8cb8170e900 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Jan 2018 17:55:41 +0900 Subject: [PATCH 19/27] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 736a139a74..8c8d8242a8 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 736a139a748eba7cebea41a09b404d47ca589522 +Subproject commit 8c8d8242a8ae78ba272e5e7e89fb7662fca9a1e9 From 80b8780f560f225b184e7fe8b1a0947fd6e202ba Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Jan 2018 18:01:39 +0900 Subject: [PATCH 20/27] Revert "Remove game-wise settings store for the time being" This reverts commit 72df2c681b6c63a32b9d3da4c23bbed9c0613f6c. --- osu.Game/OsuGameBase.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index 8b317ca59a..d0b9634696 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -44,6 +44,8 @@ namespace osu.Game protected KeyBindingStore KeyBindingStore; + protected SettingsStore SettingsStore; + protected CursorOverrideContainer CursorOverrideContainer; protected override string MainResourceFile => @"osu.Game.Resources.dll"; @@ -109,6 +111,7 @@ namespace osu.Game dependencies.Cache(BeatmapManager = new BeatmapManager(Host.Storage, contextFactory.GetContext, RulesetStore, API, Host)); dependencies.Cache(ScoreStore = new ScoreStore(Host.Storage, contextFactory.GetContext, Host, BeatmapManager, RulesetStore)); dependencies.Cache(KeyBindingStore = new KeyBindingStore(contextFactory.GetContext, RulesetStore)); + dependencies.Cache(SettingsStore = new SettingsStore(contextFactory.GetContext)); dependencies.Cache(new OsuColour()); //this completely overrides the framework default. will need to change once we make a proper FontStore. From 45e8a2b69bce8a09d7c5a7cbed00b216c5431e9d Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 25 Jan 2018 20:49:18 +0900 Subject: [PATCH 21/27] Remove ManiaPlayfield local scrollTime bindable Now not needed due to having this databased. --- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 9911be9daa..c3cbf81af1 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -80,18 +80,10 @@ namespace osu.Game.Rulesets.Mania.UI return null; } - private Bindable scrollTime; - [BackgroundDependencyLoader] private void load(ManiaConfigManager maniaConfig) { maniaConfig.BindWith(ManiaSetting.ScrollTime, VisibleTimeRange); - - // Todo: The following two lines shouldn't be required, but is an effect of not having config databased - // 1. ValueChanged is run prior to values being propagated - // 2. We want the config to be saved ASAP, in-case a new ManiaPlayfield is instantiated - scrollTime = maniaConfig.GetBindable(ManiaSetting.ScrollTime); - scrollTime.ValueChanged += v => maniaConfig.Save(); } internal void OnJudgement(DrawableHitObject judgedObject, Judgement judgement) From 03154dbc6307f9ea9ac8f1fbb2cb19b15ab94432 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 25 Jan 2018 23:41:03 +0900 Subject: [PATCH 22/27] Fix incorrect initial migration Also adds variant to settings --- .../Configuration/ManiaConfigManager.cs | 4 ++-- osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs | 10 ++++------ osu.Game/Configuration/DatabasedConfigManager.cs | 4 ++-- osu.Game/Configuration/DatabasedSetting.cs | 2 ++ osu.Game/Configuration/SettingsStore.cs | 4 ++-- osu.Game/Database/OsuDbContext.cs | 2 +- ...signer.cs => 20180125143340_Settings.Designer.cs} | 12 +++++++----- ...000_AddSettings.cs => 20180125143340_Settings.cs} | 11 ++++++----- osu.Game/Migrations/OsuDbContextModelSnapshot.cs | 8 +++++--- .../Rulesets/Configuration/RulesetConfigManager.cs | 2 +- osu.Game/Rulesets/UI/RulesetContainer.cs | 5 +++++ osu.Game/osu.Game.csproj | 6 +++--- 12 files changed, 40 insertions(+), 30 deletions(-) rename osu.Game/Migrations/{20180124024000_AddSettings.Designer.cs => 20180125143340_Settings.Designer.cs} (94%) rename osu.Game/Migrations/{20180124024000_AddSettings.cs => 20180125143340_Settings.cs} (80%) diff --git a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs index 3167d8300d..a4de360870 100644 --- a/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs +++ b/osu.Game.Rulesets.Mania/Configuration/ManiaConfigManager.cs @@ -9,8 +9,8 @@ namespace osu.Game.Rulesets.Mania.Configuration { public class ManiaConfigManager : RulesetConfigManager { - public ManiaConfigManager(RulesetInfo ruleset, SettingsStore settings) - : base(ruleset, settings) + public ManiaConfigManager(SettingsStore settings, RulesetInfo ruleset, int variant) + : base(settings, ruleset, variant) { } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs index f517d6b041..436d5c1ea6 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaRulesetContainer.cs @@ -80,11 +80,9 @@ namespace osu.Game.Rulesets.Mania.UI public override ScoreProcessor CreateScoreProcessor() => new ManiaScoreProcessor(this); - public override PassThroughInputManager CreateInputManager() - { - var variantType = Mods.OfType().FirstOrDefault()?.PlayfieldType ?? PlayfieldType.Single; - return new ManiaInputManager(Ruleset.RulesetInfo, (int)variantType + Beatmap.TotalColumns); - } + public override int Variant => (int)(Mods.OfType().FirstOrDefault()?.PlayfieldType ?? PlayfieldType.Single) + Beatmap.TotalColumns; + + public override PassThroughInputManager CreateInputManager() => new ManiaInputManager(Ruleset.RulesetInfo, Variant); protected override BeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(IsForCurrentRuleset, WorkingBeatmap.Beatmap); @@ -107,6 +105,6 @@ namespace osu.Game.Rulesets.Mania.UI protected override FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new ManiaFramedReplayInputHandler(replay, this); - protected override IRulesetConfigManager CreateConfig(Ruleset ruleset, SettingsStore settings) => new ManiaConfigManager(Ruleset.RulesetInfo, settings); + protected override IRulesetConfigManager CreateConfig(Ruleset ruleset, SettingsStore settings) => new ManiaConfigManager(settings, Ruleset.RulesetInfo, Variant); } } diff --git a/osu.Game/Configuration/DatabasedConfigManager.cs b/osu.Game/Configuration/DatabasedConfigManager.cs index f982490523..5505f3d31b 100644 --- a/osu.Game/Configuration/DatabasedConfigManager.cs +++ b/osu.Game/Configuration/DatabasedConfigManager.cs @@ -17,12 +17,12 @@ namespace osu.Game.Configuration private readonly RulesetInfo ruleset; - protected DatabasedConfigManager(SettingsStore settings, RulesetInfo ruleset = null) + protected DatabasedConfigManager(SettingsStore settings, RulesetInfo ruleset = null, int variant = 0) { this.settings = settings; this.ruleset = ruleset; - databasedSettings = settings.Query(ruleset?.ID); + databasedSettings = settings.Query(ruleset?.ID, variant); InitialiseDefaults(); } diff --git a/osu.Game/Configuration/DatabasedSetting.cs b/osu.Game/Configuration/DatabasedSetting.cs index c284c10872..7c2f65c854 100644 --- a/osu.Game/Configuration/DatabasedSetting.cs +++ b/osu.Game/Configuration/DatabasedSetting.cs @@ -14,6 +14,8 @@ namespace osu.Game.Configuration public int? RulesetID { get; set; } + public int? Variant { get; set; } + [Column("Key")] public int IntKey { diff --git a/osu.Game/Configuration/SettingsStore.cs b/osu.Game/Configuration/SettingsStore.cs index 6bb186604f..536b4f5786 100644 --- a/osu.Game/Configuration/SettingsStore.cs +++ b/osu.Game/Configuration/SettingsStore.cs @@ -23,8 +23,8 @@ namespace osu.Game.Configuration /// The ruleset's internal ID. /// An optional variant. /// - public List Query(int? rulesetId = null) => - GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId).ToList(); + public List Query(int? rulesetId = null, int? variant = null) => + GetContext().DatabasedSetting.Where(b => b.RulesetID == rulesetId && b.Variant == variant).ToList(); public void Update(DatabasedSetting setting) { diff --git a/osu.Game/Database/OsuDbContext.cs b/osu.Game/Database/OsuDbContext.cs index be0b4f3543..0fa1f238a9 100644 --- a/osu.Game/Database/OsuDbContext.cs +++ b/osu.Game/Database/OsuDbContext.cs @@ -91,7 +91,7 @@ namespace osu.Game.Database modelBuilder.Entity().HasIndex(b => new { b.RulesetID, b.Variant }); modelBuilder.Entity().HasIndex(b => b.IntAction); - modelBuilder.Entity().HasIndex(b => b.RulesetID); + modelBuilder.Entity().HasIndex(b => new { b.RulesetID, b.Variant }); modelBuilder.Entity().HasIndex(b => b.Hash).IsUnique(); modelBuilder.Entity().HasIndex(b => b.ReferenceCount); diff --git a/osu.Game/Migrations/20180124024000_AddSettings.Designer.cs b/osu.Game/Migrations/20180125143340_Settings.Designer.cs similarity index 94% rename from osu.Game/Migrations/20180124024000_AddSettings.Designer.cs rename to osu.Game/Migrations/20180125143340_Settings.Designer.cs index 5bbf382f7f..8e045abc6f 100644 --- a/osu.Game/Migrations/20180124024000_AddSettings.Designer.cs +++ b/osu.Game/Migrations/20180125143340_Settings.Designer.cs @@ -10,8 +10,8 @@ using System; namespace osu.Game.Migrations { [DbContext(typeof(OsuDbContext))] - [Migration("20180124024000_AddSettings")] - partial class AddSettings + [Migration("20180125143340_Settings")] + partial class Settings { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -202,14 +202,16 @@ namespace osu.Game.Migrations b.Property("IntKey") .HasColumnName("Key"); - b.Property("IntValue") + b.Property("RulesetID"); + + b.Property("StringValue") .HasColumnName("Value"); - b.Property("RulesetID"); + b.Property("Variant"); b.HasKey("ID"); - b.HasIndex("RulesetID"); + b.HasIndex("RulesetID", "Variant"); b.ToTable("Settings"); }); diff --git a/osu.Game/Migrations/20180124024000_AddSettings.cs b/osu.Game/Migrations/20180125143340_Settings.cs similarity index 80% rename from osu.Game/Migrations/20180124024000_AddSettings.cs rename to osu.Game/Migrations/20180125143340_Settings.cs index 63cacc0645..86a6b2dc5e 100644 --- a/osu.Game/Migrations/20180124024000_AddSettings.cs +++ b/osu.Game/Migrations/20180125143340_Settings.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace osu.Game.Migrations { - public partial class AddSettings : Migration + public partial class Settings : Migration { protected override void Up(MigrationBuilder migrationBuilder) { @@ -19,8 +19,9 @@ namespace osu.Game.Migrations ID = table.Column(type: "INTEGER", nullable: false) .Annotation("Sqlite:Autoincrement", true), Key = table.Column(type: "INTEGER", nullable: false), - Value = table.Column(type: "INTEGER", nullable: false), - RulesetID = table.Column(type: "INTEGER", nullable: true) + RulesetID = table.Column(type: "INTEGER", nullable: true), + Value = table.Column(type: "TEXT", nullable: true), + Variant = table.Column(type: "INTEGER", nullable: true) }, constraints: table => { @@ -33,9 +34,9 @@ namespace osu.Game.Migrations columns: new[] { "RulesetID", "Variant" }); migrationBuilder.CreateIndex( - name: "IX_Settings_RulesetID", + name: "IX_Settings_RulesetID_Variant", table: "Settings", - column: "RulesetID"); + columns: new[] { "RulesetID", "Variant" }); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/osu.Game/Migrations/OsuDbContextModelSnapshot.cs b/osu.Game/Migrations/OsuDbContextModelSnapshot.cs index 37e2aee3a0..157125102f 100644 --- a/osu.Game/Migrations/OsuDbContextModelSnapshot.cs +++ b/osu.Game/Migrations/OsuDbContextModelSnapshot.cs @@ -201,14 +201,16 @@ namespace osu.Game.Migrations b.Property("IntKey") .HasColumnName("Key"); - b.Property("IntValue") + b.Property("RulesetID"); + + b.Property("StringValue") .HasColumnName("Value"); - b.Property("RulesetID"); + b.Property("Variant"); b.HasKey("ID"); - b.HasIndex("RulesetID"); + b.HasIndex("RulesetID", "Variant"); b.ToTable("Settings"); }); diff --git a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs index 4f9fbe9830..9f244f6267 100644 --- a/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs +++ b/osu.Game/Rulesets/Configuration/RulesetConfigManager.cs @@ -8,7 +8,7 @@ namespace osu.Game.Rulesets.Configuration public abstract class RulesetConfigManager : DatabasedConfigManager, IRulesetConfigManager where T : struct { - protected RulesetConfigManager(RulesetInfo ruleset, SettingsStore settings) : base(settings, ruleset) + protected RulesetConfigManager(SettingsStore settings, RulesetInfo ruleset, int variant) : base(settings, ruleset, variant) { } } diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 08498d48c6..8f72644b28 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -38,6 +38,11 @@ namespace osu.Game.Rulesets.UI /// public bool AspectAdjust = true; + /// + /// The selected variant. + /// + public virtual int Variant => 0; + /// /// The input manager for this RulesetContainer. /// diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 2a09521727..7f88f65a24 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -272,9 +272,9 @@ - - - 20180124024000_AddSettings.cs + + + 20180125143340_Settings.cs From 3b9318e894e206d436bbb8d9a124431b8fe7a8ae Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 26 Jan 2018 07:39:03 +0900 Subject: [PATCH 23/27] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 8c8d8242a8..332d133a66 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 8c8d8242a8ae78ba272e5e7e89fb7662fca9a1e9 +Subproject commit 332d133a667b2a4d628d08878967e26bc5aae441 From 7a2420ead273a65707e162409b6b6ed46f099ebd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 26 Jan 2018 08:21:09 +0900 Subject: [PATCH 24/27] Fix a couple of regressions --- osu.Game/Configuration/DatabasedConfigManager.cs | 6 +++++- osu.Game/Configuration/SettingsStore.cs | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/osu.Game/Configuration/DatabasedConfigManager.cs b/osu.Game/Configuration/DatabasedConfigManager.cs index 5505f3d31b..7d045ff6d4 100644 --- a/osu.Game/Configuration/DatabasedConfigManager.cs +++ b/osu.Game/Configuration/DatabasedConfigManager.cs @@ -13,6 +13,8 @@ namespace osu.Game.Configuration { private readonly SettingsStore settings; + private int variant; + private readonly List databasedSettings; private readonly RulesetInfo ruleset; @@ -21,6 +23,7 @@ namespace osu.Game.Configuration { this.settings = settings; this.ruleset = ruleset; + this.variant = variant; databasedSettings = settings.Query(ruleset?.ID, variant); @@ -51,7 +54,8 @@ namespace osu.Game.Configuration { Key = lookup, Value = bindable.Value, - RulesetID = ruleset?.ID + RulesetID = ruleset?.ID, + Variant = variant, }); databasedSettings.Add(setting); diff --git a/osu.Game/Configuration/SettingsStore.cs b/osu.Game/Configuration/SettingsStore.cs index 536b4f5786..9b18151c84 100644 --- a/osu.Game/Configuration/SettingsStore.cs +++ b/osu.Game/Configuration/SettingsStore.cs @@ -30,9 +30,12 @@ namespace osu.Game.Configuration { var context = GetContext(); + var newValue = setting.Value; + Refresh(ref setting); - setting.Value = setting.Value; + setting.Value = newValue; + context.SaveChanges(); SettingChanged?.Invoke(); From db58e4dbfed992ba503727077b994784de30866f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 26 Jan 2018 15:02:55 +0900 Subject: [PATCH 25/27] Update framework again --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 332d133a66..209021fb49 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 332d133a667b2a4d628d08878967e26bc5aae441 +Subproject commit 209021fb491e21625127be5dbf5efb4c409e6f06 From 81c759f1e1f6ad1e21bf6c224fca15817af2cf54 Mon Sep 17 00:00:00 2001 From: Dan Balasescu <1329837+smoogipoo@users.noreply.github.com> Date: Fri, 26 Jan 2018 15:17:56 +0900 Subject: [PATCH 26/27] Make field readonly --- osu.Game/Configuration/DatabasedConfigManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Configuration/DatabasedConfigManager.cs b/osu.Game/Configuration/DatabasedConfigManager.cs index 7d045ff6d4..1f7a84c6d3 100644 --- a/osu.Game/Configuration/DatabasedConfigManager.cs +++ b/osu.Game/Configuration/DatabasedConfigManager.cs @@ -13,7 +13,7 @@ namespace osu.Game.Configuration { private readonly SettingsStore settings; - private int variant; + private readonly int variant; private readonly List databasedSettings; From 1ab2a4075f7bd25fbdc87c1365e142a8935a75ef Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 26 Jan 2018 15:39:37 +0900 Subject: [PATCH 27/27] Update resources --- osu-resources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-resources b/osu-resources index 7724abdf1d..266965f0d7 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 7724abdf1d7c9705ba2e3989a9c604e17ccdc871 +Subproject commit 266965f0d795b94a126e2da302bd2c10eadd642a