2018-01-04 18:20:43 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// 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;
|
2018-01-04 19:56:18 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
using osu.Game.Rulesets.Timing;
|
2018-01-04 19:56:18 +08:00
|
|
|
|
using OpenTK;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
2018-01-04 18:22:15 +08:00
|
|
|
|
namespace osu.Game.Rulesets.UI.Scrolling
|
2018-01-04 18:20:43 +08:00
|
|
|
|
{
|
|
|
|
|
public class ScrollingHitObjectContainer : Playfield.HitObjectContainer
|
|
|
|
|
{
|
|
|
|
|
public readonly BindableDouble TimeRange = new BindableDouble
|
|
|
|
|
{
|
|
|
|
|
MinValue = 0,
|
|
|
|
|
MaxValue = double.MaxValue
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public readonly SortedList<MultiplierControlPoint> ControlPoints = new SortedList<MultiplierControlPoint>();
|
|
|
|
|
|
|
|
|
|
private readonly ScrollingDirection direction;
|
|
|
|
|
|
|
|
|
|
public ScrollingHitObjectContainer(ScrollingDirection direction)
|
|
|
|
|
{
|
|
|
|
|
this.direction = direction;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-05 14:48:19 +08:00
|
|
|
|
protected override bool UpdateChildrenLife()
|
|
|
|
|
{
|
|
|
|
|
foreach (var obj in Objects)
|
|
|
|
|
{
|
|
|
|
|
obj.LifetimeStart = obj.HitObject.StartTime - TimeRange - 1000;
|
|
|
|
|
obj.LifetimeEnd = ((obj.HitObject as IHasEndTime)?.EndTime ?? obj.HitObject.StartTime + TimeRange) + 1000;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.UpdateChildrenLife();
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-04 20:45:29 +08:00
|
|
|
|
protected override void UpdateAfterChildrenLife()
|
2018-01-04 18:20:43 +08:00
|
|
|
|
{
|
2018-01-04 20:45:29 +08:00
|
|
|
|
base.UpdateAfterChildrenLife();
|
|
|
|
|
|
2018-01-05 14:48:19 +08:00
|
|
|
|
// We need to calculate this as soon as possible after lifetimes so that hitobjects
|
2018-01-04 20:45:29 +08:00
|
|
|
|
// get the final say in their positions
|
2018-01-04 18:20:43 +08:00
|
|
|
|
|
|
|
|
|
var currentMultiplier = controlPointAt(Time.Current);
|
|
|
|
|
|
|
|
|
|
foreach (var obj in AliveObjects)
|
|
|
|
|
{
|
|
|
|
|
// Todo: We may need to consider scale here
|
2018-01-04 19:56:18 +08:00
|
|
|
|
var relativePosition = (Time.Current - obj.HitObject.StartTime) * currentMultiplier.Multiplier / TimeRange;
|
2018-01-04 18:20:43 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
2018-01-04 19:56:18 +08:00
|
|
|
|
|
|
|
|
|
if (!(obj.HitObject is IHasEndTime endTime))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Todo: We may need to consider scale here
|
|
|
|
|
var relativeEndPosition = (Time.Current - endTime.EndTime) * currentMultiplier.Multiplier / TimeRange;
|
|
|
|
|
var finalEndPosition = (float)relativeEndPosition * DrawSize;
|
|
|
|
|
|
|
|
|
|
float length = Vector2.Distance(finalPosition, finalEndPosition);
|
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
|
case ScrollingDirection.Down:
|
|
|
|
|
obj.Height = length;
|
|
|
|
|
break;
|
|
|
|
|
case ScrollingDirection.Left:
|
|
|
|
|
case ScrollingDirection.Right:
|
|
|
|
|
obj.Width = length;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2018-01-04 18:20:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|