1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-07 06:38:27 +08:00

71 lines
2.1 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 18:19:50 +09:00
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
2019-02-21 19:04:31 +09:00
using osu.Framework.Bindables;
2018-11-20 16:51:59 +09:00
using osuTK;
2018-04-13 18:19:50 +09:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
{
public class TimelinePart : TimelinePart<Drawable>
{
}
2018-04-13 18:19:50 +09:00
/// <summary>
/// Represents a part of the summary timeline..
/// </summary>
public class TimelinePart<T> : Container<T> where T : Drawable
2018-04-13 18:19:50 +09:00
{
protected readonly IBindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
2018-04-13 18:19:50 +09:00
protected readonly IBindable<Track> Track = new Bindable<Track>();
private readonly Container<T> content;
2018-04-13 18:19:50 +09:00
protected override Container<T> Content => content;
2019-12-05 20:12:25 +09:00
public TimelinePart(Container<T> content = null)
2018-04-13 18:19:50 +09:00
{
AddInternal(this.content = content ?? new Container<T> { RelativeSizeAxes = Axes.Both });
2018-04-13 18:19:50 +09:00
Beatmap.ValueChanged += b =>
2018-04-13 18:19:50 +09:00
{
updateRelativeChildSize();
LoadBeatmap(b.NewValue);
2018-04-13 18:19:50 +09:00
};
Track.ValueChanged += _ => updateRelativeChildSize();
2018-04-13 18:19:50 +09:00
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, EditorClock clock)
{
Beatmap.BindTo(beatmap);
Track.BindTo(clock.Track);
}
2018-04-13 18:19:50 +09:00
private void updateRelativeChildSize()
{
// the track may not be loaded completely (only has a length once it is).
if (!Beatmap.Value.Track.IsLoaded)
{
content.RelativeChildSize = Vector2.One;
2018-04-13 18:19:50 +09:00
Schedule(updateRelativeChildSize);
return;
}
content.RelativeChildSize = new Vector2((float)Math.Max(1, Beatmap.Value.Track.Length), 1);
2018-04-13 18:19:50 +09:00
}
protected virtual void LoadBeatmap(WorkingBeatmap beatmap)
{
content.Clear();
2018-04-13 18:19:50 +09:00
}
}
}