From c6447e40f92368fef7ca796e200a80ada951e949 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 7 Aug 2017 14:56:26 +0900 Subject: [PATCH] Reduce implementation overhead for nested playfields (e.g. playfield + columns). --- osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs | 6 ------ osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 15 +++++++++------ osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 11 +++++++++++ osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs | 13 +++++++------ 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs index 04185f0872..a34765448c 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaHitRenderer.cs @@ -114,12 +114,6 @@ namespace osu.Game.Rulesets.Mania.UI protected override Vector2 GetPlayfieldAspectAdjust() => new Vector2(1, 0.8f); - protected override void ApplySpeedAdjustment(MultiplierControlPoint controlPoint) - { - base.ApplySpeedAdjustment(controlPoint); - Playfield.Columns.ForEach(c => c.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint))); - } - protected override SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) => new ManiaSpeedAdjustmentContainer(controlPoint, ScrollingAlgorithm.Basic); } } diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 3b1dc58e4f..4b240e4659 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -52,7 +52,8 @@ namespace osu.Game.Rulesets.Mania.UI private readonly FlowContainer columns; public IEnumerable Columns => columns.Children; - private readonly ScrollingHitObjectContainer barLineContainer; + protected override Container Content => barLineContainer; + private readonly Container barLineContainer; private List normalColumnColours = new List(); private Color4 specialColumnColour; @@ -67,7 +68,7 @@ namespace osu.Game.Rulesets.Mania.UI if (columnCount <= 0) throw new ArgumentException("Can't have zero or fewer columns."); - Children = new Drawable[] + InternalChildren = new Drawable[] { new Container { @@ -111,13 +112,12 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Top = HIT_TARGET_POSITION }, Children = new[] { - barLineContainer = new ScrollingHitObjectContainer(Axes.Y) + barLineContainer = new Container { Name = "Bar lines", Anchor = Anchor.TopCentre, Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.Y, - VisibleTimeRange = VisibleTimeRange // Width is set in the Update method } } @@ -127,7 +127,11 @@ namespace osu.Game.Rulesets.Mania.UI }; for (int i = 0; i < columnCount; i++) - columns.Add(new Column { VisibleTimeRange = VisibleTimeRange }); + { + var c = new Column { VisibleTimeRange = VisibleTimeRange }; + columns.Add(c); + AddNested(c); + } } [BackgroundDependencyLoader] @@ -202,7 +206,6 @@ namespace osu.Game.Rulesets.Mania.UI public override void Add(DrawableHitObject h) => Columns.ElementAt(h.HitObject.Column).Add(h); public void Add(DrawableBarLine barline) => barLineContainer.Add(barline); - public void Add(SpeedAdjustmentContainer speedAdjustment) => barLineContainer.AddSpeedAdjustment(speedAdjustment); protected override void Update() { diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index d21b07490a..8850bd6b96 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -53,6 +53,17 @@ namespace osu.Game.Rulesets.UI }; } + private List> nestedPlayfields; + public IEnumerable> NestedPlayfields => nestedPlayfields; + + protected void AddNested(ScrollingPlayfield otherPlayfield) + { + if (nestedPlayfields == null) + nestedPlayfields = new List>(); + + nestedPlayfields.Add(otherPlayfield); + } + protected override bool OnKeyDown(InputState state, KeyDownEventArgs args) { if (state.Keyboard.ControlPressed) diff --git a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs index 5d6293c802..4a560748c1 100644 --- a/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs +++ b/osu.Game/Rulesets/UI/SpeedAdjustedHitRenderer.cs @@ -35,7 +35,13 @@ namespace osu.Game.Rulesets.UI [BackgroundDependencyLoader] private void load() { - DefaultControlPoints.ForEach(c => ApplySpeedAdjustment(c)); + DefaultControlPoints.ForEach(c => applySpeedAdjustment(c, Playfield)); + } + + private void applySpeedAdjustment(MultiplierControlPoint controlPoint, ScrollingPlayfield playfield) + { + playfield.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint)); + playfield.NestedPlayfields.ForEach(p => applySpeedAdjustment(controlPoint, p)); } protected override void ApplyBeatmap() @@ -99,11 +105,6 @@ namespace osu.Game.Rulesets.UI return new MultiplierControlPoint(time, DefaultControlPoints[index].DeepClone()); } - protected virtual void ApplySpeedAdjustment(MultiplierControlPoint controlPoint) - { - Playfield.HitObjects.AddSpeedAdjustment(CreateSpeedAdjustmentContainer(controlPoint)); - } - protected abstract SpeedAdjustmentContainer CreateSpeedAdjustmentContainer(MultiplierControlPoint controlPoint); } }