1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 14:52:55 +08:00
osu-lazer/osu.Game/Screens/Edit/Timing/TimingScreen.cs

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

239 lines
9.0 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;
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;
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;
using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Overlays;
2019-10-22 20:50:21 +08:00
using osuTK;
2019-10-09 15:06:16 +08:00
namespace osu.Game.Screens.Edit.Timing
{
public partial class TimingScreen : EditorScreenWithTimeline
{
2019-10-11 17:46:05 +08:00
[Cached]
public readonly Bindable<ControlPointGroup> SelectedGroup = new Bindable<ControlPointGroup>();
2019-10-11 17:46:05 +08:00
public TimingScreen()
: base(EditorScreenMode.Timing)
{
}
protected override Drawable CreateMainContent() => new GridContainer
2019-10-09 15:06:16 +08:00
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
2019-10-09 15:06:16 +08:00
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 350),
},
Content = new[]
{
new Drawable[]
2019-10-09 15:06:16 +08:00
{
new ControlPointList(),
new ControlPointSettings(),
2019-10-09 15:06:16 +08:00
},
}
};
2019-10-09 15:06:16 +08:00
public partial class ControlPointList : CompositeDrawable
{
private OsuButton deleteButton = null!;
private ControlPointTable table = null!;
private OsuScrollContainer scroll = null!;
private RoundedButton addButton = null!;
2019-10-27 15:13:24 +08:00
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
2019-10-27 15:13:24 +08:00
[Resolved]
private EditorClock clock { get; set; } = null!;
2019-10-22 20:50:21 +08:00
2019-10-09 15:06:16 +08:00
[Resolved]
protected EditorBeatmap Beatmap { get; private set; } = null!;
2019-10-09 15:06:16 +08:00
2019-10-22 20:50:21 +08:00
[Resolved]
private Bindable<ControlPointGroup?> selectedGroup { get; set; } = null!;
2019-10-22 20:50:21 +08:00
[Resolved]
private IEditorChangeHandler? changeHandler { get; set; }
2019-10-09 15:06:16 +08:00
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colours)
2019-10-09 15:06:16 +08:00
{
RelativeSizeAxes = Axes.Both;
const float margins = 10;
2019-10-09 15:06:16 +08:00
InternalChildren = new Drawable[]
{
new Box
{
Colour = colours.Background4,
2019-10-09 15:06:16 +08:00
RelativeSizeAxes = Axes.Both,
},
new Box
{
Colour = colours.Background3,
RelativeSizeAxes = Axes.Y,
Width = ControlPointTable.TIMING_COLUMN_WIDTH + margins,
},
scroll = new OsuScrollContainer
2019-10-09 15:06:16 +08:00
{
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,
Margin = new MarginPadding(margins),
2019-10-22 20:50:21 +08:00
Spacing = new Vector2(5),
Children = new Drawable[]
{
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,
},
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();
selectedGroup.BindValueChanged(selected =>
{
deleteButton.Enabled.Value = selected.NewValue != null;
addButton.Text = selected.NewValue != null
2022-11-30 02:22:07 +08:00
? "+ Clone to current time"
: "+ Add at current time";
}, true);
2019-10-27 15:13:24 +08:00
controlPointGroups.BindTo(Beatmap.ControlPointInfo.Groups);
2022-06-24 20:25:23 +08:00
controlPointGroups.BindCollectionChanged((_, _) =>
{
table.ControlGroups = controlPointGroups;
changeHandler?.SaveState();
}, true);
2022-11-27 11:23:08 +08:00
table.OnRowSelected += drawable => scroll.ScrollIntoView(drawable);
}
2019-10-27 15:13:24 +08:00
protected override bool OnClick(ClickEvent e)
{
selectedGroup.Value = null;
return true;
}
protected override void Update()
{
base.Update();
trackActivePoint();
addButton.Enabled.Value = clock.CurrentTimeAccurate != selectedGroup.Value?.Time;
}
private Type? trackedType;
/// <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.
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();
}
if (trackedType != null)
{
// 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
.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;
}
}
2019-10-22 20:50:21 +08:00
private void delete()
{
2019-10-27 15:13:24 +08:00
if (selectedGroup.Value == null)
return;
Beatmap.ControlPointInfo.RemoveGroup(selectedGroup.Value);
selectedGroup.Value = Beatmap.ControlPointInfo.Groups.FirstOrDefault(g => g.Time >= clock.CurrentTime);
2019-10-22 20:50:21 +08:00
}
private void addNew()
{
bool isFirstControlPoint = !Beatmap.ControlPointInfo.TimingPoints.Any();
var group = Beatmap.ControlPointInfo.GroupAt(clock.CurrentTime, true);
if (isFirstControlPoint)
group.Add(new TimingControlPoint());
else
{
// Try and create matching types from the currently selected control point.
var selected = selectedGroup.Value;
2022-06-20 15:53:03 +08:00
if (selected != null && !ReferenceEquals(selected, group))
{
foreach (var controlPoint in selected.ControlPoints)
{
group.Add(controlPoint.DeepClone());
}
}
}
selectedGroup.Value = group;
2019-10-22 20:50:21 +08:00
}
2019-10-09 15:06:16 +08:00
}
}
}