1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 15:22:55 +08:00
This commit is contained in:
smoogipooo 2017-05-16 18:17:34 +09:00
parent 60666dc824
commit 620b4bf863

View File

@ -12,7 +12,7 @@ using osu.Game.Beatmaps.Timing;
namespace osu.Game.Rulesets.Mania.Timing namespace osu.Game.Rulesets.Mania.Timing
{ {
/// <summary> /// <summary>
/// A container in which the Y-relative coordinate space is spanned by a length of time. /// A container in which added drawables are put into a relative coordinate space spanned by a length of time.
/// <para> /// <para>
/// This container contains <see cref="ControlPoint"/>s which scroll inside this container. /// This container contains <see cref="ControlPoint"/>s which scroll inside this container.
/// Drawables added to this container are moved inside the relevant <see cref="ControlPoint"/>, /// Drawables added to this container are moved inside the relevant <see cref="ControlPoint"/>,
@ -22,39 +22,38 @@ namespace osu.Game.Rulesets.Mania.Timing
public class ControlPointContainer : Container<Drawable> public class ControlPointContainer : Container<Drawable>
{ {
/// <summary> /// <summary>
/// The amount of time which the height of this container spans. /// The amount of time which this container spans.
/// </summary> /// </summary>
public double TimeSpan { get; set; } public double TimeSpan { get; set; }
private readonly List<DrawableTimingSection> drawableTimingSections; private readonly List<DrawableControlPoint> drawableControlPoints;
public ControlPointContainer(IEnumerable<ControlPoint> timingChanges) public ControlPointContainer(IEnumerable<ControlPoint> timingChanges)
{ {
drawableTimingSections = timingChanges.Select(t => new DrawableTimingSection(t)).ToList(); drawableControlPoints = timingChanges.Select(t => new DrawableControlPoint(t)).ToList();
Children = drawableControlPoints;
Children = drawableTimingSections;
} }
/// <summary> /// <summary>
/// Adds a drawable to this container. Note that the drawable added must have a /// Adds a drawable to this container. Note that the drawable added must have its Y-position be
/// Y-position as a time relative to this container. /// an absolute unit of time that is _not_ relative to <see cref="TimeSpan"/>.
/// </summary> /// </summary>
/// <param name="drawable">The drawable to add.</param> /// <param name="drawable">The drawable to add.</param>
public override void Add(Drawable drawable) public override void Add(Drawable drawable)
{ {
// Always add timing sections to ourselves // Always add timing sections to ourselves
if (drawable is DrawableTimingSection) if (drawable is DrawableControlPoint)
{ {
base.Add(drawable); base.Add(drawable);
return; return;
} }
var section = drawableTimingSections.LastOrDefault(t => t.CanContain(drawable)) ?? drawableTimingSections.FirstOrDefault(); var controlPoint = drawableControlPoints.LastOrDefault(t => t.CanContain(drawable)) ?? drawableControlPoints.FirstOrDefault();
if (section == null) if (controlPoint == null)
throw new Exception("Could not find suitable timing section to add object to."); throw new Exception("Could not find suitable timing section to add object to.");
section.Add(drawable); controlPoint.Add(drawable);
} }
/// <summary> /// <summary>
@ -63,7 +62,7 @@ namespace osu.Game.Rulesets.Mania.Timing
/// The content of this container will scroll relative to the current time. /// The content of this container will scroll relative to the current time.
/// </para> /// </para>
/// </summary> /// </summary>
private class DrawableTimingSection : Container private class DrawableControlPoint : Container
{ {
private readonly ControlPoint timingChange; private readonly ControlPoint timingChange;
@ -71,15 +70,13 @@ namespace osu.Game.Rulesets.Mania.Timing
private readonly Container content; private readonly Container content;
/// <summary> /// <summary>
/// Creates a drawable timing section. The height of this container will be proportional /// Creates a drawable control point. The height of this container will be proportional
/// to the beat length of the timing section and the timespan of its parent at all times. /// to the beat length of the control point it is initialized with such that, e.g. a beat length
/// <para> /// of 500ms results in this container being twice as high as its parent, which further means that
/// This is so that, e.g. a beat length of 500ms results in this container being twice as high as its parent, /// the content container will scroll at twice the normal rate.
/// which means that the content container will scroll at twice the normal rate.
/// </para>
/// </summary> /// </summary>
/// <param name="timingChange">The timing change to create the drawable timing section for.</param> /// <param name="timingChange">The control point to create the drawable control point for.</param>
public DrawableTimingSection(ControlPoint timingChange) public DrawableControlPoint(ControlPoint timingChange)
{ {
this.timingChange = timingChange; this.timingChange = timingChange;
@ -107,9 +104,9 @@ namespace osu.Game.Rulesets.Mania.Timing
public override void Add(Drawable drawable) public override void Add(Drawable drawable)
{ {
// The previously relatively-positioned drawable will now become relative to us, but since the drawable has no knowledge of us, // The previously relatively-positioned drawable will now become relative to content, but since the drawable has no knowledge of content,
// we need to offset it back by our position so that it becomes correctly relatively-positioned to us // we need to offset it back by content's position position so that it becomes correctly relatively-positioned to content
// This can be removed if hit objects were stored such that either their StartTime or their "beat offset" was relative to the timing section // This can be removed if hit objects were stored such that either their StartTime or their "beat offset" was relative to the timing change
// they belonged to, but this requires a radical change to the beatmap format which we're not ready to do just yet // they belonged to, but this requires a radical change to the beatmap format which we're not ready to do just yet
drawable.Y -= (float)timingChange.Time; drawable.Y -= (float)timingChange.Time;
@ -117,8 +114,7 @@ namespace osu.Game.Rulesets.Mania.Timing
} }
/// <summary> /// <summary>
/// Whether this timing section can contain a drawable. A timing section can contain a drawable if the drawable /// Whether this control point can contain a drawable. This control point can contain a drawable if the drawable is positioned "after" this control point.
/// can be placed within the timing section's bounds (in this case, from the start of the timing section up to infinity).
/// </summary> /// </summary>
/// <param name="drawable">The drawable to check.</param> /// <param name="drawable">The drawable to check.</param>
public bool CanContain(Drawable drawable) => content.Y <= drawable.Y; public bool CanContain(Drawable drawable) => content.Y <= drawable.Y;
@ -136,14 +132,7 @@ namespace osu.Game.Rulesets.Mania.Timing
return; return;
} }
float height = 0; float height = Children.Select(child => child.Y + child.Height).Max();
foreach (Drawable child in Children)
{
float childEndPos = child.Y + child.Height;
if (childEndPos > height)
height = childEndPos;
}
Height = height; Height = height;
RelativeCoordinateSpace = new Vector2(1, height); RelativeCoordinateSpace = new Vector2(1, height);