1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 01:02:54 +08:00

Simplify construction of ScrollingInfo

This commit is contained in:
smoogipoo 2018-11-07 16:43:34 +09:00
parent ad45bc7666
commit 54668a0dec
3 changed files with 21 additions and 26 deletions

View File

@ -6,11 +6,14 @@ using OpenTK;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Rulesets.UI.Scrolling;
namespace osu.Game.Rulesets.Mania.Edit namespace osu.Game.Rulesets.Mania.Edit
{ {
public class ManiaEditRulesetContainer : ManiaRulesetContainer public class ManiaEditRulesetContainer : ManiaRulesetContainer
{ {
public new IScrollingInfo ScrollingInfo => base.ScrollingInfo;
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
: base(ruleset, beatmap) : base(ruleset, beatmap)
{ {

View File

@ -24,15 +24,20 @@ namespace osu.Game.Rulesets.Mania.Edit
{ {
} }
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ => dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
dependencies.CacheAs<IScrollingInfo>(new ScrollingInfo());
return dependencies;
}
protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap) protected override RulesetContainer<ManiaHitObject> CreateRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
=> new ManiaEditRulesetContainer(ruleset, beatmap); {
var rulesetContainer = new ManiaEditRulesetContainer(ruleset, beatmap);
// This is the earliest we can cache the scrolling info to ourselves, before masks are added to the hierarchy and inject it
dependencies.CacheAs(rulesetContainer.ScrollingInfo);
return rulesetContainer;
}
protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => Array.Empty<HitObjectCompositionTool>(); protected override IReadOnlyList<HitObjectCompositionTool> CompositionTools => Array.Empty<HitObjectCompositionTool>();
@ -48,10 +53,5 @@ namespace osu.Game.Rulesets.Mania.Edit
return base.CreateBlueprintFor(hitObject); return base.CreateBlueprintFor(hitObject);
} }
private class ScrollingInfo : IScrollingInfo
{
public IBindable<ScrollingDirection> Direction { get; } = new Bindable<ScrollingDirection>();
}
} }
} }

View File

@ -35,7 +35,8 @@ namespace osu.Game.Rulesets.UI.Scrolling
/// <returns></returns> /// <returns></returns>
private readonly SortedList<MultiplierControlPoint> controlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default); private readonly SortedList<MultiplierControlPoint> controlPoints = new SortedList<MultiplierControlPoint>(Comparer<MultiplierControlPoint>.Default);
private IScrollingInfo scrollingInfo; [Cached(Type = typeof(IScrollingInfo))]
protected readonly IScrollingInfo ScrollingInfo;
[Cached(Type = typeof(IScrollAlgorithm))] [Cached(Type = typeof(IScrollAlgorithm))]
private readonly IScrollAlgorithm algorithm; private readonly IScrollAlgorithm algorithm;
@ -55,13 +56,14 @@ namespace osu.Game.Rulesets.UI.Scrolling
algorithm = new ConstantScrollAlgorithm(); algorithm = new ConstantScrollAlgorithm();
break; break;
} }
ScrollingInfo = CreateScrollingInfo();
ScrollingInfo.Direction.BindTo(Direction);
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
scrollingInfo.Direction.BindTo(Direction);
// Calculate default multiplier control points // Calculate default multiplier control points
var lastTimingPoint = new TimingControlPoint(); var lastTimingPoint = new TimingControlPoint();
var lastDifficultyPoint = new DifficultyControlPoint(); var lastDifficultyPoint = new DifficultyControlPoint();
@ -107,19 +109,9 @@ namespace osu.Game.Rulesets.UI.Scrolling
controlPoints.Add(new MultiplierControlPoint { Velocity = Beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier }); controlPoints.Add(new MultiplierControlPoint { Velocity = Beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier });
} }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected virtual IScrollingInfo CreateScrollingInfo() => new LocalScrollingInfo();
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
if ((scrollingInfo = dependencies.Get<IScrollingInfo>()) == null) private class LocalScrollingInfo : IScrollingInfo
dependencies.CacheAs(scrollingInfo = CreateScrollingInfo());
return dependencies;
}
protected virtual IScrollingInfo CreateScrollingInfo() => new ScrollingInfo();
private class ScrollingInfo : IScrollingInfo
{ {
public IBindable<ScrollingDirection> Direction { get; } = new Bindable<ScrollingDirection>(); public IBindable<ScrollingDirection> Direction { get; } = new Bindable<ScrollingDirection>();
} }