1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:17:44 +08:00
osu-lazer/osu.Game/Rulesets/Timing/Drawables/DrawableTimingSection.cs

77 lines
3.6 KiB
C#
Raw Normal View History

2017-06-02 17:20:14 +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 System;
2017-06-09 01:42:17 +08:00
using osu.Framework.Allocation;
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;
namespace osu.Game.Rulesets.Timing.Drawables
{
/// <summary>
/// A container for hit objects which applies applies the speed changes defined by the <see cref="Timing.TimingSection.BeatLength"/> and <see cref="Timing.TimingSection.SpeedMultiplier"/>
/// properties to its <see cref="Container{T}.Content"/> to affect the <see cref="HitObjectCollection"/> scroll speed.
/// </summary>
public abstract class DrawableTimingSection : Container<DrawableHitObject>
{
public readonly TimingSection TimingSection;
protected override Container<DrawableHitObject> Content => content;
2017-06-09 01:42:17 +08:00
private Container<DrawableHitObject> content;
private readonly Axes scrollingAxes;
/// <summary>
/// Creates a new <see cref="DrawableTimingSection"/>.
/// </summary>
/// <param name="timingSection">The encapsulated timing section that provides the speed changes.</param>
/// <param name="scrollingAxes">The axes through which this drawable timing section scrolls through.</param>
protected DrawableTimingSection(TimingSection timingSection, Axes scrollingAxes)
{
this.scrollingAxes = scrollingAxes;
TimingSection = timingSection;
2017-06-09 01:42:17 +08:00
}
2017-06-09 01:42:17 +08:00
[BackgroundDependencyLoader]
private void load()
{
AddInternal(content = CreateHitObjectCollection());
content.RelativeChildOffset = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)TimingSection.Time : 0, (scrollingAxes & Axes.Y) > 0 ? (float)TimingSection.Time : 0);
}
public override Axes RelativeSizeAxes
{
get { return Axes.Both; }
set { throw new InvalidOperationException($"{nameof(DrawableTimingSection)} must always be relatively-sized."); }
}
protected override void Update()
{
2017-06-09 01:42:17 +08:00
var parent = Parent as TimingSectionCollection;
if (parent == null)
return;
float speedAdjustedSize = (float)(1000 / TimingSection.BeatLength / TimingSection.SpeedMultiplier);
// The application of speed changes happens by modifying our size while maintaining the parent's relative child size as our own
// By doing this the scroll speed of the hit objects is changed by a factor of Size / RelativeChildSize
2017-06-05 19:02:44 +08:00
Size = new Vector2((scrollingAxes & Axes.X) > 0 ? speedAdjustedSize : 1, (scrollingAxes & Axes.Y) > 0 ? speedAdjustedSize : 1);
2017-06-09 01:42:17 +08:00
RelativeChildSize = new Vector2((scrollingAxes & Axes.X) > 0 ? (float)parent.TimeSpan : 1, (scrollingAxes & Axes.Y) > 0 ? (float)parent.TimeSpan : 1);
}
/// <summary>
/// Whether this timing change can contain a hit object. This is true if the hit object occurs after this timing change with respect to time.
/// </summary>
public bool CanContain(DrawableHitObject hitObject) => TimingSection.Time <= hitObject.HitObject.StartTime;
/// <summary>
/// Creates the container which handles the movement of a collection of hit objects.
/// </summary>
2017-06-09 01:42:17 +08:00
/// <returns>The hit object collection.</returns>
protected abstract HitObjectCollection CreateHitObjectCollection();
}
}