1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 18:02:55 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/GroupSection.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

121 lines
3.7 KiB
C#
Raw Normal View History

// 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 partial class GroupSection : CompositeDrawable
{
2023-01-14 07:23:21 +08:00
private LabelledTextBox textBox = null!;
2023-01-14 07:23:21 +08:00
private OsuButton button = null!;
[Resolved]
2023-01-14 07:23:21 +08:00
protected Bindable<ControlPointGroup> SelectedGroup { get; private set; } = null!;
[Resolved]
2023-01-14 07:23:21 +08:00
protected EditorBeatmap Beatmap { get; private set; } = null!;
[Resolved]
2023-01-14 07:23:21 +08:00
private EditorClock clock { get; set; } = null!;
2023-01-14 07:23:21 +08:00
[Resolved]
private IEditorChangeHandler? changeHandler { get; set; }
2020-10-02 16:32:34 +08:00
[BackgroundDependencyLoader]
private void load()
{
RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Padding = new MarginPadding(10) { Bottom = 0 };
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"
},
button = new RoundedButton
{
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;
if (double.TryParse(sender.Text, out double newTime))
{
changeSelectedGroupTime(newTime);
}
2020-10-02 14:33:33 +08:00
else
{
SelectedGroup.TriggerChange();
}
};
SelectedGroup.BindValueChanged(group =>
{
if (group.NewValue == null)
{
textBox.Text = string.Empty;
// cannot use textBox.Current.Disabled due to https://github.com/ppy/osu-framework/issues/3919
textBox.ReadOnly = true;
button.Enabled.Value = false;
return;
}
textBox.ReadOnly = false;
button.Enabled.Value = true;
textBox.Text = $"{group.NewValue.Time:n0}";
}, true);
}
private void changeSelectedGroupTime(in double time)
{
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();
var currentGroupItems = SelectedGroup.Value.ControlPoints.ToArray();
Beatmap.ControlPointInfo.RemoveGroup(SelectedGroup.Value);
foreach (var cp in currentGroupItems)
Beatmap.ControlPointInfo.Add(time, cp);
// the control point might not necessarily exist yet, if currentGroupItems was empty.
SelectedGroup.Value = Beatmap.ControlPointInfo.GroupAt(time, true);
2020-10-02 16:32:34 +08:00
changeHandler?.EndChange();
}
}
}