2020-10-02 14:25:48 +08: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.Linq;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Timing
|
|
|
|
{
|
|
|
|
internal class GroupSection : CompositeDrawable
|
|
|
|
{
|
|
|
|
private LabelledTextBox textBox;
|
|
|
|
|
2020-10-03 00:27:42 +08:00
|
|
|
private TriangleButton button;
|
|
|
|
|
2020-10-02 14:25:48 +08:00
|
|
|
[Resolved]
|
|
|
|
protected Bindable<ControlPointGroup> SelectedGroup { get; private set; }
|
|
|
|
|
|
|
|
[Resolved]
|
2021-01-04 15:38:15 +08:00
|
|
|
protected EditorBeatmap Beatmap { get; private set; }
|
2020-10-02 14:25:48 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private EditorClock clock { get; set; }
|
|
|
|
|
2020-10-02 16:32:34 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
private IEditorChangeHandler changeHandler { get; set; }
|
|
|
|
|
2020-10-02 14:25:48 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
Padding = new MarginPadding(10);
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Spacing = new Vector2(10),
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
textBox = new LabelledTextBox
|
|
|
|
{
|
|
|
|
Label = "Time"
|
|
|
|
},
|
2020-10-03 00:27:42 +08:00
|
|
|
button = new TriangleButton
|
2020-10-02 14:25:48 +08:00
|
|
|
{
|
|
|
|
Text = "Use current time",
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Action = () => changeSelectedGroupTime(clock.CurrentTime)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
textBox.OnCommit += (sender, isNew) =>
|
|
|
|
{
|
2020-10-02 14:33:33 +08:00
|
|
|
if (!isNew)
|
|
|
|
return;
|
|
|
|
|
2020-10-02 14:25:48 +08:00
|
|
|
if (double.TryParse(sender.Text, out var newTime))
|
|
|
|
{
|
|
|
|
changeSelectedGroupTime(newTime);
|
|
|
|
}
|
2020-10-02 14:33:33 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SelectedGroup.TriggerChange();
|
|
|
|
}
|
2020-10-02 14:25:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
SelectedGroup.BindValueChanged(group =>
|
|
|
|
{
|
|
|
|
if (group.NewValue == null)
|
|
|
|
{
|
|
|
|
textBox.Text = string.Empty;
|
2020-10-03 00:27:42 +08:00
|
|
|
|
2020-11-11 04:32:47 +08:00
|
|
|
// cannot use textBox.Current.Disabled due to https://github.com/ppy/osu-framework/issues/3919
|
|
|
|
textBox.ReadOnly = true;
|
2020-10-03 00:27:42 +08:00
|
|
|
button.Enabled.Value = false;
|
2020-10-02 14:25:48 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-11 04:32:47 +08:00
|
|
|
textBox.ReadOnly = false;
|
2020-10-03 00:27:42 +08:00
|
|
|
button.Enabled.Value = true;
|
|
|
|
|
2020-10-02 14:25:48 +08:00
|
|
|
textBox.Text = $"{group.NewValue.Time:n0}";
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void changeSelectedGroupTime(in double time)
|
|
|
|
{
|
2020-10-03 00:27:42 +08:00
|
|
|
if (SelectedGroup.Value == null || time == SelectedGroup.Value.Time)
|
2020-10-02 16:35:41 +08:00
|
|
|
return;
|
|
|
|
|
2020-10-02 16:32:34 +08:00
|
|
|
changeHandler?.BeginChange();
|
|
|
|
|
2020-10-02 14:25:48 +08:00
|
|
|
var currentGroupItems = SelectedGroup.Value.ControlPoints.ToArray();
|
|
|
|
|
2021-01-04 15:38:15 +08:00
|
|
|
Beatmap.ControlPointInfo.RemoveGroup(SelectedGroup.Value);
|
2020-10-02 14:25:48 +08:00
|
|
|
|
|
|
|
foreach (var cp in currentGroupItems)
|
2021-01-04 15:38:15 +08:00
|
|
|
Beatmap.ControlPointInfo.Add(time, cp);
|
2020-10-02 14:25:48 +08:00
|
|
|
|
2020-10-08 05:10:28 +08:00
|
|
|
// the control point might not necessarily exist yet, if currentGroupItems was empty.
|
2021-01-04 15:38:15 +08:00
|
|
|
SelectedGroup.Value = Beatmap.ControlPointInfo.GroupAt(time, true);
|
2020-10-02 16:32:34 +08:00
|
|
|
|
|
|
|
changeHandler?.EndChange();
|
2020-10-02 14:25:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|