mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:12:56 +08:00
Rewrite visualisation piece to bind once and without potential event leak
This commit is contained in:
parent
904c76e437
commit
abca13eb6c
@ -27,9 +27,9 @@ namespace osu.Game.Tests.Visual.Editing
|
||||
public void TestScenePreviewTimeline()
|
||||
{
|
||||
AddStep("set preview time to -1", () => EditorBeatmap.PreviewTime.Value = -1);
|
||||
AddAssert("preview time line should not show", () => Editor.ChildrenOfType<PreviewTimePart>().Single().Alpha == 0);
|
||||
AddAssert("preview time line should not show", () => !Editor.ChildrenOfType<PreviewTimePart>().Single().Children.Any());
|
||||
AddStep("set preview time to 1000", () => EditorBeatmap.PreviewTime.Value = 1000);
|
||||
AddAssert("preview time line should show", () => Editor.ChildrenOfType<PreviewTimePart>().Single().Alpha == 1);
|
||||
AddAssert("preview time line should show", () => Editor.ChildrenOfType<PreviewTimePart>().Single().Children.Single().Alpha == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,24 +10,28 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts
|
||||
{
|
||||
public partial class PreviewTimePart : TimelinePart
|
||||
{
|
||||
private readonly BindableInt previewTime = new BindableInt();
|
||||
|
||||
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
||||
{
|
||||
base.LoadBeatmap(beatmap);
|
||||
Add(new PreviewTimeVisualisation(beatmap));
|
||||
beatmap.PreviewTime.BindValueChanged(s =>
|
||||
|
||||
previewTime.UnbindAll();
|
||||
previewTime.BindTo(beatmap.PreviewTime);
|
||||
previewTime.BindValueChanged(t =>
|
||||
{
|
||||
Alpha = s.NewValue == -1 ? 0 : 1;
|
||||
Clear();
|
||||
|
||||
if (t.NewValue >= 0)
|
||||
Add(new PreviewTimeVisualisation(t.NewValue));
|
||||
}, true);
|
||||
}
|
||||
|
||||
private partial class PreviewTimeVisualisation : PointVisualisation
|
||||
{
|
||||
private readonly BindableInt previewTime = new BindableInt();
|
||||
|
||||
public PreviewTimeVisualisation(EditorBeatmap editorBeatmap)
|
||||
public PreviewTimeVisualisation(double time)
|
||||
: base(time)
|
||||
{
|
||||
previewTime.BindTo(editorBeatmap.PreviewTime);
|
||||
previewTime.BindValueChanged(s => X = s.NewValue, true);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
|
Loading…
Reference in New Issue
Block a user