mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 07:22:54 +08:00
Simplify construction of ScrollingInfo
This commit is contained in:
parent
ad45bc7666
commit
54668a0dec
@ -6,11 +6,14 @@ using OpenTK;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
using osu.Game.Rulesets.UI;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
|
||||
namespace osu.Game.Rulesets.Mania.Edit
|
||||
{
|
||||
public class ManiaEditRulesetContainer : ManiaRulesetContainer
|
||||
{
|
||||
public new IScrollingInfo ScrollingInfo => base.ScrollingInfo;
|
||||
|
||||
public ManiaEditRulesetContainer(Ruleset ruleset, WorkingBeatmap beatmap)
|
||||
: base(ruleset, beatmap)
|
||||
{
|
||||
|
@ -24,15 +24,20 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
{
|
||||
}
|
||||
|
||||
private DependencyContainer dependencies;
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
dependencies.CacheAs<IScrollingInfo>(new ScrollingInfo());
|
||||
return dependencies;
|
||||
}
|
||||
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
|
||||
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>();
|
||||
|
||||
@ -48,10 +53,5 @@ namespace osu.Game.Rulesets.Mania.Edit
|
||||
|
||||
return base.CreateBlueprintFor(hitObject);
|
||||
}
|
||||
|
||||
private class ScrollingInfo : IScrollingInfo
|
||||
{
|
||||
public IBindable<ScrollingDirection> Direction { get; } = new Bindable<ScrollingDirection>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,7 +35,8 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
/// <returns></returns>
|
||||
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))]
|
||||
private readonly IScrollAlgorithm algorithm;
|
||||
@ -55,13 +56,14 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
algorithm = new ConstantScrollAlgorithm();
|
||||
break;
|
||||
}
|
||||
|
||||
ScrollingInfo = CreateScrollingInfo();
|
||||
ScrollingInfo.Direction.BindTo(Direction);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
scrollingInfo.Direction.BindTo(Direction);
|
||||
|
||||
// Calculate default multiplier control points
|
||||
var lastTimingPoint = new TimingControlPoint();
|
||||
var lastDifficultyPoint = new DifficultyControlPoint();
|
||||
@ -107,19 +109,9 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
controlPoints.Add(new MultiplierControlPoint { Velocity = Beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier });
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||
protected virtual IScrollingInfo CreateScrollingInfo() => new LocalScrollingInfo();
|
||||
|
||||
if ((scrollingInfo = dependencies.Get<IScrollingInfo>()) == null)
|
||||
dependencies.CacheAs(scrollingInfo = CreateScrollingInfo());
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
protected virtual IScrollingInfo CreateScrollingInfo() => new ScrollingInfo();
|
||||
|
||||
private class ScrollingInfo : IScrollingInfo
|
||||
private class LocalScrollingInfo : IScrollingInfo
|
||||
{
|
||||
public IBindable<ScrollingDirection> Direction { get; } = new Bindable<ScrollingDirection>();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user