1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 13:02:56 +08:00
osu-lazer/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/TimelinePart.cs

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