1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:07:52 +08:00

Expose singular coarse-grained change event on ControlPointInfo

This commit is contained in:
Bartłomiej Dach 2024-06-11 09:15:14 +02:00
parent b8e0704554
commit 694cfd0e25
No known key found for this signature in database
2 changed files with 19 additions and 0 deletions

View File

@ -10,8 +10,11 @@ namespace osu.Game.Beatmaps.ControlPoints
public class ControlPointGroup : IComparable<ControlPointGroup>, IEquatable<ControlPointGroup>
{
public event Action<ControlPoint>? ItemAdded;
public event Action<ControlPoint>? ItemChanged;
public event Action<ControlPoint>? ItemRemoved;
private void raiseItemChanged(ControlPoint controlPoint) => ItemChanged?.Invoke(controlPoint);
/// <summary>
/// The time at which the control point takes effect.
/// </summary>
@ -39,12 +42,14 @@ namespace osu.Game.Beatmaps.ControlPoints
controlPoints.Add(point);
ItemAdded?.Invoke(point);
point.Changed += raiseItemChanged;
}
public void Remove(ControlPoint point)
{
controlPoints.Remove(point);
ItemRemoved?.Invoke(point);
point.Changed -= raiseItemChanged;
}
public sealed override bool Equals(object? obj)

View File

@ -19,6 +19,14 @@ namespace osu.Game.Beatmaps.ControlPoints
[Serializable]
public class ControlPointInfo : IDeepCloneable<ControlPointInfo>
{
/// <summary>
/// Invoked on any change to the set of control points.
/// </summary>
[CanBeNull]
public event Action ControlPointsChanged;
private void raiseControlPointsChanged([CanBeNull] ControlPoint _ = null) => ControlPointsChanged?.Invoke();
/// <summary>
/// All control points grouped by time.
/// </summary>
@ -116,6 +124,7 @@ namespace osu.Game.Beatmaps.ControlPoints
if (addIfNotExisting)
{
newGroup.ItemAdded += GroupItemAdded;
newGroup.ItemChanged += raiseControlPointsChanged;
newGroup.ItemRemoved += GroupItemRemoved;
groups.Insert(~i, newGroup);
@ -131,6 +140,7 @@ namespace osu.Game.Beatmaps.ControlPoints
group.Remove(item);
group.ItemAdded -= GroupItemAdded;
group.ItemChanged -= raiseControlPointsChanged;
group.ItemRemoved -= GroupItemRemoved;
groups.Remove(group);
@ -287,6 +297,8 @@ namespace osu.Game.Beatmaps.ControlPoints
default:
throw new ArgumentException($"A control point of unexpected type {controlPoint.GetType()} was added to this {nameof(ControlPointInfo)}");
}
raiseControlPointsChanged();
}
protected virtual void GroupItemRemoved(ControlPoint controlPoint)
@ -301,6 +313,8 @@ namespace osu.Game.Beatmaps.ControlPoints
effectPoints.Remove(typed);
break;
}
raiseControlPointsChanged();
}
public ControlPointInfo DeepClone()