1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 13:17:26 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/TimelinePart.cs

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

73 lines
2.3 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.
2018-04-13 17:19:50 +08:00
using System;
using osu.Framework.Allocation;
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;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
{
public partial class TimelinePart : TimelinePart<Drawable>
{
}
/// <summary>
/// Represents a part of the summary timeline..
/// </summary>
public partial class TimelinePart<T> : Container<T> where T : Drawable
{
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
[Resolved]
protected EditorBeatmap EditorBeatmap { get; private set; } = null!;
2018-04-13 17:19:50 +08:00
protected readonly IBindable<Track> Track = new Bindable<Track>();
private readonly Container<T> content;
2018-04-13 17:19:50 +08:00
protected override Container<T> Content => content;
2019-12-05 19:12:25 +08:00
public TimelinePart(Container<T>? content = null)
{
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 += _ =>
{
updateRelativeChildSize();
};
Track.ValueChanged += _ => updateRelativeChildSize();
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, EditorClock clock)
{
this.beatmap.BindTo(beatmap);
LoadBeatmap(EditorBeatmap);
Track.BindTo(clock.Track);
}
private void updateRelativeChildSize()
{
// 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).
if (!beatmap.Value.Track.IsLoaded)
Schedule(updateRelativeChildSize);
}
2018-04-13 17:19:50 +08:00
protected virtual void LoadBeatmap(EditorBeatmap beatmap)
{
content.Clear();
}
}
}