diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/BreakPart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/BreakPart.cs index ed42ade490fb..100f37fd2702 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/BreakPart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/BreakPart.cs @@ -4,6 +4,7 @@ using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Graphics.Pooling; using osu.Framework.Graphics.Shapes; using osu.Game.Beatmaps.Timing; using osu.Game.Graphics; @@ -17,32 +18,54 @@ public partial class BreakPart : TimelinePart { private readonly BindableList breaks = new BindableList(); + private DrawablePool pool = null!; + + [BackgroundDependencyLoader] + private void load() + { + AddInternal(pool = new DrawablePool(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(); - foreach (var breakPeriod in beatmap.Breaks) - Add(new BreakVisualisation(breakPeriod)); + Clear(disposeChildren: false); + foreach (var breakPeriod in breaks) + Add(pool.Get(v => v.BreakPeriod = breakPeriod)); }, true); } - private partial class BreakVisualisation : Circle + private partial class BreakVisualisation : PoolableDrawable { - public BreakVisualisation(BreakPeriod breakPeriod) + public BreakPeriod BreakPeriod { - RelativePositionAxes = Axes.X; - RelativeSizeAxes = Axes.Both; - X = (float)breakPeriod.StartTime; - Width = (float)breakPeriod.Duration; + set + { + X = (float)value.StartTime; + Width = (float)value.Duration; + } } [BackgroundDependencyLoader] - private void load(OsuColour colours) => Colour = colours.Gray7; + private void load(OsuColour colours) + { + RelativePositionAxes = Axes.X; + RelativeSizeAxes = Axes.Both; + + InternalChild = new Circle { RelativeSizeAxes = Axes.Both }; + Colour = colours.Gray7; + } } } }