From 6a79c8b66c2595b0a1d5a3766e0ea2bff21db035 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 11 May 2017 19:57:24 +0900 Subject: [PATCH] Make notes scroll with beat length. --- .../Timing/TimeRelativeContainer.cs | 53 +++++++++++++++---- osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs | 6 +-- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs b/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs index d4705c2352..06e7cd1f53 100644 --- a/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/TimeRelativeContainer.cs @@ -29,9 +29,13 @@ namespace osu.Game.Rulesets.Mania.Timing set { RelativeCoordinateSpace = new Vector2(1, (float)value); } } + private readonly List drawableTimingSections; + public TimeRelativeContainer(IEnumerable timingSections) { - Children = timingSections.Select(t => new DrawableTimingSection(t)); + drawableTimingSections = timingSections.Select(t => new DrawableTimingSection(t)).ToList(); + + Children = drawableTimingSections; } /// @@ -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 /// /// A container that contains drawables within the time span of a timing section. /// - /// Scrolls relative to the current time. + /// The content of this container will scroll relative to the current time. /// /// private class DrawableTimingSection : Container { + protected override Container Content => content; + /// + /// The container which will scroll relative to the current time. + /// + private readonly Container content; + private readonly TimingSection section; + /// + /// 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. + /// + /// 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. + /// + /// + /// The section to create the drawable timing section for. 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; } } } \ No newline at end of file diff --git a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs index 826f7262f6..7636e41099 100644 --- a/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs +++ b/osu.Game.Rulesets.Mania/UI/ManiaPlayfield.cs @@ -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; /// /// Default column keys, expanding outwards from the middle as more column are added.