2017-06-09 15:11:31 +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
|
|
|
|
|
2017-06-09 15:20:55 +08:00
|
|
|
using osu.Framework.Configuration;
|
2017-06-09 15:11:31 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using OpenTK;
|
|
|
|
|
2017-06-09 15:20:55 +08:00
|
|
|
namespace osu.Game.Rulesets.Timing
|
2017-06-09 15:11:31 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// A container that provides the speed adjustments defined by <see cref="MultiplierControlPoint"/>s to affect the scroll speed
|
|
|
|
/// of container <see cref="DrawableHitObject"/>s.
|
2017-06-09 15:11:31 +08:00
|
|
|
/// </summary>
|
2017-08-04 19:22:53 +08:00
|
|
|
public class SpeedAdjustmentContainer : Container<DrawableHitObject>
|
2017-06-09 15:11:31 +08:00
|
|
|
{
|
2017-06-12 14:20:34 +08:00
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// Gets or sets the range of time that is visible by the length of the scrolling axes.
|
2017-06-12 14:20:34 +08:00
|
|
|
/// </summary>
|
2017-08-09 13:10:10 +08:00
|
|
|
public readonly Bindable<double> VisibleTimeRange = new Bindable<double> { Default = 1000 };
|
2017-06-09 15:11:31 +08:00
|
|
|
|
2017-08-08 11:59:50 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether to reverse the scrolling direction is reversed.
|
|
|
|
/// </summary>
|
2017-08-09 13:10:10 +08:00
|
|
|
public readonly BindableBool Reversed = new BindableBool();
|
2017-08-08 11:59:50 +08:00
|
|
|
|
2017-06-09 15:11:31 +08:00
|
|
|
protected override Container<DrawableHitObject> Content => content;
|
2017-08-22 15:05:19 +08:00
|
|
|
private readonly Container<DrawableHitObject> content;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
2017-06-16 12:00:08 +08:00
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// The axes which the content of this container will scroll through.
|
2017-06-16 12:00:08 +08:00
|
|
|
/// </summary>
|
2017-08-22 17:37:49 +08:00
|
|
|
public Axes ScrollingAxes
|
|
|
|
{
|
|
|
|
get { return scrollingContainer.ScrollingAxes; }
|
|
|
|
set { scrollingContainer.ScrollingAxes = value; }
|
|
|
|
}
|
2017-06-16 12:00:08 +08:00
|
|
|
|
2017-08-09 15:19:09 +08:00
|
|
|
public override bool RemoveWhenNotAlive => false;
|
2017-09-13 14:56:49 +08:00
|
|
|
protected override bool RequiresChildrenUpdate => true;
|
2017-08-09 15:19:09 +08:00
|
|
|
|
2017-08-07 16:25:40 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="MultiplierControlPoint"/> that defines the speed adjustments.
|
|
|
|
/// </summary>
|
2017-06-16 12:00:08 +08:00
|
|
|
public readonly MultiplierControlPoint ControlPoint;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
2017-08-22 15:05:19 +08:00
|
|
|
private readonly ScrollingContainer scrollingContainer;
|
2017-06-16 18:21:54 +08:00
|
|
|
|
2017-06-09 15:11:31 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="SpeedAdjustmentContainer"/>.
|
|
|
|
/// </summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// <param name="controlPoint">The <see cref="MultiplierControlPoint"/> that defines the speed adjustments.</param>
|
2017-08-07 14:22:31 +08:00
|
|
|
public SpeedAdjustmentContainer(MultiplierControlPoint controlPoint)
|
2017-06-09 15:11:31 +08:00
|
|
|
{
|
2017-06-16 12:09:06 +08:00
|
|
|
ControlPoint = controlPoint;
|
2017-06-12 14:20:34 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
2017-08-04 19:22:53 +08:00
|
|
|
scrollingContainer = CreateScrollingContainer();
|
|
|
|
scrollingContainer.ControlPoint = ControlPoint;
|
|
|
|
scrollingContainer.VisibleTimeRange.BindTo(VisibleTimeRange);
|
2017-06-09 15:11:31 +08:00
|
|
|
|
2017-08-04 19:22:53 +08:00
|
|
|
AddInternal(content = scrollingContainer);
|
2017-06-09 15:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
2017-06-12 16:31:24 +08:00
|
|
|
float multiplier = (float)ControlPoint.Multiplier;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
2017-06-09 15:57:17 +08:00
|
|
|
// The speed adjustment happens by modifying our size by the multiplier while maintaining the visible time range as the relatve size for our children
|
2017-06-15 13:48:02 +08:00
|
|
|
Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? multiplier : 1, (ScrollingAxes & Axes.Y) > 0 ? multiplier : 1);
|
2017-08-08 11:59:50 +08:00
|
|
|
|
|
|
|
if (Reversed)
|
|
|
|
{
|
|
|
|
RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)-VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)-VisibleTimeRange : 1);
|
|
|
|
RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 0);
|
2017-08-09 13:50:52 +08:00
|
|
|
Origin = Anchor = Anchor.BottomRight;
|
2017-08-08 11:59:50 +08:00
|
|
|
}
|
|
|
|
else
|
2017-08-08 12:23:46 +08:00
|
|
|
{
|
2017-08-08 11:59:50 +08:00
|
|
|
RelativeChildSize = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (ScrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1);
|
2017-08-08 12:23:46 +08:00
|
|
|
RelativeChildOffset = Vector2.Zero;
|
2017-08-09 13:24:07 +08:00
|
|
|
Origin = Anchor = Anchor.TopLeft;
|
2017-08-08 12:23:46 +08:00
|
|
|
}
|
2017-06-09 15:11:31 +08:00
|
|
|
}
|
|
|
|
|
2017-06-16 18:21:54 +08:00
|
|
|
public override double LifetimeStart => ControlPoint.StartTime - VisibleTimeRange;
|
2017-08-04 19:22:53 +08:00
|
|
|
public override double LifetimeEnd => ControlPoint.StartTime + scrollingContainer.Duration + VisibleTimeRange;
|
2017-06-16 18:21:54 +08:00
|
|
|
|
|
|
|
public override void Add(DrawableHitObject drawable)
|
|
|
|
{
|
2017-06-19 09:54:23 +08:00
|
|
|
var scrollingHitObject = drawable as IScrollingHitObject;
|
2017-08-07 15:02:38 +08:00
|
|
|
|
|
|
|
if (scrollingHitObject != null)
|
|
|
|
{
|
|
|
|
scrollingHitObject.LifetimeOffset.BindTo(VisibleTimeRange);
|
|
|
|
scrollingHitObject.ScrollingAxes = ScrollingAxes;
|
|
|
|
}
|
2017-06-19 09:54:23 +08:00
|
|
|
|
2017-06-16 18:21:54 +08:00
|
|
|
base.Add(drawable);
|
|
|
|
}
|
|
|
|
|
2017-06-16 08:38:06 +08:00
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// Whether a point in time falls within this <see cref="SpeedAdjustmentContainer"/>s affecting timespan.
|
2017-06-16 08:38:06 +08:00
|
|
|
/// </summary>
|
|
|
|
public bool CanContain(double startTime) => ControlPoint.StartTime <= startTime;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
/// Creates the <see cref="ScrollingContainer"/> which contains the scrolling <see cref="DrawableHitObject"/>s of this container.
|
2017-06-09 15:11:31 +08:00
|
|
|
/// </summary>
|
2017-08-04 19:22:53 +08:00
|
|
|
/// <returns>The <see cref="ScrollingContainer"/>.</returns>
|
2017-08-22 17:37:49 +08:00
|
|
|
protected virtual ScrollingContainer CreateScrollingContainer() => new LinearScrollingContainer(ControlPoint);
|
2017-06-09 15:11:31 +08:00
|
|
|
}
|
2017-08-22 17:37:49 +08:00
|
|
|
}
|