1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 14:12:56 +08:00

Give ruleset settings a ruleset-specific config manager

This commit is contained in:
smoogipoo 2018-06-11 13:28:50 +09:00
parent eca016ec6c
commit f4fbf27d42
4 changed files with 44 additions and 3 deletions

View File

@ -130,7 +130,7 @@ namespace osu.Game.Rulesets.Osu
public override string ShortName => "osu"; public override string ShortName => "osu";
public override SettingsSubsection CreateSettings() => new OsuSettings(); public override RulesetSettingsSubsection CreateSettings() => new OsuSettings(this);
public override int? LegacyID => 0; public override int? LegacyID => 0;

View File

@ -8,10 +8,15 @@ using osu.Game.Overlays.Settings;
namespace osu.Game.Rulesets.Osu.UI namespace osu.Game.Rulesets.Osu.UI
{ {
public class OsuSettings : SettingsSubsection public class OsuSettings : RulesetSettingsSubsection
{ {
protected override string Header => "osu!"; protected override string Header => "osu!";
public OsuSettings(Ruleset ruleset)
: base(ruleset)
{
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuConfigManager config) private void load(OsuConfigManager config)
{ {

View File

@ -0,0 +1,36 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Game.Configuration;
using osu.Game.Rulesets;
namespace osu.Game.Overlays.Settings
{
/// <summary>
/// A <see cref="SettingsSubsection"/> which provides subclasses with the <see cref="IRulesetConfigManager"/>
/// from the <see cref="Ruleset"/>'s <see cref="Ruleset.CreateConfig()"/>.
/// </summary>
public abstract class RulesetSettingsSubsection : SettingsSubsection
{
private readonly Ruleset ruleset;
protected RulesetSettingsSubsection(Ruleset ruleset)
{
this.ruleset = ruleset;
}
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
{
dependencies = new DependencyContainer(base.CreateLocalDependencies(parent));
var config = ruleset.CreateConfig(dependencies.Get<SettingsStore>());
if (config != null)
dependencies.Cache(config);
return dependencies;
}
}
}

View File

@ -71,7 +71,7 @@ namespace osu.Game.Rulesets
public abstract string Description { get; } public abstract string Description { get; }
public virtual SettingsSubsection CreateSettings() => null; public virtual RulesetSettingsSubsection CreateSettings() => null;
/// <summary> /// <summary>
/// Creates the <see cref="IRulesetConfigManager"/> for this <see cref="Ruleset"/>. /// Creates the <see cref="IRulesetConfigManager"/> for this <see cref="Ruleset"/>.