2019-10-08 13:23:13 +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.
|
|
|
|
|
|
2022-06-02 17:33:09 +08:00
|
|
|
|
using System;
|
2019-10-27 15:30:05 +08:00
|
|
|
|
using System.Linq;
|
2019-10-09 15:06:16 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-06-02 17:18:18 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-10-11 17:46:05 +08:00
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2019-10-09 15:06:16 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-10-22 20:50:21 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-05-24 15:02:08 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterfaceV2;
|
2021-04-19 13:11:26 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2019-10-22 20:50:21 +08:00
|
|
|
|
using osuTK;
|
2019-10-09 15:06:16 +08:00
|
|
|
|
|
2019-10-08 13:23:13 +08:00
|
|
|
|
namespace osu.Game.Screens.Edit.Timing
|
|
|
|
|
{
|
2022-05-24 15:15:24 +08:00
|
|
|
|
public class TimingScreen : EditorScreenWithTimeline
|
2019-10-08 13:23:13 +08:00
|
|
|
|
{
|
2019-10-11 17:46:05 +08:00
|
|
|
|
[Cached]
|
2022-05-31 14:00:30 +08:00
|
|
|
|
public readonly Bindable<ControlPointGroup> SelectedGroup = new Bindable<ControlPointGroup>();
|
2019-10-11 17:46:05 +08:00
|
|
|
|
|
2020-09-24 16:03:54 +08:00
|
|
|
|
public TimingScreen()
|
|
|
|
|
: base(EditorScreenMode.Timing)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-24 15:15:24 +08:00
|
|
|
|
protected override Drawable CreateMainContent() => new GridContainer
|
2019-10-09 15:06:16 +08:00
|
|
|
|
{
|
2022-05-24 15:15:24 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColumnDimensions = new[]
|
2019-10-09 15:06:16 +08:00
|
|
|
|
{
|
2022-05-24 15:15:24 +08:00
|
|
|
|
new Dimension(),
|
|
|
|
|
new Dimension(GridSizeMode.Absolute, 350),
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
2019-10-09 15:06:16 +08:00
|
|
|
|
{
|
2022-05-24 15:15:24 +08:00
|
|
|
|
new ControlPointList(),
|
|
|
|
|
new ControlPointSettings(),
|
2019-10-09 15:06:16 +08:00
|
|
|
|
},
|
2022-05-24 15:15:24 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2020-09-30 15:39:27 +08:00
|
|
|
|
|
2019-10-09 15:06:16 +08:00
|
|
|
|
public class ControlPointList : CompositeDrawable
|
2019-10-08 13:23:13 +08:00
|
|
|
|
{
|
2019-10-22 20:50:21 +08:00
|
|
|
|
private OsuButton deleteButton;
|
2019-10-27 15:13:24 +08:00
|
|
|
|
private ControlPointTable table;
|
|
|
|
|
|
2020-11-04 14:29:14 +08:00
|
|
|
|
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
|
2019-10-27 15:13:24 +08:00
|
|
|
|
|
2022-06-02 17:28:13 +08:00
|
|
|
|
private RoundedButton addButton;
|
|
|
|
|
|
2019-10-27 15:13:24 +08:00
|
|
|
|
[Resolved]
|
2020-05-22 18:49:49 +08:00
|
|
|
|
private EditorClock clock { get; set; }
|
2019-10-22 20:50:21 +08:00
|
|
|
|
|
2019-10-09 15:06:16 +08:00
|
|
|
|
[Resolved]
|
2021-01-04 15:38:15 +08:00
|
|
|
|
protected EditorBeatmap Beatmap { get; private set; }
|
2019-10-09 15:06:16 +08:00
|
|
|
|
|
2019-10-22 20:50:21 +08:00
|
|
|
|
[Resolved]
|
2019-10-27 15:13:24 +08:00
|
|
|
|
private Bindable<ControlPointGroup> selectedGroup { get; set; }
|
2019-10-22 20:50:21 +08:00
|
|
|
|
|
2020-10-02 16:15:58 +08:00
|
|
|
|
[Resolved(canBeNull: true)]
|
|
|
|
|
private IEditorChangeHandler changeHandler { get; set; }
|
|
|
|
|
|
2019-10-09 15:06:16 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-04-19 13:11:26 +08:00
|
|
|
|
private void load(OverlayColourProvider colours)
|
2019-10-09 15:06:16 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2021-04-19 17:25:30 +08:00
|
|
|
|
const float margins = 10;
|
2019-10-09 15:06:16 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
2022-05-24 15:15:24 +08:00
|
|
|
|
Colour = colours.Background4,
|
2019-10-09 15:06:16 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2021-04-19 17:25:30 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
2022-05-24 15:15:24 +08:00
|
|
|
|
Colour = colours.Background3,
|
2021-04-19 17:25:30 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Width = ControlPointTable.TIMING_COLUMN_WIDTH + margins,
|
|
|
|
|
},
|
2019-10-09 15:06:16 +08:00
|
|
|
|
new OsuScrollContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-10-27 15:13:24 +08:00
|
|
|
|
Child = table = new ControlPointTable(),
|
2019-10-22 20:50:21 +08:00
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
2021-04-19 17:25:30 +08:00
|
|
|
|
Margin = new MarginPadding(margins),
|
2019-10-22 20:50:21 +08:00
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2022-05-24 15:02:08 +08:00
|
|
|
|
deleteButton = new RoundedButton
|
2019-10-22 20:50:21 +08:00
|
|
|
|
{
|
|
|
|
|
Text = "-",
|
|
|
|
|
Size = new Vector2(30, 30),
|
|
|
|
|
Action = delete,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
},
|
2022-06-02 17:28:13 +08:00
|
|
|
|
addButton = new RoundedButton
|
2019-10-22 20:50:21 +08:00
|
|
|
|
{
|
|
|
|
|
Action = addNew,
|
2021-04-19 12:15:24 +08:00
|
|
|
|
Size = new Vector2(160, 30),
|
2019-10-22 20:50:21 +08:00
|
|
|
|
Anchor = Anchor.BottomRight,
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-09 15:06:16 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2019-10-22 20:50:21 +08:00
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
2022-06-02 17:28:13 +08:00
|
|
|
|
selectedGroup.BindValueChanged(selected =>
|
|
|
|
|
{
|
|
|
|
|
deleteButton.Enabled.Value = selected.NewValue != null;
|
|
|
|
|
|
|
|
|
|
addButton.Text = selected.NewValue != null
|
|
|
|
|
? "+ Clone to current time"
|
|
|
|
|
: "+ Add at current time";
|
|
|
|
|
}, true);
|
2019-10-27 15:13:24 +08:00
|
|
|
|
|
2021-01-04 15:38:15 +08:00
|
|
|
|
controlPointGroups.BindTo(Beatmap.ControlPointInfo.Groups);
|
2020-11-04 14:29:14 +08:00
|
|
|
|
controlPointGroups.BindCollectionChanged((sender, args) =>
|
2020-09-30 15:02:22 +08:00
|
|
|
|
{
|
2020-11-04 14:29:14 +08:00
|
|
|
|
table.ControlGroups = controlPointGroups;
|
2020-11-14 21:48:48 +08:00
|
|
|
|
changeHandler?.SaveState();
|
2020-09-30 15:02:22 +08:00
|
|
|
|
}, true);
|
|
|
|
|
}
|
2019-10-27 15:13:24 +08:00
|
|
|
|
|
2022-06-02 17:18:18 +08:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
|
{
|
|
|
|
|
selectedGroup.Value = null;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 14:00:30 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
trackActivePoint();
|
2022-06-02 17:28:13 +08:00
|
|
|
|
|
|
|
|
|
addButton.Enabled.Value = clock.CurrentTimeAccurate != selectedGroup.Value?.Time;
|
2022-05-31 14:00:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-02 17:33:09 +08:00
|
|
|
|
private Type trackedType;
|
|
|
|
|
|
2022-05-31 14:00:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Given the user has selected a control point group, we want to track any group which is
|
|
|
|
|
/// active at the current point in time which matches the type the user has selected.
|
|
|
|
|
///
|
|
|
|
|
/// So if the user is currently looking at a timing point and seeks into the future, a
|
|
|
|
|
/// future timing point would be automatically selected if it is now the new "current" point.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void trackActivePoint()
|
|
|
|
|
{
|
|
|
|
|
// For simplicity only match on the first type of the active control point.
|
2022-06-02 17:33:09 +08:00
|
|
|
|
if (selectedGroup.Value == null)
|
|
|
|
|
trackedType = null;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// If the selected group only has one control point, update the tracking type.
|
|
|
|
|
if (selectedGroup.Value.ControlPoints.Count == 1)
|
|
|
|
|
trackedType = selectedGroup.Value?.ControlPoints.Single().GetType();
|
|
|
|
|
// If the selected group has more than one control point, choose the first as the tracking type
|
|
|
|
|
// if we don't already have a singular tracked type.
|
|
|
|
|
else if (trackedType == null)
|
|
|
|
|
trackedType = selectedGroup.Value?.ControlPoints.FirstOrDefault()?.GetType();
|
|
|
|
|
}
|
2022-05-31 14:00:30 +08:00
|
|
|
|
|
2022-06-02 17:33:09 +08:00
|
|
|
|
if (trackedType != null)
|
2022-05-31 14:00:30 +08:00
|
|
|
|
{
|
|
|
|
|
// We don't have an efficient way of looking up groups currently, only individual point types.
|
|
|
|
|
// To improve the efficiency of this in the future, we should reconsider the overall structure of ControlPointInfo.
|
|
|
|
|
|
|
|
|
|
// Find the next group which has the same type as the selected one.
|
2022-06-01 19:20:16 +08:00
|
|
|
|
var found = Beatmap.ControlPointInfo.Groups
|
2022-06-02 17:33:09 +08:00
|
|
|
|
.Where(g => g.ControlPoints.Any(cp => cp.GetType() == trackedType))
|
2022-06-01 19:20:16 +08:00
|
|
|
|
.LastOrDefault(g => g.Time <= clock.CurrentTimeAccurate);
|
|
|
|
|
|
|
|
|
|
if (found != null)
|
|
|
|
|
selectedGroup.Value = found;
|
2022-05-31 14:00:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-22 20:50:21 +08:00
|
|
|
|
private void delete()
|
|
|
|
|
{
|
2019-10-27 15:13:24 +08:00
|
|
|
|
if (selectedGroup.Value == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-01-04 15:38:15 +08:00
|
|
|
|
Beatmap.ControlPointInfo.RemoveGroup(selectedGroup.Value);
|
2019-10-27 15:30:05 +08:00
|
|
|
|
|
2021-01-04 15:38:15 +08:00
|
|
|
|
selectedGroup.Value = Beatmap.ControlPointInfo.Groups.FirstOrDefault(g => g.Time >= clock.CurrentTime);
|
2019-10-22 20:50:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addNew()
|
|
|
|
|
{
|
2022-05-31 20:49:32 +08:00
|
|
|
|
bool isFirstControlPoint = !Beatmap.ControlPointInfo.TimingPoints.Any();
|
|
|
|
|
|
|
|
|
|
var group = Beatmap.ControlPointInfo.GroupAt(clock.CurrentTime, true);
|
|
|
|
|
|
|
|
|
|
if (isFirstControlPoint)
|
|
|
|
|
group.Add(new TimingControlPoint());
|
2022-05-31 20:49:47 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Try and create matching types from the currently selected control point.
|
|
|
|
|
var selected = selectedGroup.Value;
|
|
|
|
|
|
2022-06-02 17:14:26 +08:00
|
|
|
|
if (selected != null && selected != group)
|
2022-05-31 20:49:47 +08:00
|
|
|
|
{
|
|
|
|
|
foreach (var controlPoint in selected.ControlPoints)
|
|
|
|
|
{
|
2022-06-01 09:47:45 +08:00
|
|
|
|
group.Add(controlPoint.DeepClone());
|
2022-05-31 20:49:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-05-31 20:49:32 +08:00
|
|
|
|
|
|
|
|
|
selectedGroup.Value = group;
|
2019-10-22 20:50:21 +08:00
|
|
|
|
}
|
2019-10-09 15:06:16 +08:00
|
|
|
|
}
|
2019-10-08 13:23:13 +08:00
|
|
|
|
}
|
|
|
|
|
}
|