2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2017-09-26 14:44:40 +08:00
|
|
|
using System;
|
2018-05-23 16:37:39 +08:00
|
|
|
using osu.Framework.Allocation;
|
2020-09-24 20:05:29 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2017-09-26 14:44:40 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Game.Beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2017-09-26 14:44:40 +08:00
|
|
|
namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
|
|
|
|
{
|
2020-01-20 23:53:59 +08:00
|
|
|
public class TimelinePart : TimelinePart<Drawable>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-26 14:44:40 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Represents a part of the summary timeline..
|
|
|
|
/// </summary>
|
2020-01-20 23:53:59 +08:00
|
|
|
public class TimelinePart<T> : Container<T> where T : Drawable
|
2017-09-26 14:44:40 +08:00
|
|
|
{
|
2021-01-25 17:43:36 +08:00
|
|
|
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
protected EditorBeatmap EditorBeatmap { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-09-24 20:05:29 +08:00
|
|
|
protected readonly IBindable<Track> Track = new Bindable<Track>();
|
|
|
|
|
2020-01-20 23:53:59 +08:00
|
|
|
private readonly Container<T> content;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2020-01-20 23:53:59 +08:00
|
|
|
protected override Container<T> Content => content;
|
2019-12-05 19:12:25 +08:00
|
|
|
|
2020-01-20 23:53:59 +08:00
|
|
|
public TimelinePart(Container<T> content = null)
|
2017-09-26 14:44:40 +08:00
|
|
|
{
|
2020-01-20 23:53:59 +08:00
|
|
|
AddInternal(this.content = content ?? new Container<T> { RelativeSizeAxes = Axes.Both });
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2022-06-24 20:25:23 +08:00
|
|
|
beatmap.ValueChanged += _ =>
|
2017-09-26 14:44:40 +08:00
|
|
|
{
|
2017-09-27 11:07:43 +08:00
|
|
|
updateRelativeChildSize();
|
2017-09-26 14:44:40 +08:00
|
|
|
};
|
2020-09-24 20:05:29 +08:00
|
|
|
|
|
|
|
Track.ValueChanged += _ => updateRelativeChildSize();
|
2017-09-26 14:44:40 +08:00
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-05-23 16:37:39 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2020-09-24 20:05:29 +08:00
|
|
|
private void load(IBindable<WorkingBeatmap> beatmap, EditorClock clock)
|
2018-05-23 16:37:39 +08:00
|
|
|
{
|
2021-01-25 17:43:36 +08:00
|
|
|
this.beatmap.BindTo(beatmap);
|
|
|
|
LoadBeatmap(EditorBeatmap);
|
|
|
|
|
2020-09-24 20:05:29 +08:00
|
|
|
Track.BindTo(clock.Track);
|
2018-05-23 16:37:39 +08:00
|
|
|
}
|
|
|
|
|
2017-09-27 11:07:43 +08:00
|
|
|
private void updateRelativeChildSize()
|
|
|
|
{
|
2022-11-03 12:59:22 +08:00
|
|
|
// If the track is not loaded, assign a default sane length otherwise relative positioning becomes meaningless.
|
|
|
|
double trackLength = beatmap.Value.Track.IsLoaded ? beatmap.Value.Track.Length : 60000;
|
|
|
|
content.RelativeChildSize = new Vector2((float)Math.Max(1, trackLength), 1);
|
|
|
|
|
|
|
|
// The track may not be loaded completely (only has a length once it is).
|
2021-01-25 17:43:36 +08:00
|
|
|
if (!beatmap.Value.Track.IsLoaded)
|
2017-09-27 11:07:43 +08:00
|
|
|
Schedule(updateRelativeChildSize);
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2021-01-25 17:43:36 +08:00
|
|
|
protected virtual void LoadBeatmap(EditorBeatmap beatmap)
|
2017-09-26 16:56:16 +08:00
|
|
|
{
|
2020-01-20 23:53:59 +08:00
|
|
|
content.Clear();
|
2017-09-26 16:56:16 +08:00
|
|
|
}
|
2017-09-26 14:44:40 +08:00
|
|
|
}
|
|
|
|
}
|