2020-10-01 16:54:54 +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.
|
|
|
|
|
|
2024-03-14 04:08:00 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2020-10-01 16:54:54 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2024-03-14 04:08:00 +08:00
|
|
|
|
using osu.Framework.Caching;
|
2020-10-01 16:54:54 +08:00
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The part of the timeline that displays the control points.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class TimelineControlPointDisplay : TimelinePart<TimelineControlPointGroup>
|
|
|
|
|
{
|
2024-03-14 04:08:00 +08:00
|
|
|
|
[Resolved]
|
2024-03-19 01:38:19 +08:00
|
|
|
|
private Timeline timeline { get; set; } = null!;
|
2024-03-14 04:08:00 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The visible time/position range of the timeline.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private (float min, float max) visibleRange = (float.MinValue, float.MaxValue);
|
|
|
|
|
|
|
|
|
|
private readonly Cached groupCache = new Cached();
|
|
|
|
|
|
2020-11-04 14:29:14 +08:00
|
|
|
|
private readonly IBindableList<ControlPointGroup> controlPointGroups = new BindableList<ControlPointGroup>();
|
2020-10-01 16:54:54 +08:00
|
|
|
|
|
2021-01-25 17:43:36 +08:00
|
|
|
|
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
2020-10-01 16:54:54 +08:00
|
|
|
|
{
|
|
|
|
|
base.LoadBeatmap(beatmap);
|
|
|
|
|
|
2020-11-08 03:59:41 +08:00
|
|
|
|
controlPointGroups.UnbindAll();
|
2021-01-25 17:43:36 +08:00
|
|
|
|
controlPointGroups.BindTo(beatmap.ControlPointInfo.Groups);
|
2024-03-20 12:52:54 +08:00
|
|
|
|
controlPointGroups.BindCollectionChanged((_, _) => groupCache.Invalidate(), true);
|
2024-03-14 04:08:00 +08:00
|
|
|
|
}
|
2020-10-01 16:54:54 +08:00
|
|
|
|
|
2024-03-14 04:08:00 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2022-12-16 17:16:26 +08:00
|
|
|
|
|
2024-03-19 01:38:19 +08:00
|
|
|
|
if (DrawWidth <= 0) return;
|
2024-03-14 04:08:00 +08:00
|
|
|
|
|
|
|
|
|
(float, float) newRange = (
|
|
|
|
|
(ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopLeft).X - TopPointPiece.WIDTH) / DrawWidth * Content.RelativeChildSize.X,
|
|
|
|
|
(ToLocalSpace(timeline.ScreenSpaceDrawQuad.TopRight).X) / DrawWidth * Content.RelativeChildSize.X);
|
2020-10-01 16:54:54 +08:00
|
|
|
|
|
2024-03-14 04:08:00 +08:00
|
|
|
|
if (visibleRange != newRange)
|
|
|
|
|
{
|
|
|
|
|
visibleRange = newRange;
|
2024-03-20 12:52:54 +08:00
|
|
|
|
groupCache.Invalidate();
|
2024-03-14 04:08:00 +08:00
|
|
|
|
}
|
2022-12-16 17:16:26 +08:00
|
|
|
|
|
2024-03-14 04:08:00 +08:00
|
|
|
|
if (!groupCache.IsValid)
|
2024-03-20 12:52:54 +08:00
|
|
|
|
{
|
2024-03-14 04:08:00 +08:00
|
|
|
|
recreateDrawableGroups();
|
2024-03-20 12:52:54 +08:00
|
|
|
|
groupCache.Validate();
|
|
|
|
|
}
|
2024-03-14 04:08:00 +08:00
|
|
|
|
}
|
2020-10-01 16:54:54 +08:00
|
|
|
|
|
2024-03-14 04:08:00 +08:00
|
|
|
|
private void recreateDrawableGroups()
|
|
|
|
|
{
|
|
|
|
|
// Remove groups outside the visible range
|
2024-03-20 12:52:54 +08:00
|
|
|
|
foreach (TimelineControlPointGroup drawableGroup in this)
|
2024-03-14 04:08:00 +08:00
|
|
|
|
{
|
2024-03-19 01:46:38 +08:00
|
|
|
|
if (!shouldBeVisible(drawableGroup.Group))
|
|
|
|
|
drawableGroup.Expire();
|
2024-03-14 04:08:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add remaining ones
|
2024-03-16 17:26:56 +08:00
|
|
|
|
for (int i = 0; i < controlPointGroups.Count; i++)
|
2024-03-14 04:08:00 +08:00
|
|
|
|
{
|
2024-03-16 17:26:56 +08:00
|
|
|
|
var group = controlPointGroups[i];
|
|
|
|
|
|
2024-03-14 04:08:00 +08:00
|
|
|
|
if (!shouldBeVisible(group))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
bool alreadyVisible = false;
|
|
|
|
|
|
|
|
|
|
foreach (var g in this)
|
|
|
|
|
{
|
|
|
|
|
if (ReferenceEquals(g.Group, group))
|
|
|
|
|
{
|
|
|
|
|
alreadyVisible = true;
|
2020-10-01 16:54:54 +08:00
|
|
|
|
break;
|
2024-03-14 04:08:00 +08:00
|
|
|
|
}
|
2020-10-01 16:54:54 +08:00
|
|
|
|
}
|
2024-03-14 04:08:00 +08:00
|
|
|
|
|
|
|
|
|
if (alreadyVisible)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
Add(new TimelineControlPointGroup(group));
|
|
|
|
|
}
|
2020-10-01 16:54:54 +08:00
|
|
|
|
}
|
2024-03-14 04:08:00 +08:00
|
|
|
|
|
|
|
|
|
private bool shouldBeVisible(ControlPointGroup group) => group.Time >= visibleRange.min && group.Time <= visibleRange.max;
|
2020-10-01 16:54:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|