1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 14:53:01 +08:00

Add the ability to add/remove groups

This commit is contained in:
Dean Herbert 2019-10-27 16:13:24 +09:00
parent 0fba272e78
commit 73369ae613
3 changed files with 39 additions and 9 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Framework.Lists; using osu.Framework.Lists;
namespace osu.Game.Beatmaps.ControlPoints namespace osu.Game.Beatmaps.ControlPoints
@ -16,9 +17,9 @@ namespace osu.Game.Beatmaps.ControlPoints
/// Control point groups. /// Control point groups.
/// </summary> /// </summary>
[JsonProperty] [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> /// <summary>
/// All timing points. /// All timing points.
@ -294,5 +295,19 @@ namespace osu.Game.Beatmaps.ControlPoints
samplePoints.Clear(); samplePoints.Clear();
effectPoints.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);
} }
} }

View File

@ -203,7 +203,7 @@ namespace osu.Game.Screens.Edit.Timing
{ {
base.LoadComplete(); base.LoadComplete();
selectedGroup.BindValueChanged(group => { Selected = controlGroup == group.NewValue; }); selectedGroup.BindValueChanged(group => { Selected = controlGroup == group.NewValue; }, true);
} }
private bool selected; private bool selected;

View File

@ -52,12 +52,18 @@ namespace osu.Game.Screens.Edit.Timing
public class ControlPointList : CompositeDrawable public class ControlPointList : CompositeDrawable
{ {
private OsuButton deleteButton; private OsuButton deleteButton;
private ControlPointTable table;
private IBindableList<ControlPointGroup> controlGroups;
[Resolved]
protected IFrameBasedClock EditorClock { get; private set; }
[Resolved] [Resolved]
protected IBindable<WorkingBeatmap> Beatmap { get; private set; } protected IBindable<WorkingBeatmap> Beatmap { get; private set; }
[Resolved] [Resolved]
private Bindable<ControlPointGroup> selectedPoints { get; set; } private Bindable<ControlPointGroup> selectedGroup { get; set; }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
@ -74,10 +80,7 @@ namespace osu.Game.Screens.Edit.Timing
new OsuScrollContainer new OsuScrollContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new ControlPointTable Child = table = new ControlPointTable(),
{
ControlGroups = Beatmap.Value.Beatmap.ControlPointInfo.Groups
}
}, },
new FillFlowContainer new FillFlowContainer
{ {
@ -114,15 +117,27 @@ namespace osu.Game.Screens.Edit.Timing
{ {
base.LoadComplete(); 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() private void delete()
{ {
if (selectedGroup.Value == null)
return;
Beatmap.Value.Beatmap.ControlPointInfo.RemoveGroup(selectedGroup.Value);
} }
private void addNew() private void addNew()
{ {
selectedGroup.Value = Beatmap.Value.Beatmap.ControlPointInfo.CreateGroup(EditorClock.CurrentTime);
} }
} }
} }