2019-10-25 10:48:01 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Linq;
|
2019-10-28 02:39:17 +00:00
|
|
|
using osu.Framework.Bindables;
|
2019-10-25 10:48:01 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.ControlPoints
|
|
|
|
{
|
|
|
|
public class ControlPointGroup : IComparable<ControlPointGroup>
|
|
|
|
{
|
|
|
|
public event Action<ControlPoint> ItemAdded;
|
|
|
|
public event Action<ControlPoint> ItemRemoved;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The time at which the control point takes effect.
|
|
|
|
/// </summary>
|
|
|
|
public double Time { get; }
|
|
|
|
|
2019-10-28 02:39:17 +00:00
|
|
|
public IBindableList<ControlPoint> ControlPoints => controlPoints;
|
2019-10-25 10:48:01 +00:00
|
|
|
|
2019-10-28 02:39:17 +00:00
|
|
|
private readonly BindableList<ControlPoint> controlPoints = new BindableList<ControlPoint>();
|
2019-10-25 10:48:01 +00:00
|
|
|
|
|
|
|
public ControlPointGroup(double time)
|
|
|
|
{
|
|
|
|
Time = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int CompareTo(ControlPointGroup other) => Time.CompareTo(other.Time);
|
|
|
|
|
|
|
|
public void Add(ControlPoint point)
|
|
|
|
{
|
2019-10-26 01:25:13 +00:00
|
|
|
var existing = controlPoints.FirstOrDefault(p => p.GetType() == point.GetType());
|
2019-10-25 10:48:01 +00:00
|
|
|
|
2019-10-26 01:25:13 +00:00
|
|
|
if (existing != null)
|
2019-10-25 10:48:01 +00:00
|
|
|
Remove(existing);
|
|
|
|
|
2019-10-26 01:25:13 +00:00
|
|
|
point.AttachGroup(this);
|
2019-10-25 10:48:01 +00:00
|
|
|
|
|
|
|
controlPoints.Add(point);
|
|
|
|
ItemAdded?.Invoke(point);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Remove(ControlPoint point)
|
|
|
|
{
|
|
|
|
controlPoints.Remove(point);
|
|
|
|
ItemRemoved?.Invoke(point);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|