mirror of
https://github.com/ppy/osu.git
synced 2025-01-21 08:52:54 +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()
|
public void TestScenePreviewTimeline()
|
||||||
{
|
{
|
||||||
AddStep("set preview time to -1", () => EditorBeatmap.PreviewTime.Value = -1);
|
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);
|
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
|
public partial class PreviewTimePart : TimelinePart
|
||||||
{
|
{
|
||||||
|
private readonly BindableInt previewTime = new BindableInt();
|
||||||
|
|
||||||
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
protected override void LoadBeatmap(EditorBeatmap beatmap)
|
||||||
{
|
{
|
||||||
base.LoadBeatmap(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);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private partial class PreviewTimeVisualisation : PointVisualisation
|
private partial class PreviewTimeVisualisation : PointVisualisation
|
||||||
{
|
{
|
||||||
private readonly BindableInt previewTime = new BindableInt();
|
public PreviewTimeVisualisation(double time)
|
||||||
|
: base(time)
|
||||||
public PreviewTimeVisualisation(EditorBeatmap editorBeatmap)
|
|
||||||
{
|
{
|
||||||
previewTime.BindTo(editorBeatmap.PreviewTime);
|
|
||||||
previewTime.BindValueChanged(s => X = s.NewValue, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
|
Loading…
Reference in New Issue
Block a user