// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections { public class FollowPointRenderer : CompositeDrawable { /// /// Adds the s around a . /// This includes s leading into , and s exiting . /// /// The to add s for. public void AddFollowPoints(DrawableOsuHitObject hitObject) { var startGroup = new FollowPointGroup(hitObject); AddInternal(startGroup); // Groups are sorted by their start time when added, so the index can be used to post-process other surrounding groups int startIndex = IndexOfInternal(startGroup); if (startIndex < InternalChildren.Count - 1) { // h1 -> -> -> h2 // hitObject nextGroup var nextGroup = (FollowPointGroup)InternalChildren[startIndex + 1]; startGroup.End = nextGroup.Start; } if (startIndex > 0) { // h1 -> -> -> h2 // prevGroup hitObject var previousGroup = (FollowPointGroup)InternalChildren[startIndex - 1]; previousGroup.End = startGroup.Start; } } /// /// Removes the s around a . /// This includes s leading into , and s exiting . /// /// The to remove s for. public void RemoveFollowPoints(DrawableOsuHitObject hitObject) { var groups = findGroups(hitObject); // Regardless of the position of the hitobject in the beatmap, there will always be a group leading from the hitobject RemoveInternal(groups.start); if (groups.end != null) { // When there were two groups referencing the same hitobject, merge them by updating the end group to point to the new end (the start group was already removed) groups.end.End = groups.start.End; } } /// /// Finds the s with as the start and end s. /// /// The to find the relevant of. /// A tuple containing the end group (the where is the end of), /// and the start group (the where is the start of). private (FollowPointGroup start, FollowPointGroup end) findGroups(DrawableOsuHitObject hitObject) { // endGroup startGroup // h1 -> -> -> -> -> h2 -> -> -> -> -> h3 // hitObject FollowPointGroup startGroup = null; // The group which the hitobject is the start in FollowPointGroup endGroup = null; // The group which the hitobject is the end in int startIndex = 0; for (; startIndex < InternalChildren.Count; startIndex++) { var group = (FollowPointGroup)InternalChildren[startIndex]; if (group.Start == hitObject) { startGroup = group; break; } } if (startIndex > 0) endGroup = (FollowPointGroup)InternalChildren[startIndex - 1]; return (startGroup, endGroup); } protected override int Compare(Drawable x, Drawable y) { var groupX = (FollowPointGroup)x; var groupY = (FollowPointGroup)y; return groupX.Start.HitObject.StartTime.CompareTo(groupY.Start.HitObject.StartTime); } } }