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
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
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-06-12 14:20:34 +08:00
|
|
|
/// A container for hit objects which applies applies the speed adjustments defined by the properties of a <see cref="Timing.MultiplierControlPoint"/>
|
|
|
|
/// to affect the scroll speed of the contained <see cref="DrawableTimingSection"/>.
|
|
|
|
///
|
|
|
|
/// <para>
|
|
|
|
/// This container must always be relatively-sized to its parent to provide the speed adjustments. This container will provide the speed adjustments
|
|
|
|
/// by modifying its size while maintaining a constant <see cref="Container{T}.RelativeChildSize"/> for its children
|
|
|
|
/// </para>
|
2017-06-09 15:11:31 +08:00
|
|
|
/// </summary>
|
|
|
|
public abstract class SpeedAdjustmentContainer : Container<DrawableHitObject>
|
|
|
|
{
|
|
|
|
private readonly Bindable<double> visibleTimeRange = new Bindable<double>();
|
2017-06-12 14:20:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the range of time that is visible by the length of this container.
|
|
|
|
/// </summary>
|
2017-06-09 15:11:31 +08:00
|
|
|
public Bindable<double> VisibleTimeRange
|
|
|
|
{
|
|
|
|
get { return visibleTimeRange; }
|
|
|
|
set { visibleTimeRange.BindTo(value); }
|
|
|
|
}
|
|
|
|
|
2017-06-12 14:20:34 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The <see cref="MultiplierControlPoint"/> which provides the speed adjustments for this container.
|
|
|
|
/// </summary>
|
2017-06-12 16:31:24 +08:00
|
|
|
public readonly MultiplierControlPoint ControlPoint;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
|
|
|
protected override Container<DrawableHitObject> Content => content;
|
|
|
|
private Container<DrawableHitObject> content;
|
|
|
|
|
|
|
|
private readonly Axes scrollingAxes;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="SpeedAdjustmentContainer"/>.
|
|
|
|
/// </summary>
|
2017-06-12 16:31:24 +08:00
|
|
|
/// <param name="controlPoint">The <see cref="MultiplierControlPoint"/> which provides the speed adjustments for this container.</param>
|
2017-06-12 14:20:34 +08:00
|
|
|
/// <param name="scrollingAxes">The axes through which the content of this container should scroll through.</param>
|
2017-06-12 16:31:24 +08:00
|
|
|
protected SpeedAdjustmentContainer(MultiplierControlPoint controlPoint, Axes scrollingAxes)
|
2017-06-09 15:11:31 +08:00
|
|
|
{
|
|
|
|
this.scrollingAxes = scrollingAxes;
|
|
|
|
|
2017-06-12 14:20:34 +08:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
2017-06-12 16:31:24 +08:00
|
|
|
ControlPoint = controlPoint;
|
2017-06-09 15:11:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
DrawableTimingSection timingSection = CreateTimingSection();
|
|
|
|
|
|
|
|
timingSection.VisibleTimeRange.BindTo(VisibleTimeRange);
|
2017-06-12 16:31:24 +08:00
|
|
|
timingSection.RelativeChildOffset = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (scrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0);
|
2017-06-09 15:11:31 +08:00
|
|
|
|
|
|
|
AddInternal(content = timingSection);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
Size = new Vector2((scrollingAxes & Axes.X) > 0 ? multiplier : 1, (scrollingAxes & Axes.Y) > 0 ? multiplier : 1);
|
2017-06-09 15:11:31 +08:00
|
|
|
RelativeChildSize = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)VisibleTimeRange : 1, (scrollingAxes & Axes.Y) > 0 ? (float)VisibleTimeRange : 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 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.
|
|
|
|
/// </summary>
|
2017-06-12 16:31:24 +08:00
|
|
|
public bool CanContain(DrawableHitObject hitObject) => ControlPoint.StartTime <= hitObject.HitObject.StartTime;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates the container which handles the movement of a collection of hit objects.
|
|
|
|
/// </summary>
|
2017-06-12 14:20:34 +08:00
|
|
|
/// <returns>The <see cref="DrawableTimingSection"/>.</returns>
|
2017-06-09 15:11:31 +08:00
|
|
|
protected abstract DrawableTimingSection CreateTimingSection();
|
|
|
|
}
|
|
|
|
}
|