mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 07:32:55 +08:00
Implement group re-ordering based on start time
This commit is contained in:
parent
a19e26f8aa
commit
3b6064336b
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
@ -16,16 +17,25 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
|||||||
private const int spacing = 32;
|
private const int spacing = 32;
|
||||||
private const double preempt = 800;
|
private const double preempt = 800;
|
||||||
|
|
||||||
|
public readonly Bindable<double> StartTime = new Bindable<double>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.
|
/// The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[NotNull]
|
[NotNull]
|
||||||
public readonly DrawableOsuHitObject Start;
|
public readonly DrawableOsuHitObject Start;
|
||||||
|
|
||||||
public FollowPointGroup(DrawableOsuHitObject start)
|
/// <summary>
|
||||||
|
/// Creates a new <see cref="FollowPointGroup"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="start">The <see cref="DrawableOsuHitObject"/> which <see cref="FollowPoint"/>s will exit from.</param>
|
||||||
|
public FollowPointGroup([NotNull] DrawableOsuHitObject start)
|
||||||
{
|
{
|
||||||
Start = start;
|
Start = start;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
StartTime.BindTo(Start.HitObject.StartTimeBindable);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
|
||||||
@ -8,97 +11,87 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
|
|||||||
{
|
{
|
||||||
public class FollowPointRenderer : CompositeDrawable
|
public class FollowPointRenderer : CompositeDrawable
|
||||||
{
|
{
|
||||||
|
private readonly List<FollowPointGroup> groups = new List<FollowPointGroup>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the <see cref="FollowPoint"/>s around a <see cref="DrawableOsuHitObject"/>.
|
/// Adds the <see cref="FollowPoint"/>s around a <see cref="DrawableOsuHitObject"/>.
|
||||||
/// This includes <see cref="FollowPoint"/>s leading into <paramref name="hitObject"/>, and <see cref="FollowPoint"/>s exiting <paramref name="hitObject"/>.
|
/// This includes <see cref="FollowPoint"/>s leading into <paramref name="hitObject"/>, and <see cref="FollowPoint"/>s exiting <paramref name="hitObject"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to add <see cref="FollowPoint"/>s for.</param>
|
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to add <see cref="FollowPoint"/>s for.</param>
|
||||||
public void AddFollowPoints(DrawableOsuHitObject hitObject)
|
public void AddFollowPoints(DrawableOsuHitObject hitObject)
|
||||||
{
|
=> addGroup(new FollowPointGroup(hitObject).With(g => g.StartTime.BindValueChanged(_ => onStartTimeChanged(g))));
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes the <see cref="FollowPoint"/>s around a <see cref="DrawableOsuHitObject"/>.
|
/// Removes the <see cref="FollowPoint"/>s around a <see cref="DrawableOsuHitObject"/>.
|
||||||
/// This includes <see cref="FollowPoint"/>s leading into <paramref name="hitObject"/>, and <see cref="FollowPoint"/>s exiting <paramref name="hitObject"/>.
|
/// This includes <see cref="FollowPoint"/>s leading into <paramref name="hitObject"/>, and <see cref="FollowPoint"/>s exiting <paramref name="hitObject"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to remove <see cref="FollowPoint"/>s for.</param>
|
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to remove <see cref="FollowPoint"/>s for.</param>
|
||||||
public void RemoveFollowPoints(DrawableOsuHitObject hitObject)
|
public void RemoveFollowPoints(DrawableOsuHitObject hitObject) => removeGroup(groups.Single(g => g.Start == hitObject));
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a <see cref="FollowPointGroup"/> to this <see cref="FollowPointRenderer"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="group">The <see cref="FollowPointGroup"/> to add.</param>
|
||||||
|
/// <returns>The index of <paramref name="group"/> in <see cref="groups"/>.</returns>
|
||||||
|
private int addGroup(FollowPointGroup group)
|
||||||
{
|
{
|
||||||
var groups = findGroups(hitObject);
|
AddInternal(group);
|
||||||
|
|
||||||
// Regardless of the position of the hitobject in the beatmap, there will always be a group leading from the hitobject
|
// Groups are sorted by their start time when added such that the index can be used to post-process other surrounding groups
|
||||||
RemoveInternal(groups.start);
|
int index = groups.AddInPlace(group, Comparer<FollowPointGroup>.Create((g1, g2) => g1.StartTime.Value.CompareTo(g2.StartTime.Value)));
|
||||||
|
|
||||||
if (groups.end != null)
|
if (index < groups.Count - 1)
|
||||||
{
|
{
|
||||||
// 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)
|
// Update the group's end point to the next hitobject
|
||||||
groups.end.End = groups.start.End;
|
// h1 -> -> -> h2
|
||||||
|
// hitObject nextGroup
|
||||||
|
|
||||||
|
FollowPointGroup nextGroup = groups[index + 1];
|
||||||
|
group.End = nextGroup.Start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (index > 0)
|
||||||
|
{
|
||||||
|
// Previous group's end point to the current group's start point
|
||||||
|
// h1 -> -> -> h2
|
||||||
|
// prevGroup hitObject
|
||||||
|
|
||||||
|
FollowPointGroup previousGroup = groups[index - 1];
|
||||||
|
previousGroup.End = group.Start;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the <see cref="FollowPointGroup"/>s with <paramref name="hitObject"/> as the start and end <see cref="DrawableOsuHitObject"/>s.
|
/// Removes a <see cref="FollowPointGroup"/> from this <see cref="FollowPointRenderer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="hitObject">The <see cref="DrawableOsuHitObject"/> to find the relevant <see cref="FollowPointGroup"/> of.</param>
|
/// <param name="group">The <see cref="FollowPointGroup"/> to remove.</param>
|
||||||
/// <returns>A tuple containing the end group (the <see cref="FollowPointGroup"/> where <paramref name="hitObject"/> is the end of),
|
/// <returns>Whether <paramref name="group"/> was removed.</returns>
|
||||||
/// and the start group (the <see cref="FollowPointGroup"/> where <paramref name="hitObject"/> is the start of).</returns>
|
private bool removeGroup(FollowPointGroup group)
|
||||||
private (FollowPointGroup start, FollowPointGroup end) findGroups(DrawableOsuHitObject hitObject)
|
|
||||||
{
|
{
|
||||||
// endGroup startGroup
|
RemoveInternal(group);
|
||||||
// h1 -> -> -> -> -> h2 -> -> -> -> -> h3
|
|
||||||
// hitObject
|
|
||||||
|
|
||||||
FollowPointGroup startGroup = null; // The group which the hitobject is the start in
|
int index = groups.IndexOf(group);
|
||||||
FollowPointGroup endGroup = null; // The group which the hitobject is the end in
|
|
||||||
|
|
||||||
int startIndex = 0;
|
if (index > 0)
|
||||||
|
|
||||||
for (; startIndex < InternalChildren.Count; startIndex++)
|
|
||||||
{
|
{
|
||||||
var group = (FollowPointGroup)InternalChildren[startIndex];
|
// Update the previous group's end point to the next group's start point
|
||||||
|
// h1 -> -> -> h2 -> -> -> h3
|
||||||
if (group.Start == hitObject)
|
// prevGroup group nextGroup
|
||||||
{
|
// The current group's end point is used since there may not be a next group
|
||||||
startGroup = group;
|
FollowPointGroup previousGroup = groups[index - 1];
|
||||||
break;
|
previousGroup.End = group.End;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startIndex > 0)
|
return groups.Remove(group);
|
||||||
endGroup = (FollowPointGroup)InternalChildren[startIndex - 1];
|
|
||||||
|
|
||||||
return (startGroup, endGroup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override int Compare(Drawable x, Drawable y)
|
private void onStartTimeChanged(FollowPointGroup group)
|
||||||
{
|
{
|
||||||
var groupX = (FollowPointGroup)x;
|
// Naive but can be improved if performance becomes problematic
|
||||||
var groupY = (FollowPointGroup)y;
|
removeGroup(group);
|
||||||
|
addGroup(group);
|
||||||
return groupX.Start.HitObject.StartTime.CompareTo(groupY.Start.HitObject.StartTime);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user