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

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

80 lines
2.4 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 osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Pooling;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Beatmaps.Timing;
using osu.Game.Extensions;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
{
/// <summary>
/// The part of the timeline that displays breaks in the song.
/// </summary>
public partial class BreakPart : TimelinePart
{
private readonly BindableList<BreakPeriod> breaks = new BindableList<BreakPeriod>();
private DrawablePool<BreakVisualisation> pool = null!;
[BackgroundDependencyLoader]
private void load()
{
AddInternal(pool = new DrawablePool<BreakVisualisation>(10));
}
protected override void LoadBeatmap(EditorBeatmap beatmap)
{
base.LoadBeatmap(beatmap);
breaks.UnbindAll();
breaks.BindTo(beatmap.Breaks);
}
protected override void LoadComplete()
{
base.LoadComplete();
breaks.BindCollectionChanged((_, _) =>
{
Clear(disposeChildren: false);
foreach (var breakPeriod in breaks)
Add(pool.Get(v => v.BreakPeriod = breakPeriod));
}, true);
}
2018-04-13 17:19:50 +08:00
private partial class BreakVisualisation : PoolableDrawable, IHasTooltip
{
private BreakPeriod breakPeriod;
public BreakPeriod BreakPeriod
{
set
{
breakPeriod = value;
X = (float)value.StartTime;
Width = (float)value.Duration;
}
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
RelativePositionAxes = Axes.X;
RelativeSizeAxes = Axes.Both;
InternalChild = new Circle { RelativeSizeAxes = Axes.Both };
Colour = colours.Gray6;
}
public LocalisableString TooltipText => $"{breakPeriod.StartTime.ToEditorFormattedString()} - {breakPeriod.EndTime.ToEditorFormattedString()} break time";
}
}
}