From e0c921ff5c7426c6115c9f690eb749dcb2405b15 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 4 Jan 2018 19:20:43 +0900 Subject: [PATCH] Split out ScrollingHitObjectContainer into new file --- .../Visual/TestCaseScrollingHitObjects.cs | 4 +- .../UI/ScrollingHitObjectContainer.cs | 79 +++++++++++++++++++ osu.Game/Rulesets/UI/ScrollingPlayfield.cs | 71 ----------------- osu.Game/osu.Game.csproj | 1 + 4 files changed, 82 insertions(+), 73 deletions(-) create mode 100644 osu.Game/Rulesets/UI/ScrollingHitObjectContainer.cs diff --git a/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs b/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs index b05efbde5c..71c1295ebb 100644 --- a/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs +++ b/osu.Game.Tests/Visual/TestCaseScrollingHitObjects.cs @@ -107,13 +107,13 @@ namespace osu.Game.Tests.Visual public readonly ScrollingDirection Direction; - public new ScrollingPlayfield.ScrollingHitObjectContainer HitObjects => (ScrollingPlayfield.ScrollingHitObjectContainer)base.HitObjects; + public new ScrollingHitObjectContainer HitObjects => (ScrollingHitObjectContainer)base.HitObjects; public TestPlayfield(ScrollingDirection direction) { Direction = direction; - base.HitObjects = new ScrollingPlayfield.ScrollingHitObjectContainer(direction); + base.HitObjects = new ScrollingHitObjectContainer(direction); HitObjects.TimeRange.BindTo(TimeRange); } } diff --git a/osu.Game/Rulesets/UI/ScrollingHitObjectContainer.cs b/osu.Game/Rulesets/UI/ScrollingHitObjectContainer.cs new file mode 100644 index 0000000000..61184ac53f --- /dev/null +++ b/osu.Game/Rulesets/UI/ScrollingHitObjectContainer.cs @@ -0,0 +1,79 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Lists; +using osu.Game.Rulesets.Timing; + +namespace osu.Game.Rulesets.UI +{ + public class ScrollingHitObjectContainer : Playfield.HitObjectContainer + { + public readonly BindableDouble TimeRange = new BindableDouble + { + MinValue = 0, + MaxValue = double.MaxValue + }; + + public readonly SortedList ControlPoints = new SortedList(); + + private readonly ScrollingDirection direction; + + public ScrollingHitObjectContainer(ScrollingDirection direction) + { + this.direction = direction; + + RelativeSizeAxes = Axes.Both; + } + + protected override void UpdateAfterChildren() + { + base.UpdateAfterChildren(); + + var currentMultiplier = controlPointAt(Time.Current); + + foreach (var obj in AliveObjects) + { + var relativePosition = (Time.Current - obj.HitObject.StartTime) / (TimeRange / currentMultiplier.Multiplier); + + // Todo: We may need to consider scale here + var finalPosition = (float)relativePosition * DrawSize; + + switch (direction) + { + case ScrollingDirection.Up: + obj.Y = -finalPosition.Y; + break; + case ScrollingDirection.Down: + obj.Y = finalPosition.Y; + break; + case ScrollingDirection.Left: + obj.X = -finalPosition.X; + break; + case ScrollingDirection.Right: + obj.X = finalPosition.X; + break; + } + } + } + + private readonly MultiplierControlPoint searchingPoint = new MultiplierControlPoint(); + private MultiplierControlPoint controlPointAt(double time) + { + if (ControlPoints.Count == 0) + return new MultiplierControlPoint(double.MinValue); + + if (time < ControlPoints[0].StartTime) + return ControlPoints[0]; + + searchingPoint.StartTime = time; + + int index = ControlPoints.BinarySearch(searchingPoint); + if (index < 0) + index = ~index - 1; + + return ControlPoints[index]; + } + } +} diff --git a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs index f391d01ac9..5492f9e272 100644 --- a/osu.Game/Rulesets/UI/ScrollingPlayfield.cs +++ b/osu.Game/Rulesets/UI/ScrollingPlayfield.cs @@ -7,10 +7,8 @@ using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Transforms; using osu.Framework.Input; -using osu.Framework.Lists; using osu.Framework.MathUtils; using osu.Game.Rulesets.Objects.Drawables; -using osu.Game.Rulesets.Timing; namespace osu.Game.Rulesets.UI { @@ -122,74 +120,5 @@ namespace osu.Game.Rulesets.UI protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time); protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value; } - - public class ScrollingHitObjectContainer : HitObjectContainer - { - public readonly BindableDouble TimeRange = new BindableDouble - { - MinValue = 0, - MaxValue = double.MaxValue - }; - - public readonly SortedList ControlPoints = new SortedList(); - - private readonly ScrollingDirection direction; - - public ScrollingHitObjectContainer(ScrollingDirection direction) - { - this.direction = direction; - - RelativeSizeAxes = Axes.Both; - } - - protected override void UpdateAfterChildren() - { - base.UpdateAfterChildren(); - - var currentMultiplier = controlPointAt(Time.Current); - - foreach (var obj in AliveObjects) - { - var relativePosition = (Time.Current - obj.HitObject.StartTime) / (TimeRange / currentMultiplier.Multiplier); - - // Todo: We may need to consider scale here - var finalPosition = (float)relativePosition * DrawSize; - - switch (direction) - { - case ScrollingDirection.Up: - obj.Y = -finalPosition.Y; - break; - case ScrollingDirection.Down: - obj.Y = finalPosition.Y; - break; - case ScrollingDirection.Left: - obj.X = -finalPosition.X; - break; - case ScrollingDirection.Right: - obj.X = finalPosition.X; - break; - } - } - } - - private readonly MultiplierControlPoint searchingPoint = new MultiplierControlPoint(); - private MultiplierControlPoint controlPointAt(double time) - { - if (ControlPoints.Count == 0) - return new MultiplierControlPoint(double.MinValue); - - if (time < ControlPoints[0].StartTime) - return ControlPoints[0]; - - searchingPoint.StartTime = time; - - int index = ControlPoints.BinarySearch(searchingPoint); - if (index < 0) - index = ~index - 1; - - return ControlPoints[index]; - } - } } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index c5c1004663..9cf7d72d1b 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -315,6 +315,7 @@ +