From c1647440641abe58d4ef1abf834e8f936d0877a2 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 16 Dec 2022 01:03:30 +0900 Subject: [PATCH 01/14] Add ability to set preview time --- .../Summary/Parts/PreviewTimePart.cs | 31 +++++++++++++++++++ .../Timelines/Summary/SummaryTimeline.cs | 8 +++++ osu.Game/Screens/Edit/Editor.cs | 12 +++++++ osu.Game/Screens/Edit/EditorBeatmap.cs | 5 +++ 4 files changed, 56 insertions(+) create mode 100644 osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs new file mode 100644 index 0000000000..a09d93fd5a --- /dev/null +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -0,0 +1,31 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Bindables; +using osu.Game.Graphics; +using osu.Game.Screens.Edit.Components.Timelines.Summary.Visualisations; + +namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts +{ + public partial class PreviewTimePart : TimelinePart + { + protected override void LoadBeatmap(EditorBeatmap beatmap) + { + base.LoadBeatmap(beatmap); + Add(new PreviewTimeVisualisation(beatmap.PreviewTime)); + } + + private partial class PreviewTimeVisualisation : PointVisualisation + { + public PreviewTimeVisualisation(BindableInt time) + : base(time.Value) + { + time.BindValueChanged(s => X = s.NewValue); + } + + [BackgroundDependencyLoader] + private void load(OsuColour colours) => Colour = colours.Lime; + } + } +} diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs index 7f762b9d50..41377bcb18 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs @@ -41,6 +41,14 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary RelativeSizeAxes = Axes.Both, Height = 0.35f }, + new PreviewTimePart + { + Anchor = Anchor.Centre, + Origin = Anchor.BottomCentre, + RelativeSizeAxes = Axes.Both, + Y = -10, + Height = 0.35f + }, new Container { Name = "centre line", diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index f3f2b8ad6b..16fff76ac7 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -322,6 +322,13 @@ namespace osu.Game.Screens.Edit State = { BindTarget = editorHitMarkers }, } } + }, + new MenuItem("Timing") + { + Items = new MenuItem[] + { + new EditorMenuItem("Set Current Position as Preview Point", MenuItemType.Standard, SetCurrectTimeAsPreview) + } } } }, @@ -801,6 +808,11 @@ namespace osu.Game.Screens.Edit protected void Redo() => changeHandler?.RestoreState(1); + protected void SetCurrectTimeAsPreview() + { + editorBeatmap.PreviewTime.Value = (int)clock.CurrentTime; + } + private void resetTrack(bool seekToStart = false) { Beatmap.Value.Track.Stop(); diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index e204b44db3..0a0557a992 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -86,6 +86,8 @@ namespace osu.Game.Screens.Edit [Resolved] private EditorClock editorClock { get; set; } + public BindableInt PreviewTime; + private readonly IBeatmapProcessor beatmapProcessor; private readonly Dictionary> startTimeBindables = new Dictionary>(); @@ -107,6 +109,9 @@ namespace osu.Game.Screens.Edit foreach (var obj in HitObjects) trackStartTime(obj); + + PreviewTime = new BindableInt(playableBeatmap.Metadata.PreviewTime); + PreviewTime.BindValueChanged(s => this.beatmapInfo.Metadata.PreviewTime = s.NewValue); } /// From 984f0b5fa961e5ed54dbbac132f39273fa2e7e8f Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 16 Dec 2022 01:35:54 +0900 Subject: [PATCH 02/14] Add test for set preview point --- .../Visual/Editing/TestScenePreviewTime.cs | 23 +++++++++++++++++++ osu.Game/Tests/Visual/EditorTestScene.cs | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs diff --git a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs new file mode 100644 index 0000000000..f95851f646 --- /dev/null +++ b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs @@ -0,0 +1,23 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using NUnit.Framework; +using osu.Game.Rulesets; +using osu.Game.Rulesets.Osu; + +namespace osu.Game.Tests.Visual.Editing +{ + public partial class TestScenePreviewTime : EditorTestScene + { + protected override Ruleset CreateEditorRuleset() => new OsuRuleset(); + + [Test] + public void TestSetPreviewTimingPoint() + { + AddStep("seek to 1000", () => EditorClock.Seek(1000)); + AddAssert("time is 1000", () => EditorClock.CurrentTime == 1000); + AddStep("set current time as preview point", () => Editor.SetCurrectTimeAsPreview()); + AddAssert("preview time is 1000", () => EditorBeatmap.PreviewTime.Value == 1000); + } + } +} diff --git a/osu.Game/Tests/Visual/EditorTestScene.cs b/osu.Game/Tests/Visual/EditorTestScene.cs index 833c12ba54..9944a561ca 100644 --- a/osu.Game/Tests/Visual/EditorTestScene.cs +++ b/osu.Game/Tests/Visual/EditorTestScene.cs @@ -102,6 +102,8 @@ namespace osu.Game.Tests.Visual public new void Redo() => base.Redo(); + public new void SetCurrectTimeAsPreview() => base.SetCurrectTimeAsPreview(); + public new bool Save() => base.Save(); public new void Cut() => base.Cut(); From f0246df1a9751da8826b215a69725f14571572f5 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 16 Dec 2022 09:58:58 +0900 Subject: [PATCH 03/14] only get; --- osu.Game/Screens/Edit/EditorBeatmap.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index 0a0557a992..1059654077 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -86,7 +86,7 @@ namespace osu.Game.Screens.Edit [Resolved] private EditorClock editorClock { get; set; } - public BindableInt PreviewTime; + public BindableInt PreviewTime { get; } private readonly IBeatmapProcessor beatmapProcessor; From 79e27c2d9d7dbeb1444de238a72686cb90c26053 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 16 Dec 2022 10:44:07 +0900 Subject: [PATCH 04/14] `PreviewTimePart` will not show if preview time is -1 --- .../Visual/Editing/TestScenePreviewTime.cs | 14 +++++++++++++- .../Timelines/Summary/Parts/PreviewTimePart.cs | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs index f95851f646..213eb4b175 100644 --- a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs +++ b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs @@ -1,9 +1,12 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System.Linq; using NUnit.Framework; +using osu.Framework.Testing; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu; +using osu.Game.Screens.Edit.Components.Timelines.Summary.Parts; namespace osu.Game.Tests.Visual.Editing { @@ -12,12 +15,21 @@ namespace osu.Game.Tests.Visual.Editing protected override Ruleset CreateEditorRuleset() => new OsuRuleset(); [Test] - public void TestSetPreviewTimingPoint() + public void TestSceneSetPreviewTimingPoint() { AddStep("seek to 1000", () => EditorClock.Seek(1000)); AddAssert("time is 1000", () => EditorClock.CurrentTime == 1000); AddStep("set current time as preview point", () => Editor.SetCurrectTimeAsPreview()); AddAssert("preview time is 1000", () => EditorBeatmap.PreviewTime.Value == 1000); } + + [Test] + public void TestScenePreviewTimeline() + { + AddStep("set preview time to -1", () => EditorBeatmap.PreviewTime.Value = -1); + AddAssert("preview time line should not show", () => Editor.ChildrenOfType().Single().Alpha == 0); + AddStep("set preview time to 1000", () => EditorBeatmap.PreviewTime.Value = 1000); + AddAssert("preview time line should show", () => Editor.ChildrenOfType().Single().Alpha == 1); + } } } diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs index a09d93fd5a..6149900fdc 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -14,6 +14,10 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts { base.LoadBeatmap(beatmap); Add(new PreviewTimeVisualisation(beatmap.PreviewTime)); + beatmap.PreviewTime.BindValueChanged(s => + { + Alpha = s.NewValue == -1 ? 0 : 1; + }, true); } private partial class PreviewTimeVisualisation : PointVisualisation From a4d28aff6d73d28515c5a158d8a8152ac6be7eef Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 16 Dec 2022 10:48:56 +0900 Subject: [PATCH 05/14] fix typo --- osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs | 2 +- osu.Game/Screens/Edit/Editor.cs | 4 ++-- osu.Game/Tests/Visual/EditorTestScene.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs index 213eb4b175..ad49f3ac0a 100644 --- a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs +++ b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs @@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual.Editing { AddStep("seek to 1000", () => EditorClock.Seek(1000)); AddAssert("time is 1000", () => EditorClock.CurrentTime == 1000); - AddStep("set current time as preview point", () => Editor.SetCurrectTimeAsPreview()); + AddStep("set current time as preview point", () => Editor.SetCurrentTimeAsPreview()); AddAssert("preview time is 1000", () => EditorBeatmap.PreviewTime.Value == 1000); } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 16fff76ac7..62bb7d3133 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -327,7 +327,7 @@ namespace osu.Game.Screens.Edit { Items = new MenuItem[] { - new EditorMenuItem("Set Current Position as Preview Point", MenuItemType.Standard, SetCurrectTimeAsPreview) + new EditorMenuItem("Set Current Position as Preview Point", MenuItemType.Standard, SetCurrentTimeAsPreview) } } } @@ -808,7 +808,7 @@ namespace osu.Game.Screens.Edit protected void Redo() => changeHandler?.RestoreState(1); - protected void SetCurrectTimeAsPreview() + protected void SetCurrentTimeAsPreview() { editorBeatmap.PreviewTime.Value = (int)clock.CurrentTime; } diff --git a/osu.Game/Tests/Visual/EditorTestScene.cs b/osu.Game/Tests/Visual/EditorTestScene.cs index 9944a561ca..9c8ac65add 100644 --- a/osu.Game/Tests/Visual/EditorTestScene.cs +++ b/osu.Game/Tests/Visual/EditorTestScene.cs @@ -102,7 +102,7 @@ namespace osu.Game.Tests.Visual public new void Redo() => base.Redo(); - public new void SetCurrectTimeAsPreview() => base.SetCurrectTimeAsPreview(); + public new void SetCurrentTimeAsPreview() => base.SetCurrentTimeAsPreview(); public new bool Save() => base.Save(); From a91da2284d27e5dc84c98b724cbbfae5cc4c2fad Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 30 Dec 2022 22:58:46 +0900 Subject: [PATCH 06/14] safe way to pass bindable --- .../Components/Timelines/Summary/Parts/PreviewTimePart.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs index 6149900fdc..b20f971086 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -22,10 +22,13 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts private partial class PreviewTimeVisualisation : PointVisualisation { + private BindableInt previewTime = new BindableInt(); + public PreviewTimeVisualisation(BindableInt time) : base(time.Value) { - time.BindValueChanged(s => X = s.NewValue); + previewTime.BindTo(time); + previewTime.BindValueChanged(s => X = s.NewValue); } [BackgroundDependencyLoader] From 23c485c763e91b4e7352138a0a94ec698afbb09c Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 30 Dec 2022 22:59:56 +0900 Subject: [PATCH 07/14] readonly --- .../Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs index b20f971086..bd34662969 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -22,7 +22,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts private partial class PreviewTimeVisualisation : PointVisualisation { - private BindableInt previewTime = new BindableInt(); + private readonly BindableInt previewTime = new BindableInt(); public PreviewTimeVisualisation(BindableInt time) : base(time.Value) From a82f1a6abd19bc8f79f1b3e72a45806d4c2c23ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 1 Jan 2023 18:48:56 +0100 Subject: [PATCH 08/14] Adjust method naming and copy --- osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs | 2 +- osu.Game/Screens/Edit/Editor.cs | 4 ++-- osu.Game/Tests/Visual/EditorTestScene.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs index ad49f3ac0a..d5aa71095b 100644 --- a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs +++ b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs @@ -19,7 +19,7 @@ namespace osu.Game.Tests.Visual.Editing { AddStep("seek to 1000", () => EditorClock.Seek(1000)); AddAssert("time is 1000", () => EditorClock.CurrentTime == 1000); - AddStep("set current time as preview point", () => Editor.SetCurrentTimeAsPreview()); + AddStep("set current time as preview point", () => Editor.SetPreviewPointToCurrentTime()); AddAssert("preview time is 1000", () => EditorBeatmap.PreviewTime.Value == 1000); } diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 62bb7d3133..be4e2f9628 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -327,7 +327,7 @@ namespace osu.Game.Screens.Edit { Items = new MenuItem[] { - new EditorMenuItem("Set Current Position as Preview Point", MenuItemType.Standard, SetCurrentTimeAsPreview) + new EditorMenuItem("Set preview point to current time", MenuItemType.Standard, SetPreviewPointToCurrentTime) } } } @@ -808,7 +808,7 @@ namespace osu.Game.Screens.Edit protected void Redo() => changeHandler?.RestoreState(1); - protected void SetCurrentTimeAsPreview() + protected void SetPreviewPointToCurrentTime() { editorBeatmap.PreviewTime.Value = (int)clock.CurrentTime; } diff --git a/osu.Game/Tests/Visual/EditorTestScene.cs b/osu.Game/Tests/Visual/EditorTestScene.cs index 9c8ac65add..6e2f1e99cd 100644 --- a/osu.Game/Tests/Visual/EditorTestScene.cs +++ b/osu.Game/Tests/Visual/EditorTestScene.cs @@ -102,7 +102,7 @@ namespace osu.Game.Tests.Visual public new void Redo() => base.Redo(); - public new void SetCurrentTimeAsPreview() => base.SetCurrentTimeAsPreview(); + public new void SetPreviewPointToCurrentTime() => base.SetPreviewPointToCurrentTime(); public new bool Save() => base.Save(); From 656bf12b3d43d15d38873b9993c6531fcfb2eb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 1 Jan 2023 19:37:19 +0100 Subject: [PATCH 09/14] Add all possible timeline elements to test for demonstrative purposes --- .../Visual/Editing/TestSceneEditorSummaryTimeline.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Editing/TestSceneEditorSummaryTimeline.cs b/osu.Game.Tests/Visual/Editing/TestSceneEditorSummaryTimeline.cs index ccd2feef9c..f255dd08a8 100644 --- a/osu.Game.Tests/Visual/Editing/TestSceneEditorSummaryTimeline.cs +++ b/osu.Game.Tests/Visual/Editing/TestSceneEditorSummaryTimeline.cs @@ -6,6 +6,7 @@ using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Game.Beatmaps.ControlPoints; using osu.Game.Rulesets.Osu; using osu.Game.Screens.Edit; using osu.Game.Screens.Edit.Components.Timelines.Summary; @@ -21,7 +22,13 @@ namespace osu.Game.Tests.Visual.Editing public TestSceneEditorSummaryTimeline() { - editorBeatmap = new EditorBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)); + var beatmap = CreateBeatmap(new OsuRuleset().RulesetInfo); + + beatmap.ControlPointInfo.Add(100000, new TimingControlPoint { BeatLength = 100 }); + beatmap.ControlPointInfo.Add(50000, new DifficultyControlPoint { SliderVelocity = 2 }); + beatmap.BeatmapInfo.Bookmarks = new[] { 75000, 125000 }; + + editorBeatmap = new EditorBeatmap(beatmap); } protected override void LoadComplete() From 452ebddfd28b8740e9c268a8ee41fc48de701d2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 1 Jan 2023 19:39:21 +0100 Subject: [PATCH 10/14] Adjust visual appearance of preview time part - Use slightly different hue of green to distinguish from difficulty control points. The colour is still not ideal, but picking a distinctive enough hue is pretty hard. - Place the preview time part at the bottom rather at the top. Not sure why it was at the top; not only could it overlap with the control points, but it also looked quite badly misaligned there when bookmarks were displayed at the bottom. --- .../Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs | 2 +- .../Edit/Components/Timelines/Summary/SummaryTimeline.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs index bd34662969..9d3bbe8bff 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -32,7 +32,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts } [BackgroundDependencyLoader] - private void load(OsuColour colours) => Colour = colours.Lime; + private void load(OsuColour colours) => Colour = colours.Green1; } } } diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs index 41377bcb18..075d47d82e 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/SummaryTimeline.cs @@ -44,9 +44,8 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary new PreviewTimePart { Anchor = Anchor.Centre, - Origin = Anchor.BottomCentre, + Origin = Anchor.TopCentre, RelativeSizeAxes = Axes.Both, - Y = -10, Height = 0.35f }, new Container From efdd557f3b7b9a503b189d1aa864d6bd4f15421f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 1 Jan 2023 19:45:23 +0100 Subject: [PATCH 11/14] Adjust binding logic --- .../Timelines/Summary/Parts/PreviewTimePart.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs index 9d3bbe8bff..de7f611424 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -13,7 +13,7 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts protected override void LoadBeatmap(EditorBeatmap beatmap) { base.LoadBeatmap(beatmap); - Add(new PreviewTimeVisualisation(beatmap.PreviewTime)); + Add(new PreviewTimeVisualisation(beatmap)); beatmap.PreviewTime.BindValueChanged(s => { Alpha = s.NewValue == -1 ? 0 : 1; @@ -24,11 +24,10 @@ namespace osu.Game.Screens.Edit.Components.Timelines.Summary.Parts { private readonly BindableInt previewTime = new BindableInt(); - public PreviewTimeVisualisation(BindableInt time) - : base(time.Value) + public PreviewTimeVisualisation(EditorBeatmap editorBeatmap) { - previewTime.BindTo(time); - previewTime.BindValueChanged(s => X = s.NewValue); + previewTime.BindTo(editorBeatmap.PreviewTime); + previewTime.BindValueChanged(s => X = s.NewValue, true); } [BackgroundDependencyLoader] From b689ad6d80e177734a470fc0d30e6497dc9af09b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sun, 1 Jan 2023 19:54:26 +0100 Subject: [PATCH 12/14] Fix changing preview point not prompting for save --- osu.Game/Screens/Edit/EditorBeatmap.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index dfd7328d11..1684dcf0cd 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -111,7 +111,12 @@ namespace osu.Game.Screens.Edit trackStartTime(obj); PreviewTime = new BindableInt(playableBeatmap.Metadata.PreviewTime); - PreviewTime.BindValueChanged(s => this.beatmapInfo.Metadata.PreviewTime = s.NewValue); + PreviewTime.BindValueChanged(s => + { + BeginChange(); + this.beatmapInfo.Metadata.PreviewTime = s.NewValue; + EndChange(); + }); } /// From 904c76e437114a214ec5fcc649066ad4daadf30f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 7 Jan 2023 14:23:31 +0300 Subject: [PATCH 13/14] Use sane `BeatmapInfo` for preview time mutation `EditorBeatmap.BeatmapInfo` is usually the correct instance for mutating properties that should persist in the database. --- osu.Game/Screens/Edit/EditorBeatmap.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/EditorBeatmap.cs b/osu.Game/Screens/Edit/EditorBeatmap.cs index 1684dcf0cd..dc1fda13f4 100644 --- a/osu.Game/Screens/Edit/EditorBeatmap.cs +++ b/osu.Game/Screens/Edit/EditorBeatmap.cs @@ -110,11 +110,11 @@ namespace osu.Game.Screens.Edit foreach (var obj in HitObjects) trackStartTime(obj); - PreviewTime = new BindableInt(playableBeatmap.Metadata.PreviewTime); + PreviewTime = new BindableInt(BeatmapInfo.Metadata.PreviewTime); PreviewTime.BindValueChanged(s => { BeginChange(); - this.beatmapInfo.Metadata.PreviewTime = s.NewValue; + BeatmapInfo.Metadata.PreviewTime = s.NewValue; EndChange(); }); } From abca13eb6cb934dc81f3791f8352ee4ac1ef0a95 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 7 Jan 2023 14:30:01 +0300 Subject: [PATCH 14/14] Rewrite visualisation piece to bind once and without potential event leak --- .../Visual/Editing/TestScenePreviewTime.cs | 4 ++-- .../Summary/Parts/PreviewTimePart.cs | 20 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs index d5aa71095b..3319788c8a 100644 --- a/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs +++ b/osu.Game.Tests/Visual/Editing/TestScenePreviewTime.cs @@ -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().Single().Alpha == 0); + AddAssert("preview time line should not show", () => !Editor.ChildrenOfType().Single().Children.Any()); AddStep("set preview time to 1000", () => EditorBeatmap.PreviewTime.Value = 1000); - AddAssert("preview time line should show", () => Editor.ChildrenOfType().Single().Alpha == 1); + AddAssert("preview time line should show", () => Editor.ChildrenOfType().Single().Children.Single().Alpha == 1); } } } diff --git a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs index de7f611424..c63bb7ac24 100644 --- a/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs +++ b/osu.Game/Screens/Edit/Components/Timelines/Summary/Parts/PreviewTimePart.cs @@ -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]