2017-06-09 15:11:31 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
2017-06-02 17:20:14 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-08-22 19:51:53 +08:00
|
|
|
|
using System;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Caching;
|
2017-06-09 18:57:03 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2017-06-01 13:26:21 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2017-06-02 18:53:30 +08:00
|
|
|
|
using OpenTK;
|
2017-06-16 18:21:54 +08:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
2017-06-01 13:26:21 +08:00
|
|
|
|
|
2017-06-09 18:57:03 +08:00
|
|
|
|
namespace osu.Game.Rulesets.Timing
|
2017-06-01 13:26:21 +08:00
|
|
|
|
{
|
2017-06-02 18:27:00 +08:00
|
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
|
/// A container that scrolls relative to the current time. Will autosize to the total duration of all contained hit objects along the scrolling axes.
|
2017-06-02 18:27:00 +08:00
|
|
|
|
/// </summary>
|
2017-08-04 19:22:53 +08:00
|
|
|
|
public abstract class ScrollingContainer : Container<DrawableHitObject>
|
2017-06-01 13:26:21 +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:25:49 +08:00
|
|
|
|
public readonly BindableDouble VisibleTimeRange = new BindableDouble { Default = 1000 };
|
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 through which this <see cref="ScrollingContainer"/> scrolls. This is set by the <see cref="SpeedAdjustmentContainer"/>.
|
2017-06-16 12:00:08 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
internal Axes ScrollingAxes;
|
2017-06-01 13:26:21 +08:00
|
|
|
|
|
2017-08-09 15:19:09 +08:00
|
|
|
|
public override bool RemoveWhenNotAlive => false;
|
|
|
|
|
|
2017-06-16 18:21:54 +08:00
|
|
|
|
/// <summary>
|
2017-08-07 16:25:40 +08:00
|
|
|
|
/// The control point that defines the speed adjustments for this container. This is set by the <see cref="SpeedAdjustmentContainer"/>.
|
2017-06-16 18:21:54 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
internal MultiplierControlPoint ControlPoint;
|
|
|
|
|
|
2017-08-22 19:51:53 +08:00
|
|
|
|
private Cached<double> durationBacking = new Cached<double>();
|
2017-08-07 15:02:38 +08:00
|
|
|
|
|
2017-06-02 18:27:00 +08:00
|
|
|
|
/// <summary>
|
2017-08-04 19:22:53 +08:00
|
|
|
|
/// Creates a new <see cref="ScrollingContainer"/>.
|
2017-06-02 18:27:00 +08:00
|
|
|
|
/// </summary>
|
2017-08-04 19:22:53 +08:00
|
|
|
|
protected ScrollingContainer()
|
2017-06-01 13:26:21 +08:00
|
|
|
|
{
|
2017-06-12 14:20:34 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2017-06-12 12:09:02 +08:00
|
|
|
|
RelativePositionAxes = Axes.Both;
|
2017-06-02 17:11:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 19:51:20 +08:00
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
2017-06-09 15:11:31 +08:00
|
|
|
|
{
|
2017-08-22 19:51:20 +08:00
|
|
|
|
var hX = (DrawableHitObject)x;
|
|
|
|
|
var hY = (DrawableHitObject)y;
|
2017-06-02 17:11:36 +08:00
|
|
|
|
|
2017-08-22 19:51:20 +08:00
|
|
|
|
int result = hY.HitObject.StartTime.CompareTo(hX.HitObject.StartTime);
|
|
|
|
|
if (result != 0)
|
|
|
|
|
return result;
|
|
|
|
|
return base.Compare(y, x);
|
2017-06-01 13:26:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 19:51:53 +08:00
|
|
|
|
public override void Add(DrawableHitObject drawable)
|
2017-06-09 15:11:31 +08:00
|
|
|
|
{
|
2017-08-22 19:51:53 +08:00
|
|
|
|
durationBacking.Invalidate();
|
|
|
|
|
base.Add(drawable);
|
|
|
|
|
}
|
2017-06-16 18:21:54 +08:00
|
|
|
|
|
2017-08-22 19:51:53 +08:00
|
|
|
|
public override bool Remove(DrawableHitObject drawable)
|
|
|
|
|
{
|
|
|
|
|
durationBacking.Invalidate();
|
|
|
|
|
return base.Remove(drawable);
|
2017-07-02 18:00:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-22 19:51:53 +08:00
|
|
|
|
// Todo: This may underestimate the size of the hit object in some cases, but won't be too much of a problem for now
|
|
|
|
|
private double computeDuration() => Math.Max(0, Children.Select(c => (c.HitObject as IHasEndTime)?.EndTime ?? c.HitObject.StartTime).DefaultIfEmpty().Max() - ControlPoint.StartTime) + 1000;
|
|
|
|
|
|
2017-07-02 18:00:02 +08:00
|
|
|
|
/// <summary>
|
2017-08-22 19:51:53 +08:00
|
|
|
|
/// An approximate total duration of this scrolling container.
|
2017-07-02 18:00:02 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public double Duration => durationBacking.IsValid ? durationBacking : (durationBacking.Value = computeDuration());
|
2017-06-16 18:21:54 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2017-08-22 17:37:49 +08:00
|
|
|
|
RelativeChildOffset = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)ControlPoint.StartTime : 0, (ScrollingAxes & Axes.Y) > 0 ? (float)ControlPoint.StartTime : 0);
|
|
|
|
|
|
2017-08-07 16:25:40 +08:00
|
|
|
|
// We want our size and position-space along the scrolling axes to span our duration to completely enclose all the hit objects
|
2017-06-16 18:21:54 +08:00
|
|
|
|
Size = new Vector2((ScrollingAxes & Axes.X) > 0 ? (float)Duration : Size.X, (ScrollingAxes & Axes.Y) > 0 ? (float)Duration : Size.Y);
|
2017-06-16 18:47:15 +08:00
|
|
|
|
// And we need to make sure the hit object's position-space doesn't change due to our resizing
|
2017-06-16 18:21:54 +08:00
|
|
|
|
RelativeChildSize = Size;
|
2017-06-09 15:11:31 +08:00
|
|
|
|
}
|
2017-06-01 13:26:21 +08:00
|
|
|
|
}
|
2017-06-09 15:11:31 +08:00
|
|
|
|
}
|