2017-08-07 09:03:44 +00: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 System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using OpenTK.Input;
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
using osu.Framework.Graphics;
|
2017-08-09 07:19:09 +00:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-08-07 09:03:44 +00:00
|
|
|
using osu.Framework.Graphics.Transforms;
|
|
|
|
using osu.Framework.Input;
|
|
|
|
using osu.Framework.MathUtils;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.UI
|
|
|
|
{
|
|
|
|
/// <summary>
|
2017-09-12 10:05:37 +00:00
|
|
|
/// A type of <see cref="Playfield"/> specialized towards scrolling <see cref="DrawableHitObject"/>s.
|
2017-08-07 09:03:44 +00:00
|
|
|
/// </summary>
|
2017-09-12 09:19:28 +00:00
|
|
|
public class ScrollingPlayfield : Playfield
|
2017-08-07 09:03:44 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The default span of time visible by the length of the scrolling axes.
|
|
|
|
/// This is clamped between <see cref="time_span_min"/> and <see cref="time_span_max"/>.
|
|
|
|
/// </summary>
|
|
|
|
private const double time_span_default = 1500;
|
|
|
|
/// <summary>
|
|
|
|
/// The minimum span of time that may be visible by the length of the scrolling axes.
|
|
|
|
/// </summary>
|
|
|
|
private const double time_span_min = 50;
|
|
|
|
/// <summary>
|
|
|
|
/// The maximum span of time that may be visible by the length of the scrolling axes.
|
|
|
|
/// </summary>
|
|
|
|
private const double time_span_max = 10000;
|
|
|
|
/// <summary>
|
|
|
|
/// The step increase/decrease of the span of time visible by the length of the scrolling axes.
|
|
|
|
/// </summary>
|
|
|
|
private const double time_span_step = 50;
|
|
|
|
|
|
|
|
/// <summary>
|
2017-08-08 03:59:50 +00:00
|
|
|
/// The span of time that is visible by the length of the scrolling axes.
|
2017-08-07 09:03:44 +00:00
|
|
|
/// For example, only hit objects with start time less than or equal to 1000 will be visible with <see cref="VisibleTimeRange"/> = 1000.
|
|
|
|
/// </summary>
|
2017-08-08 03:59:50 +00:00
|
|
|
public readonly BindableDouble VisibleTimeRange = new BindableDouble(time_span_default)
|
2017-08-07 09:03:44 +00:00
|
|
|
{
|
|
|
|
Default = time_span_default,
|
|
|
|
MinValue = time_span_min,
|
|
|
|
MaxValue = time_span_max
|
|
|
|
};
|
|
|
|
|
|
|
|
/// <summary>
|
2017-08-23 11:50:03 +00:00
|
|
|
/// Whether to reverse the scrolling direction is reversed. Note that this does _not_ invert the hit objects.
|
2017-08-07 09:03:44 +00:00
|
|
|
/// </summary>
|
2017-08-23 11:50:03 +00:00
|
|
|
protected readonly BindableBool Reversed = new BindableBool();
|
2017-08-07 09:03:44 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The container that contains the <see cref="SpeedAdjustmentContainer"/>s and <see cref="DrawableHitObject"/>s.
|
|
|
|
/// </summary>
|
2017-08-22 07:05:12 +00:00
|
|
|
public new readonly ScrollingHitObjectContainer HitObjects;
|
2017-08-07 09:03:44 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2017-09-12 10:05:37 +00:00
|
|
|
/// Creates a new <see cref="ScrollingPlayfield"/>.
|
2017-08-07 09:03:44 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="scrollingAxes">The axes on which <see cref="DrawableHitObject"/>s in this container should scroll.</param>
|
|
|
|
/// <param name="customWidth">Whether we want our internal coordinate system to be scaled to a specified width</param>
|
|
|
|
protected ScrollingPlayfield(Axes scrollingAxes, float? customWidth = null)
|
|
|
|
: base(customWidth)
|
|
|
|
{
|
2017-08-09 05:10:10 +00:00
|
|
|
base.HitObjects = HitObjects = new ScrollingHitObjectContainer(scrollingAxes) { RelativeSizeAxes = Axes.Both };
|
|
|
|
HitObjects.VisibleTimeRange.BindTo(VisibleTimeRange);
|
|
|
|
HitObjects.Reversed.BindTo(Reversed);
|
2017-08-07 09:03:44 +00:00
|
|
|
}
|
|
|
|
|
2017-09-12 09:19:28 +00:00
|
|
|
private List<ScrollingPlayfield> nestedPlayfields;
|
2017-08-07 09:03:44 +00:00
|
|
|
/// <summary>
|
2017-09-12 10:05:37 +00:00
|
|
|
/// All the <see cref="ScrollingPlayfield"/>s nested inside this playfield.
|
2017-08-07 09:03:44 +00:00
|
|
|
/// </summary>
|
2017-09-12 09:19:28 +00:00
|
|
|
public IEnumerable<ScrollingPlayfield> NestedPlayfields => nestedPlayfields;
|
2017-08-07 09:03:44 +00:00
|
|
|
|
|
|
|
/// <summary>
|
2017-09-12 10:05:37 +00:00
|
|
|
/// Adds a <see cref="ScrollingPlayfield"/> to this playfield. The nested <see cref="ScrollingPlayfield"/>
|
2017-08-07 09:03:44 +00:00
|
|
|
/// will be given all of the same speed adjustments as this playfield.
|
|
|
|
/// </summary>
|
2017-09-12 10:05:37 +00:00
|
|
|
/// <param name="otherPlayfield">The <see cref="ScrollingPlayfield"/> to add.</param>
|
2017-09-12 09:19:28 +00:00
|
|
|
protected void AddNested(ScrollingPlayfield otherPlayfield)
|
2017-08-07 09:03:44 +00:00
|
|
|
{
|
|
|
|
if (nestedPlayfields == null)
|
2017-09-12 09:19:28 +00:00
|
|
|
nestedPlayfields = new List<ScrollingPlayfield>();
|
2017-08-07 09:03:44 +00:00
|
|
|
|
|
|
|
nestedPlayfields.Add(otherPlayfield);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
|
|
|
{
|
|
|
|
if (state.Keyboard.ControlPressed)
|
|
|
|
{
|
|
|
|
switch (args.Key)
|
|
|
|
{
|
|
|
|
case Key.Minus:
|
|
|
|
transformVisibleTimeRangeTo(VisibleTimeRange + time_span_step, 200, Easing.OutQuint);
|
|
|
|
break;
|
|
|
|
case Key.Plus:
|
|
|
|
transformVisibleTimeRangeTo(VisibleTimeRange - time_span_step, 200, Easing.OutQuint);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void transformVisibleTimeRangeTo(double newTimeRange, double duration = 0, Easing easing = Easing.None)
|
|
|
|
{
|
|
|
|
this.TransformTo(this.PopulateTransform(new TransformVisibleTimeRange(), newTimeRange, duration, easing));
|
|
|
|
}
|
|
|
|
|
2017-09-12 09:19:28 +00:00
|
|
|
private class TransformVisibleTimeRange : Transform<double, ScrollingPlayfield>
|
2017-08-07 09:03:44 +00:00
|
|
|
{
|
|
|
|
private double valueAt(double time)
|
|
|
|
{
|
|
|
|
if (time < StartTime) return StartValue;
|
|
|
|
if (time >= EndTime) return EndValue;
|
|
|
|
|
|
|
|
return Interpolation.ValueAt(time, StartValue, EndValue, StartTime, EndTime, Easing);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override string TargetMember => "VisibleTimeRange.Value";
|
|
|
|
|
2017-09-12 09:19:28 +00:00
|
|
|
protected override void Apply(ScrollingPlayfield d, double time) => d.VisibleTimeRange.Value = valueAt(time);
|
|
|
|
protected override void ReadIntoStartValue(ScrollingPlayfield d) => StartValue = d.VisibleTimeRange.Value;
|
2017-08-07 09:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A container that provides the foundation for sorting <see cref="DrawableHitObject"/>s into <see cref="SpeedAdjustmentContainer"/>s.
|
|
|
|
/// </summary>
|
2017-08-22 07:05:12 +00:00
|
|
|
public class ScrollingHitObjectContainer : HitObjectContainer
|
2017-08-07 09:03:44 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets the range of time that is visible by the length of the scrolling axes.
|
|
|
|
/// For example, only hit objects with start time less than or equal to 1000 will be visible with <see cref="VisibleTimeRange"/> = 1000.
|
|
|
|
/// </summary>
|
2017-08-09 05:10:10 +00:00
|
|
|
public readonly BindableDouble VisibleTimeRange = new BindableDouble { Default = 1000 };
|
2017-08-07 09:03:44 +00:00
|
|
|
|
2017-08-08 03:59:50 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Whether to reverse the scrolling direction is reversed.
|
|
|
|
/// </summary>
|
2017-08-09 05:10:10 +00:00
|
|
|
public readonly BindableBool Reversed = new BindableBool();
|
2017-08-08 03:59:50 +00:00
|
|
|
|
2017-08-22 09:36:32 +00:00
|
|
|
private readonly SortedContainer speedAdjustments;
|
2017-08-22 07:05:12 +00:00
|
|
|
public IReadOnlyList<SpeedAdjustmentContainer> SpeedAdjustments => speedAdjustments;
|
2017-08-07 09:03:44 +00:00
|
|
|
|
2017-08-22 07:15:40 +00:00
|
|
|
private readonly SpeedAdjustmentContainer defaultSpeedAdjustment;
|
|
|
|
|
2017-08-07 09:03:44 +00:00
|
|
|
private readonly Axes scrollingAxes;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new <see cref="ScrollingHitObjectContainer"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="scrollingAxes">The axes upon which hit objects should appear to scroll inside this container.</param>
|
|
|
|
public ScrollingHitObjectContainer(Axes scrollingAxes)
|
|
|
|
{
|
|
|
|
this.scrollingAxes = scrollingAxes;
|
2017-08-09 07:19:09 +00:00
|
|
|
|
2017-08-22 09:36:32 +00:00
|
|
|
AddInternal(speedAdjustments = new SortedContainer { RelativeSizeAxes = Axes.Both });
|
2017-08-21 07:14:44 +00:00
|
|
|
|
|
|
|
// Default speed adjustment
|
2017-08-22 07:15:40 +00:00
|
|
|
AddSpeedAdjustment(defaultSpeedAdjustment = new SpeedAdjustmentContainer(new MultiplierControlPoint(0)));
|
2017-08-07 09:03:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
2017-08-22 12:08:27 +00:00
|
|
|
/// Adds a <see cref="SpeedAdjustmentContainer"/> to this container, re-sorting all hit objects
|
|
|
|
/// in the last <see cref="SpeedAdjustmentContainer"/> that occurred (time-wise) before it.
|
2017-08-07 09:03:44 +00:00
|
|
|
/// </summary>
|
|
|
|
/// <param name="speedAdjustment">The <see cref="SpeedAdjustmentContainer"/>.</param>
|
|
|
|
public void AddSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment)
|
|
|
|
{
|
|
|
|
speedAdjustment.ScrollingAxes = scrollingAxes;
|
2017-08-09 05:10:10 +00:00
|
|
|
speedAdjustment.VisibleTimeRange.BindTo(VisibleTimeRange);
|
|
|
|
speedAdjustment.Reversed.BindTo(Reversed);
|
2017-08-21 07:14:44 +00:00
|
|
|
|
2017-08-22 09:36:56 +00:00
|
|
|
if (speedAdjustments.Count > 0)
|
2017-08-21 07:14:44 +00:00
|
|
|
{
|
2017-08-22 12:08:27 +00:00
|
|
|
// We need to re-sort all hit objects in the speed adjustment container prior to figure out if they
|
|
|
|
// should now lie within this one
|
2017-08-22 09:36:56 +00:00
|
|
|
var existingAdjustment = adjustmentContainerAt(speedAdjustment.ControlPoint.StartTime);
|
|
|
|
for (int i = 0; i < existingAdjustment.Count; i++)
|
|
|
|
{
|
|
|
|
DrawableHitObject hitObject = existingAdjustment[i];
|
2017-08-22 07:00:26 +00:00
|
|
|
|
2017-08-22 09:36:56 +00:00
|
|
|
if (!speedAdjustment.CanContain(hitObject.HitObject.StartTime))
|
|
|
|
continue;
|
2017-08-21 07:14:44 +00:00
|
|
|
|
2017-08-22 09:36:56 +00:00
|
|
|
existingAdjustment.Remove(hitObject);
|
|
|
|
speedAdjustment.Add(hitObject);
|
2017-08-22 07:00:26 +00:00
|
|
|
|
2017-08-22 09:36:56 +00:00
|
|
|
i--;
|
|
|
|
}
|
2017-08-21 07:14:44 +00:00
|
|
|
}
|
2017-08-22 09:36:56 +00:00
|
|
|
|
|
|
|
speedAdjustments.Add(speedAdjustment);
|
2017-08-07 09:03:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-22 07:01:19 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Removes a <see cref="SpeedAdjustmentContainer"/> from this container, re-sorting all hit objects
|
|
|
|
/// which it contained into new <see cref="SpeedAdjustmentContainer"/>s.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="speedAdjustment">The <see cref="SpeedAdjustmentContainer"/> to remove.</param>
|
|
|
|
public void RemoveSpeedAdjustment(SpeedAdjustmentContainer speedAdjustment)
|
|
|
|
{
|
2017-08-22 07:15:40 +00:00
|
|
|
if (speedAdjustment == defaultSpeedAdjustment)
|
|
|
|
throw new InvalidOperationException($"The default {nameof(SpeedAdjustmentContainer)} must not be removed.");
|
|
|
|
|
2017-08-22 07:01:19 +00:00
|
|
|
if (!speedAdjustments.Remove(speedAdjustment))
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (speedAdjustment.Count > 0)
|
|
|
|
{
|
|
|
|
DrawableHitObject hitObject = speedAdjustment[0];
|
|
|
|
|
|
|
|
speedAdjustment.Remove(hitObject);
|
|
|
|
Add(hitObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 08:37:11 +00:00
|
|
|
public override IEnumerable<DrawableHitObject> Objects => speedAdjustments.SelectMany(s => s.Children);
|
|
|
|
|
2017-08-07 09:03:44 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adds a hit object to this <see cref="ScrollingHitObjectContainer"/>. The hit objects will be queued to be processed
|
|
|
|
/// new <see cref="SpeedAdjustmentContainer"/>s are added to this <see cref="ScrollingHitObjectContainer"/>.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="hitObject">The hit object to add.</param>
|
2017-08-08 08:37:11 +00:00
|
|
|
public override void Add(DrawableHitObject hitObject)
|
2017-08-07 09:03:44 +00:00
|
|
|
{
|
|
|
|
if (!(hitObject is IScrollingHitObject))
|
|
|
|
throw new InvalidOperationException($"Hit objects added to a {nameof(ScrollingHitObjectContainer)} must implement {nameof(IScrollingHitObject)}.");
|
|
|
|
|
2017-08-22 09:36:56 +00:00
|
|
|
adjustmentContainerAt(hitObject.HitObject.StartTime).Add(hitObject);
|
2017-08-07 09:03:44 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 07:14:44 +00:00
|
|
|
public override bool Remove(DrawableHitObject hitObject) => speedAdjustments.Any(s => s.Remove(hitObject));
|
|
|
|
|
2017-08-07 09:03:44 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Finds the <see cref="SpeedAdjustmentContainer"/> which provides the speed adjustment active at a time.
|
|
|
|
/// If there is no <see cref="SpeedAdjustmentContainer"/> active at the time, then the first (time-wise) speed adjustment is returned.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="time">The time to find the active <see cref="SpeedAdjustmentContainer"/> at.</param>
|
|
|
|
/// <returns>The <see cref="SpeedAdjustmentContainer"/> active at <paramref name="time"/>. Null if there are no speed adjustments.</returns>
|
2017-08-22 09:39:09 +00:00
|
|
|
private SpeedAdjustmentContainer adjustmentContainerAt(double time) => speedAdjustments.FirstOrDefault(c => c.CanContain(time)) ?? defaultSpeedAdjustment;
|
2017-08-22 09:36:32 +00:00
|
|
|
|
|
|
|
private class SortedContainer : Container<SpeedAdjustmentContainer>
|
|
|
|
{
|
|
|
|
protected override int Compare(Drawable x, Drawable y)
|
|
|
|
{
|
|
|
|
var sX = (SpeedAdjustmentContainer)x;
|
|
|
|
var sY = (SpeedAdjustmentContainer)y;
|
|
|
|
|
|
|
|
int result = sY.ControlPoint.StartTime.CompareTo(sX.ControlPoint.StartTime);
|
|
|
|
if (result != 0)
|
|
|
|
return result;
|
2017-08-22 09:54:41 +00:00
|
|
|
return base.Compare(y, x);
|
2017-08-22 09:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-07 09:03:44 +00:00
|
|
|
}
|
|
|
|
}
|
2017-08-21 07:14:44 +00:00
|
|
|
}
|