1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-31 06:12:55 +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 class ControlPointGroup : IComparable<ControlPointGroup>, IEquatable<ControlPointGroup>
{ {
public event Action<ControlPoint>? ItemAdded; public event Action<ControlPoint>? ItemAdded;
public event Action<ControlPoint>? ItemChanged;
public event Action<ControlPoint>? ItemRemoved; public event Action<ControlPoint>? ItemRemoved;
private void raiseItemChanged(ControlPoint controlPoint) => ItemChanged?.Invoke(controlPoint);
/// <summary> /// <summary>
/// The time at which the control point takes effect. /// The time at which the control point takes effect.
/// </summary> /// </summary>
@ -39,12 +42,14 @@ namespace osu.Game.Beatmaps.ControlPoints
controlPoints.Add(point); controlPoints.Add(point);
ItemAdded?.Invoke(point); ItemAdded?.Invoke(point);
point.Changed += raiseItemChanged;
} }
public void Remove(ControlPoint point) public void Remove(ControlPoint point)
{ {
controlPoints.Remove(point); controlPoints.Remove(point);
ItemRemoved?.Invoke(point); ItemRemoved?.Invoke(point);
point.Changed -= raiseItemChanged;
} }
public sealed override bool Equals(object? obj) public sealed override bool Equals(object? obj)

View File

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