From d75bbb2b88debd6b578e4e77ea5de73c87c2f4dc Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 2 Jun 2017 15:28:30 +0900 Subject: [PATCH] Fix incorrect sorting. --- .../Timing/TimingChangeContainer.cs | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Mania/Timing/TimingChangeContainer.cs b/osu.Game.Rulesets.Mania/Timing/TimingChangeContainer.cs index d01819b291..cb6f4319a3 100644 --- a/osu.Game.Rulesets.Mania/Timing/TimingChangeContainer.cs +++ b/osu.Game.Rulesets.Mania/Timing/TimingChangeContainer.cs @@ -35,11 +35,37 @@ namespace osu.Game.Rulesets.Mania.Timing target.Add(hitObject); } + protected override IComparer DepthComparer => new TimingChangeReverseStartTimeComparer(); + /// /// Finds the most applicable timing change that can contain a hit object. /// /// The hit object to contain. - /// The last timing change which can contain . - private DrawableTimingChange timingChangeFor(DrawableHitObject hitObject) => Children.LastOrDefault(c => c.CanContain(hitObject)) ?? Children.FirstOrDefault(); + /// The last timing change which can contain . Null if no timing change can contain the hit object. + private DrawableTimingChange timingChangeFor(DrawableHitObject hitObject) => Children.FirstOrDefault(c => c.CanContain(hitObject)); + } + + /// + /// Compares two timing changes by their start time, falling back to creation order if their start time is equal. + /// This will compare the two timing changes in reverse order. + /// + public class TimingChangeReverseStartTimeComparer : Drawable.ReverseCreationOrderDepthComparer + { + public override int Compare(Drawable x, Drawable y) + { + var timingChangeX = x as DrawableTimingChange; + var timingChangeY = y as DrawableTimingChange; + + // If either of the two drawables are not hit objects, fall back to the base comparer + if (timingChangeX?.TimingChange == null || timingChangeY?.TimingChange == null) + return base.Compare(x, y); + + // Compare by start time + int i = timingChangeY.TimingChange.Time.CompareTo(timingChangeX.TimingChange.Time); + if (i != 0) + return i; + + return base.Compare(x, y); + } } } \ No newline at end of file