mirror of
https://github.com/ppy/osu
synced 2024-12-14 10:57:41 +00:00
Make notes scroll with beat length.
This commit is contained in:
parent
5dd83067ee
commit
6a79c8b66c
@ -29,9 +29,13 @@ namespace osu.Game.Rulesets.Mania.Timing
|
||||
set { RelativeCoordinateSpace = new Vector2(1, (float)value); }
|
||||
}
|
||||
|
||||
private readonly List<DrawableTimingSection> drawableTimingSections;
|
||||
|
||||
public TimeRelativeContainer(IEnumerable<TimingSection> timingSections)
|
||||
{
|
||||
Children = timingSections.Select(t => new DrawableTimingSection(t));
|
||||
drawableTimingSections = timingSections.Select(t => new DrawableTimingSection(t)).ToList();
|
||||
|
||||
Children = drawableTimingSections;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -48,7 +52,7 @@ namespace osu.Game.Rulesets.Mania.Timing
|
||||
return;
|
||||
}
|
||||
|
||||
var section = (Children.LastOrDefault(t => t.Y >= drawable.Y) ?? Children.First()) as DrawableTimingSection;
|
||||
var section = drawableTimingSections.LastOrDefault(t => t.CanContain(drawable)) ?? drawableTimingSections.First();
|
||||
|
||||
if (section == null)
|
||||
throw new Exception("Could not find suitable timing section to add object to.");
|
||||
@ -59,13 +63,28 @@ namespace osu.Game.Rulesets.Mania.Timing
|
||||
/// <summary>
|
||||
/// A container that contains drawables within the time span of a timing section.
|
||||
/// <para>
|
||||
/// Scrolls relative to the current time.
|
||||
/// The content of this container will scroll relative to the current time.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private class DrawableTimingSection : Container
|
||||
{
|
||||
protected override Container<Drawable> Content => content;
|
||||
/// <summary>
|
||||
/// The container which will scroll relative to the current time.
|
||||
/// </summary>
|
||||
private readonly Container content;
|
||||
|
||||
private readonly TimingSection section;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a drawable timing section. 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.
|
||||
/// <para>
|
||||
/// This is so that, e.g. a beat length of 500ms results in this container being twice as high as its parent,
|
||||
/// which means that the content container will scroll at twice the normal rate.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="section">The section to create the drawable timing section for.</param>
|
||||
public DrawableTimingSection(TimingSection section)
|
||||
{
|
||||
this.section = section;
|
||||
@ -73,18 +92,30 @@ namespace osu.Game.Rulesets.Mania.Timing
|
||||
Anchor = Anchor.BottomCentre;
|
||||
Origin = Anchor.BottomCentre;
|
||||
|
||||
RelativePositionAxes = Axes.Y;
|
||||
Y = -(float)section.StartTime;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Height = (float)section.Duration;
|
||||
|
||||
RelativeCoordinateSpace = new Vector2(1, Height);
|
||||
AddInternal(content = new Container
|
||||
{
|
||||
Anchor = Anchor.BottomCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
RelativePositionAxes = Axes.Both,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Y = -(float)section.StartTime,
|
||||
Height = (float)section.Duration,
|
||||
RelativeCoordinateSpace = new Vector2(1, (float)section.Duration)
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
Y = (float)(Time.Current - section.StartTime);
|
||||
var parent = (TimeRelativeContainer)Parent;
|
||||
|
||||
// Adjust our height to account for the speed changes
|
||||
Height = (float)(parent.TimeSpan * 1000 / section.BeatLength);
|
||||
RelativeCoordinateSpace = new Vector2(1, (float)parent.TimeSpan);
|
||||
|
||||
// Scroll the content
|
||||
content.Y = (float)(Time.Current - section.StartTime);
|
||||
}
|
||||
|
||||
public override void Add(Drawable drawable)
|
||||
@ -93,10 +124,12 @@ namespace osu.Game.Rulesets.Mania.Timing
|
||||
// we need to offset it back by our position so that it becomes correctly relatively-positioned to us
|
||||
// This can be removed if hit objects were stored such that either their StartTime or their "beat offset" was relative to the timing section
|
||||
// they belonged to, but this requires a radical change to the beatmap format which we're not ready to do just yet
|
||||
drawable.Y -= Y;
|
||||
drawable.Y += (float)section.StartTime;
|
||||
|
||||
base.Add(drawable);
|
||||
}
|
||||
|
||||
public bool CanContain(Drawable drawable) => content.Y >= drawable.Y;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,10 +27,10 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
{
|
||||
public const float HIT_TARGET_POSITION = 50;
|
||||
|
||||
private const float time_span_default = 500;
|
||||
private const float time_span_default = 20000;
|
||||
private const float time_span_min = 10;
|
||||
private const float time_span_max = 20000;
|
||||
private const float time_span_step = 100;
|
||||
private const float time_span_max = 50000;
|
||||
private const float time_span_step = 1000;
|
||||
|
||||
/// <summary>
|
||||
/// Default column keys, expanding outwards from the middle as more column are added.
|
||||
|
Loading…
Reference in New Issue
Block a user