From 5bac0919f004aee28dd1fc7f1889da35f5905a15 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 16 Jun 2017 13:00:08 +0900 Subject: [PATCH] Remove gross autoSizingAxes and life time. --- .../Tests/TestCaseScrollingHitObjects.cs | 7 ++--- .../BasicScrollingDrawableTimingSection.cs | 1 - .../GravityScrollingDrawableTimingSection.cs | 1 - .../Timing/ManiaSpeedAdjustmentContainer.cs | 22 +++------------ osu.Game.Rulesets.Mania/UI/Column.cs | 2 +- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 2 +- .../Rulesets/Timing/DrawableTimingSection.cs | 12 ++++---- .../Timing/SpeedAdjustmentCollection.cs | 12 ++++++++ .../Timing/SpeedAdjustmentContainer.cs | 28 ++++++++++--------- 9 files changed, 42 insertions(+), 45 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs b/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs index e2620f4246..5e73d900a5 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs @@ -69,7 +69,7 @@ namespace osu.Desktop.VisualTests.Tests RelativeSizeAxes = Axes.Both, Alpha = 0.25f }, - adjustmentCollection = new SpeedAdjustmentCollection + adjustmentCollection = new SpeedAdjustmentCollection(Axes.Y) { RelativeSizeAxes = Axes.Both, VisibleTimeRange = timeRangeBindable, @@ -126,18 +126,17 @@ namespace osu.Desktop.VisualTests.Tests private class TestSpeedAdjustmentContainer : SpeedAdjustmentContainer { public TestSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) - : base(controlPoint, Axes.Y) + : base(controlPoint) { } - protected override DrawableTimingSection CreateTimingSection() => new TestDrawableTimingSection(ControlPoint); + protected override DrawableTimingSection CreateTimingSection(MultiplierControlPoint controlPoint) => new TestDrawableTimingSection(controlPoint); private class TestDrawableTimingSection : DrawableTimingSection { private readonly MultiplierControlPoint controlPoint; public TestDrawableTimingSection(MultiplierControlPoint controlPoint) - : base(Axes.Y) { this.controlPoint = controlPoint; } diff --git a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs index f579567a6c..54f24b0c5d 100644 --- a/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/BasicScrollingDrawableTimingSection.cs @@ -14,7 +14,6 @@ namespace osu.Game.Rulesets.Mania.Timing private readonly MultiplierControlPoint controlPoint; public BasicScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) - : base(Axes.Y) { this.controlPoint = controlPoint; } diff --git a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs b/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs index df8daa43dd..5d8721bee0 100644 --- a/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs +++ b/osu.Game.Rulesets.Mania/Timing/GravityScrollingDrawableTimingSection.cs @@ -14,7 +14,6 @@ namespace osu.Game.Rulesets.Mania.Timing private readonly MultiplierControlPoint controlPoint; public GravityScrollingDrawableTimingSection(MultiplierControlPoint controlPoint) - : base(Axes.Y) { this.controlPoint = controlPoint; } diff --git a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs index 3eb2313df4..eed57eed24 100644 --- a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs @@ -11,34 +11,20 @@ namespace osu.Game.Rulesets.Mania.Timing private readonly ScrollingAlgorithm scrollingAlgorithm; public ManiaSpeedAdjustmentContainer(MultiplierControlPoint timingSection, ScrollingAlgorithm scrollingAlgorithm) - : base(timingSection, Axes.Y) + : base(timingSection) { this.scrollingAlgorithm = scrollingAlgorithm; } - protected override void UpdateAfterChildren() - { - base.UpdateAfterChildren(); - - var parent = Parent as SpeedAdjustmentCollection; - - if (parent == null) - return; - - // This is very naive and can be improved, but is adequate for now - LifetimeStart = ControlPoint.StartTime - VisibleTimeRange; - LifetimeEnd = ControlPoint.StartTime + Content.Height * 2; - } - - protected override DrawableTimingSection CreateTimingSection() + protected override DrawableTimingSection CreateTimingSection(MultiplierControlPoint controlPoint) { switch (scrollingAlgorithm) { default: case ScrollingAlgorithm.Basic: - return new BasicScrollingDrawableTimingSection(ControlPoint); + return new BasicScrollingDrawableTimingSection(controlPoint); case ScrollingAlgorithm.Gravity: - return new GravityScrollingDrawableTimingSection(ControlPoint); + return new GravityScrollingDrawableTimingSection(controlPoint); } } } diff --git a/osu.Game.Rulesets.Mania/UI/Column.cs b/osu.Game.Rulesets.Mania/UI/Column.cs index f832d8db45..dea4dc1a3a 100644 --- a/osu.Game.Rulesets.Mania/UI/Column.cs +++ b/osu.Game.Rulesets.Mania/UI/Column.cs @@ -97,7 +97,7 @@ namespace osu.Game.Rulesets.Mania.UI } } }, - speedAdjustments = new SpeedAdjustmentCollection + speedAdjustments = new SpeedAdjustmentCollection(Axes.Y) { Name = "Hit objects", RelativeSizeAxes = Axes.Both, diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index ae235db5d5..5f33ac2cf1 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -122,7 +122,7 @@ namespace osu.Game.Rulesets.Mania.UI Padding = new MarginPadding { Top = HIT_TARGET_POSITION }, Children = new[] { - barLineContainer = new SpeedAdjustmentCollection + barLineContainer = new SpeedAdjustmentCollection(Axes.Y) { Name = "Bar lines", Anchor = Anchor.TopCentre, diff --git a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs b/osu.Game/Rulesets/Timing/DrawableTimingSection.cs index d58e0ae8cd..ef5daf0de8 100644 --- a/osu.Game/Rulesets/Timing/DrawableTimingSection.cs +++ b/osu.Game/Rulesets/Timing/DrawableTimingSection.cs @@ -46,18 +46,18 @@ namespace osu.Game.Rulesets.Timing protected override IComparer DepthComparer => new HitObjectReverseStartTimeComparer(); - private readonly Axes autoSizingAxes; + /// + /// Axes through which this timing section scrolls. This is set from . + /// + internal Axes ScrollingAxes; private Cached layout = new Cached(); /// /// Creates a new . /// - /// The axes on which to auto-size to the total size of items in the container. - protected DrawableTimingSection(Axes autoSizingAxes) + protected DrawableTimingSection() { - this.autoSizingAxes = autoSizingAxes; - RelativeSizeAxes = Axes.Both; RelativePositionAxes = Axes.Both; } @@ -101,7 +101,7 @@ namespace osu.Game.Rulesets.Timing float height = Children.Select(child => child.Y + child.Height).Max() - RelativeChildOffset.Y; // Consider that width/height are time values. To have ourselves span these time values 1:1, we first need to set our size - Size = new Vector2((autoSizingAxes & Axes.X) > 0 ? width : Size.X, (autoSizingAxes & Axes.Y) > 0 ? height : Size.Y); + Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? width : Size.X, (ScrollingAxes & Axes.Y) > 0 ? height : Size.Y); // Then to make our position-space be time values again, we need our relative child size to follow our size RelativeChildSize = Size; }); diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs index 9fb0c582d7..53ad00c5e1 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs @@ -40,6 +40,17 @@ namespace osu.Game.Rulesets.Timing /// private readonly Queue queuedHitObjects = new Queue(); + private readonly Axes scrollingAxes; + + /// + /// Creates a new . + /// + /// The axes upon which hit objects should appear to scroll inside this container. + public SpeedAdjustmentCollection(Axes scrollingAxes) + { + this.scrollingAxes = scrollingAxes; + } + /// /// Adds a hit object to this . The hit objects will be kept in a queue /// and will be processed when new s are added to this . @@ -53,6 +64,7 @@ namespace osu.Game.Rulesets.Timing public override void Add(SpeedAdjustmentContainer speedAdjustment) { speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange); + speedAdjustment.ScrollingAxes = scrollingAxes; base.Add(speedAdjustment); } diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index d5383eaef8..2227277c36 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -7,6 +7,9 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Rulesets.Objects.Drawables; using OpenTK; +using System; +using System.Linq; +using osu.Game.Rulesets.Objects.Types; namespace osu.Game.Rulesets.Timing { @@ -31,35 +34,34 @@ namespace osu.Game.Rulesets.Timing set { visibleTimeRange.BindTo(value); } } - /// - /// The which provides the speed adjustments for this container. - /// - public readonly MultiplierControlPoint ControlPoint; - protected override Container Content => content; private Container content; - public readonly Axes ScrollingAxes; + /// + /// Axes which the content of this container will scroll through. + /// + /// + public Axes ScrollingAxes { get; internal set; } + + public readonly MultiplierControlPoint ControlPoint; /// /// Creates a new . /// /// The which provides the speed adjustments for this container. - /// The axes through which the content of this container should scroll through. - protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint, Axes scrollingAxes) + protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint) { - ScrollingAxes = scrollingAxes; + this.ControlPoint = controlPoint; RelativeSizeAxes = Axes.Both; - - ControlPoint = controlPoint; } [BackgroundDependencyLoader] private void load() { - DrawableTimingSection timingSection = CreateTimingSection(); + DrawableTimingSection timingSection = CreateTimingSection(ControlPoint); + timingSection.ScrollingAxes = ScrollingAxes; timingSection.VisibleTimeRange.BindTo(VisibleTimeRange); timingSection.RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); @@ -89,6 +91,6 @@ namespace osu.Game.Rulesets.Timing /// Creates the container which handles the movement of a collection of hit objects. /// /// The . - protected abstract DrawableTimingSection CreateTimingSection(); + protected abstract DrawableTimingSection CreateTimingSection(MultiplierControlPoint controlPoint); } } \ No newline at end of file