From 56244e01347313be41cafa4828e984cbb40d6ace Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Mon, 12 Jun 2017 17:31:24 +0900 Subject: [PATCH] Add small test case to demonstrate usage. --- .../Tests/TestCaseScrollingHitObjects.cs | 128 ++++++++++++++++++ .../osu.Desktop.VisualTests.csproj | 1 + .../Timing/ManiaSpeedAdjustmentContainer.cs | 8 +- .../Timing/SpeedAdjustmentCollection.cs | 4 +- .../Timing/SpeedAdjustmentContainer.cs | 14 +- 5 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs b/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs new file mode 100644 index 0000000000..55d1d2071f --- /dev/null +++ b/osu.Desktop.VisualTests/Tests/TestCaseScrollingHitObjects.cs @@ -0,0 +1,128 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Globalization; +using OpenTK; +using OpenTK.Graphics; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Testing; +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Timing; + +namespace osu.Desktop.VisualTests.Tests +{ + public class TestCaseScrollingHitObjects : TestCase + { + public override string Description => "SpeedAdjustmentContainer/DrawableTimingSection"; + + private SpeedAdjustmentCollection adjustmentCollection; + + private BindableDouble timeRangeBindable; + private SpriteText timeRangeText; + + public override void Reset() + { + base.Reset(); + + timeRangeBindable = new BindableDouble(2000) + { + MinValue = 50, + MaxValue = 20000, + }; + + SliderBar timeRange; + Add(timeRange = new BasicSliderBar + { + Size = new Vector2(200, 20), + SelectionColor = Color4.Pink, + KeyboardStep = 100 + }); + + Add(timeRangeText = new SpriteText + { + X = 210, + TextSize = 16, + }); + + timeRange.Current.BindTo(timeRangeBindable); + timeRangeBindable.ValueChanged += v => timeRangeText.Text = v.ToString(CultureInfo.InvariantCulture); + + Add(new Drawable[] + { + new Container + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Size = new Vector2(100, 500), + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Alpha = 0.25f + }, + adjustmentCollection = new SpeedAdjustmentCollection + { + RelativeSizeAxes = Axes.Both, + VisibleTimeRange = timeRangeBindable + } + } + } + }); + + adjustmentCollection.Add(new TestSpeedAdjustmentContainer(new MultiplierControlPoint())); + + AddStep("Add hit object", () => adjustmentCollection.Add(new TestDrawableHitObject(new HitObject { StartTime = Time.Current + 5000 }))); + } + + private class TestSpeedAdjustmentContainer : SpeedAdjustmentContainer + { + public TestSpeedAdjustmentContainer(MultiplierControlPoint controlPoint) + : base(controlPoint, Axes.Y) + { + } + + protected override DrawableTimingSection CreateTimingSection() => new TestDrawableTimingSection(ControlPoint); + + private class TestDrawableTimingSection : DrawableTimingSection + { + private readonly MultiplierControlPoint controlPoint; + + public TestDrawableTimingSection(MultiplierControlPoint controlPoint) + : base(Axes.Y) + { + this.controlPoint = controlPoint; + } + + protected override void Update() + { + base.Update(); + + Y = (float)(controlPoint.StartTime - Time.Current); + } + } + } + + private class TestDrawableHitObject : DrawableHitObject + { + public TestDrawableHitObject(HitObject hitObject) + : base(hitObject) + { + AutoSizeAxes = Axes.Both; + RelativePositionAxes = Axes.Y; + Y = (float)hitObject.StartTime; + + Add(new Box + { + Size = new Vector2(100) + }); + } + } + } +} \ No newline at end of file diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index d1d0cc1c1a..8b03479e0c 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -204,6 +204,7 @@ + diff --git a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs index 41bb001531..3eb2313df4 100644 --- a/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/ManiaSpeedAdjustmentContainer.cs @@ -26,8 +26,8 @@ namespace osu.Game.Rulesets.Mania.Timing return; // This is very naive and can be improved, but is adequate for now - LifetimeStart = MultiplierControlPoint.StartTime - VisibleTimeRange; - LifetimeEnd = MultiplierControlPoint.StartTime + Content.Height * 2; + LifetimeStart = ControlPoint.StartTime - VisibleTimeRange; + LifetimeEnd = ControlPoint.StartTime + Content.Height * 2; } protected override DrawableTimingSection CreateTimingSection() @@ -36,9 +36,9 @@ namespace osu.Game.Rulesets.Mania.Timing { default: case ScrollingAlgorithm.Basic: - return new BasicScrollingDrawableTimingSection(MultiplierControlPoint); + return new BasicScrollingDrawableTimingSection(ControlPoint); case ScrollingAlgorithm.Gravity: - return new GravityScrollingDrawableTimingSection(MultiplierControlPoint); + return new GravityScrollingDrawableTimingSection(ControlPoint); } } } diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs index 03bbe6528d..27784c22b3 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentCollection.cs @@ -77,11 +77,11 @@ namespace osu.Game.Rulesets.Timing var speedAdjustmentY = y as SpeedAdjustmentContainer; // If either of the two drawables are not hit objects, fall back to the base comparer - if (speedAdjustmentX?.MultiplierControlPoint == null || speedAdjustmentY?.MultiplierControlPoint == null) + if (speedAdjustmentX?.ControlPoint == null || speedAdjustmentY?.ControlPoint == null) return base.Compare(x, y); // Compare by start time - int i = speedAdjustmentY.MultiplierControlPoint.StartTime.CompareTo(speedAdjustmentX.MultiplierControlPoint.StartTime); + int i = speedAdjustmentY.ControlPoint.StartTime.CompareTo(speedAdjustmentX.ControlPoint.StartTime); return i != 0 ? i : base.Compare(x, y); } diff --git a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs index 7021c1435b..c78ccba0bd 100644 --- a/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs +++ b/osu.Game/Rulesets/Timing/SpeedAdjustmentContainer.cs @@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Timing /// /// The which provides the speed adjustments for this container. /// - public readonly MultiplierControlPoint MultiplierControlPoint; + public readonly MultiplierControlPoint ControlPoint; protected override Container Content => content; private Container content; @@ -44,15 +44,15 @@ namespace osu.Game.Rulesets.Timing /// /// Creates a new . /// - /// The which provides the speed adjustments for this container. + /// The which provides the speed adjustments for this container. /// The axes through which the content of this container should scroll through. - protected SpeedAdjustmentContainer(MultiplierControlPoint multiplierControlPoint, Axes scrollingAxes) + protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint, Axes scrollingAxes) { this.scrollingAxes = scrollingAxes; RelativeSizeAxes = Axes.Both; - MultiplierControlPoint = multiplierControlPoint; + ControlPoint = controlPoint; } [BackgroundDependencyLoader] @@ -61,14 +61,14 @@ namespace osu.Game.Rulesets.Timing DrawableTimingSection timingSection = CreateTimingSection(); timingSection.VisibleTimeRange.BindTo(VisibleTimeRange); - timingSection.RelativeChildOffset = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)MultiplierControlPoint.StartTime : 0, (scrollingAxes & Axes.Y) > 0 ? (float)MultiplierControlPoint.StartTime : 0); + timingSection.RelativeChildOffset = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (scrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0); AddInternal(content = timingSection); } protected override void Update() { - float multiplier = (float)MultiplierControlPoint.Multiplier; + float multiplier = (float)ControlPoint.Multiplier; // The speed adjustment happens by modifying our size by the multiplier while maintaining the visible time range as the relatve size for our children Size = new Vector2((scrollingAxes & Axes.X) > 0 ? multiplier : 1, (scrollingAxes & Axes.Y) > 0 ? multiplier : 1); @@ -78,7 +78,7 @@ namespace osu.Game.Rulesets.Timing /// /// Whether this speed adjustment can contain a hit object. This is true if the hit object occurs after this speed adjustment with respect to time. /// - public bool CanContain(DrawableHitObject hitObject) => MultiplierControlPoint.StartTime <= hitObject.HitObject.StartTime; + public bool CanContain(DrawableHitObject hitObject) => ControlPoint.StartTime <= hitObject.HitObject.StartTime; /// /// Creates the container which handles the movement of a collection of hit objects.