1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 12:57:36 +08:00

Move ConfigManager registration/dependency injection to RulesetContainer

This commit is contained in:
smoogipoo 2018-01-18 17:00:23 +09:00
parent c2c478750d
commit 7910b47868
6 changed files with 47 additions and 32 deletions

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -71,6 +71,7 @@ namespace osu.Game
private OsuScreen screenStack;
private VolumeControl volume;
private OnScreenDisplay onscreenDisplay;
private Bindable<int> configRuleset;
public Bindable<RulesetInfo> Ruleset = new Bindable<RulesetInfo>();
@ -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);

View File

@ -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
/// <returns>A descriptive name of the variant.</returns>
public virtual string GetVariantName(int variant) => string.Empty;
private static readonly Dictionary<Type, IRulesetConfigManager> config_manager_cache = new Dictionary<Type, IRulesetConfigManager>();
public IRulesetConfigManager GetConfigManager(Storage storage)
{
if (config_manager_cache.TryGetValue(GetType(), out var existing))
return existing;
return config_manager_cache[GetType()] = CreateConfigManager(storage);
}
/// <summary>
/// The <see cref="ConfigManager{T}"/> that is used for settings specific to this <see cref="Ruleset"/>.
/// </summary>
protected virtual IRulesetConfigManager CreateConfigManager(Storage storage) => null;
/// <summary>
/// Create a ruleset info based on this ruleset.
/// </summary>

View File

@ -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));
/// <summary>
/// A visual representation of a <see cref="Rulesets.Ruleset"/>.
/// </summary>
@ -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<Type, IRulesetConfigManager> config_cache = new Dictionary<Type, IRulesetConfigManager>();
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();
/// <summary>
@ -107,11 +137,19 @@ namespace osu.Game.Rulesets.UI
/// </summary>
protected virtual CursorContainer CreateCursor() => null;
protected virtual IRulesetConfigManager CreateConfig(Ruleset ruleset, Storage storage) => null;
/// <summary>
/// Creates a Playfield.
/// </summary>
/// <returns>The Playfield.</returns>
protected abstract Playfield CreatePlayfield();
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
rulesetConfig.Save();
}
}
/// <summary>

View File

@ -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)
{