mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 23:22:55 +08:00
Add the ability to add/remove groups
This commit is contained in:
parent
0fba272e78
commit
73369ae613
@ -5,6 +5,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Lists;
|
||||
|
||||
namespace osu.Game.Beatmaps.ControlPoints
|
||||
@ -16,9 +17,9 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
/// Control point groups.
|
||||
/// </summary>
|
||||
[JsonProperty]
|
||||
public IReadOnlyList<ControlPointGroup> Groups => groups;
|
||||
public IBindableList<ControlPointGroup> Groups => groups;
|
||||
|
||||
private readonly SortedList<ControlPointGroup> groups = new SortedList<ControlPointGroup>(Comparer<ControlPointGroup>.Default);
|
||||
private readonly BindableList<ControlPointGroup> groups = new BindableList<ControlPointGroup>();
|
||||
|
||||
/// <summary>
|
||||
/// All timing points.
|
||||
@ -294,5 +295,19 @@ namespace osu.Game.Beatmaps.ControlPoints
|
||||
samplePoints.Clear();
|
||||
effectPoints.Clear();
|
||||
}
|
||||
|
||||
public ControlPointGroup CreateGroup(double time)
|
||||
{
|
||||
var newGroup = new ControlPointGroup(time);
|
||||
|
||||
int i = groups.BinarySearch(newGroup);
|
||||
if (i < 0) i = ~i;
|
||||
|
||||
groups.Insert(i, newGroup);
|
||||
|
||||
return newGroup;
|
||||
}
|
||||
|
||||
public void RemoveGroup(ControlPointGroup group) => groups.Remove(group);
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
selectedGroup.BindValueChanged(group => { Selected = controlGroup == group.NewValue; });
|
||||
selectedGroup.BindValueChanged(group => { Selected = controlGroup == group.NewValue; }, true);
|
||||
}
|
||||
|
||||
private bool selected;
|
||||
|
@ -52,12 +52,18 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
public class ControlPointList : CompositeDrawable
|
||||
{
|
||||
private OsuButton deleteButton;
|
||||
private ControlPointTable table;
|
||||
|
||||
private IBindableList<ControlPointGroup> controlGroups;
|
||||
|
||||
[Resolved]
|
||||
protected IFrameBasedClock EditorClock { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
protected IBindable<WorkingBeatmap> Beatmap { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private Bindable<ControlPointGroup> selectedPoints { get; set; }
|
||||
private Bindable<ControlPointGroup> selectedGroup { get; set; }
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
@ -74,10 +80,7 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
new OsuScrollContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new ControlPointTable
|
||||
{
|
||||
ControlGroups = Beatmap.Value.Beatmap.ControlPointInfo.Groups
|
||||
}
|
||||
Child = table = new ControlPointTable(),
|
||||
},
|
||||
new FillFlowContainer
|
||||
{
|
||||
@ -114,15 +117,27 @@ namespace osu.Game.Screens.Edit.Timing
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
selectedPoints.BindValueChanged(selected => { deleteButton.Enabled.Value = selected.NewValue != null; }, true);
|
||||
selectedGroup.BindValueChanged(selected => { deleteButton.Enabled.Value = selected.NewValue != null; }, true);
|
||||
|
||||
controlGroups = Beatmap.Value.Beatmap.ControlPointInfo.Groups.GetBoundCopy();
|
||||
controlGroups.ItemsAdded += _ => createContent();
|
||||
controlGroups.ItemsRemoved += _ => createContent();
|
||||
createContent();
|
||||
}
|
||||
|
||||
private void createContent() => table.ControlGroups = controlGroups;
|
||||
|
||||
private void delete()
|
||||
{
|
||||
if (selectedGroup.Value == null)
|
||||
return;
|
||||
|
||||
Beatmap.Value.Beatmap.ControlPointInfo.RemoveGroup(selectedGroup.Value);
|
||||
}
|
||||
|
||||
private void addNew()
|
||||
{
|
||||
selectedGroup.Value = Beatmap.Value.Beatmap.ControlPointInfo.CreateGroup(EditorClock.CurrentTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user