From c1647440641abe58d4ef1abf834e8f936d0877a2 Mon Sep 17 00:00:00 2001 From: cdwcgt Date: Fri, 16 Dec 2022 01:03:30 +0900 Subject: [PATCH 01/18] 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/18] 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/18] 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/18] `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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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 7f970f3cd846068bb775586f398e8fce73329089 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Thu, 29 Dec 2022 21:17:24 -0800 Subject: [PATCH 13/18] Display nominators on beatmap set overlay --- .../API/Requests/Responses/APIBeatmapSet.cs | 6 ++ .../Responses/BeatmapSetOnlineNominations.cs | 22 +++++++ osu.Game/Overlays/BeatmapSet/Info.cs | 4 ++ .../BeatmapSet/MetadataSectionNominators.cs | 62 +++++++++++++++++++ osu.Game/Overlays/BeatmapSet/MetadataType.cs | 5 +- 5 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs create mode 100644 osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index 717a1de6b5..eb39b7489d 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -111,6 +111,12 @@ namespace osu.Game.Online.API.Requests.Responses [JsonProperty(@"language")] public BeatmapSetOnlineLanguage Language { get; set; } + [JsonProperty(@"current_nominations")] + public BeatmapSetOnlineNominations[] CurrentNominations { get; set; } = Array.Empty(); + + [JsonProperty(@"related_users")] + public APIUser[] RelatedUsers { get; set; } = Array.Empty(); + public string Source { get; set; } = string.Empty; [JsonProperty(@"tags")] diff --git a/osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs b/osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs new file mode 100644 index 0000000000..5d0a3ea38b --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs @@ -0,0 +1,22 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; + +namespace osu.Game.Online.API.Requests.Responses +{ + public struct BeatmapSetOnlineNominations + { + [JsonProperty(@"beatmapset_id")] + public int BeatmapsetId { get; set; } + + [JsonProperty(@"reset")] + public bool Reset { get; set; } + + [JsonProperty(@"rulesets")] + public string[]? Rulesets { get; set; } + + [JsonProperty(@"user_id")] + public int UserId { get; set; } + } +} diff --git a/osu.Game/Overlays/BeatmapSet/Info.cs b/osu.Game/Overlays/BeatmapSet/Info.cs index d184f0d0fd..dbeea74f6f 100644 --- a/osu.Game/Overlays/BeatmapSet/Info.cs +++ b/osu.Game/Overlays/BeatmapSet/Info.cs @@ -3,6 +3,7 @@ #nullable disable +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -36,6 +37,7 @@ namespace osu.Game.Overlays.BeatmapSet public Info() { + MetadataSectionNominators nominators; MetadataSection source, tags; MetadataSectionGenre genre; MetadataSectionLanguage language; @@ -82,6 +84,7 @@ namespace osu.Game.Overlays.BeatmapSet Direction = FillDirection.Full, Children = new Drawable[] { + nominators = new MetadataSectionNominators(), source = new MetadataSectionSource(), genre = new MetadataSectionGenre { Width = 0.5f }, language = new MetadataSectionLanguage { Width = 0.5f }, @@ -122,6 +125,7 @@ namespace osu.Game.Overlays.BeatmapSet BeatmapSet.ValueChanged += b => { + nominators.Metadata = (b.NewValue?.CurrentNominations ?? Array.Empty(), b.NewValue?.RelatedUsers ?? Array.Empty()); source.Metadata = b.NewValue?.Source ?? string.Empty; tags.Metadata = b.NewValue?.Tags ?? string.Empty; genre.Metadata = b.NewValue?.Genre ?? new BeatmapSetOnlineGenre { Id = (int)SearchGenre.Unspecified }; diff --git a/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs b/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs new file mode 100644 index 0000000000..78a3fe7cd5 --- /dev/null +++ b/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs @@ -0,0 +1,62 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Linq; +using osu.Framework.Graphics; +using osu.Game.Graphics.Containers; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Resources.Localisation.Web; + +namespace osu.Game.Overlays.BeatmapSet +{ + public partial class MetadataSectionNominators : MetadataSection<(BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers)> + { + public override (BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers) Metadata + { + set + { + if (value.CurrentNominations.Length == 0) + { + this.FadeOut(TRANSITION_DURATION); + return; + } + + base.Metadata = value; + } + } + + public MetadataSectionNominators(Action<(BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers)>? searchAction = null) + : base(MetadataType.Nominators, searchAction) + { + } + + protected override void AddMetadata((BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers) metadata, LinkFlowContainer loaded) + { + int[] nominatorIds = metadata.CurrentNominations.Select(n => n.UserId).ToArray(); + + int nominatorsFound = 0; + + foreach (int nominatorId in nominatorIds) + { + foreach (var user in metadata.RelatedUsers) + { + if (nominatorId != user.OnlineID) continue; + + nominatorsFound++; + + loaded.AddUserLink(new APIUser + { + Username = user.Username, + Id = nominatorId, + }); + + if (nominatorsFound < nominatorIds.Length) + loaded.AddText(CommonStrings.ArrayAndWordsConnector); + + break; + } + } + } + } +} diff --git a/osu.Game/Overlays/BeatmapSet/MetadataType.cs b/osu.Game/Overlays/BeatmapSet/MetadataType.cs index 924e020641..dc96ce99e9 100644 --- a/osu.Game/Overlays/BeatmapSet/MetadataType.cs +++ b/osu.Game/Overlays/BeatmapSet/MetadataType.cs @@ -23,6 +23,9 @@ namespace osu.Game.Overlays.BeatmapSet Genre, [LocalisableDescription(typeof(BeatmapsetsStrings), nameof(BeatmapsetsStrings.ShowInfoLanguage))] - Language + Language, + + [LocalisableDescription(typeof(BeatmapsetsStrings), nameof(BeatmapsetsStrings.ShowInfoNominators))] + Nominators, } } From e449d8dda067cc671b648330e6089d3e5f53cf9c Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 6 Jan 2023 22:39:46 +0300 Subject: [PATCH 14/18] Fix friends list duplicating on connection failure --- osu.Game/Online/API/APIAccess.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/API/APIAccess.cs b/osu.Game/Online/API/APIAccess.cs index f2b9b6e968..757f6598e7 100644 --- a/osu.Game/Online/API/APIAccess.cs +++ b/osu.Game/Online/API/APIAccess.cs @@ -259,7 +259,11 @@ namespace osu.Game.Online.API var friendsReq = new GetFriendsRequest(); friendsReq.Failure += _ => state.Value = APIState.Failing; - friendsReq.Success += res => friends.AddRange(res); + friendsReq.Success += res => + { + friends.Clear(); + friends.AddRange(res); + }; if (!handleRequest(friendsReq)) { From 904c76e437114a214ec5fcc649066ad4daadf30f Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Sat, 7 Jan 2023 14:23:31 +0300 Subject: [PATCH 15/18] 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 16/18] 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] From 0f6735564eeefca5ea9ef14dd85771da117b3366 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Sat, 7 Jan 2023 10:54:48 -0800 Subject: [PATCH 17/18] Move and rename nomination response model to singular --- .../BeatmapSetOnlineNomination.cs} | 4 ++-- osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 2 +- osu.Game/Overlays/BeatmapSet/Info.cs | 2 +- .../Overlays/BeatmapSet/MetadataSectionNominators.cs | 9 +++++---- 4 files changed, 9 insertions(+), 8 deletions(-) rename osu.Game/{Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs => Beatmaps/BeatmapSetOnlineNomination.cs} (84%) diff --git a/osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs b/osu.Game/Beatmaps/BeatmapSetOnlineNomination.cs similarity index 84% rename from osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs rename to osu.Game/Beatmaps/BeatmapSetOnlineNomination.cs index 5d0a3ea38b..f6de414628 100644 --- a/osu.Game/Online/API/Requests/Responses/BeatmapSetOnlineNominations.cs +++ b/osu.Game/Beatmaps/BeatmapSetOnlineNomination.cs @@ -3,9 +3,9 @@ using Newtonsoft.Json; -namespace osu.Game.Online.API.Requests.Responses +namespace osu.Game.Beatmaps { - public struct BeatmapSetOnlineNominations + public struct BeatmapSetOnlineNomination { [JsonProperty(@"beatmapset_id")] public int BeatmapsetId { get; set; } diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index eb39b7489d..fc740f1eec 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -112,7 +112,7 @@ namespace osu.Game.Online.API.Requests.Responses public BeatmapSetOnlineLanguage Language { get; set; } [JsonProperty(@"current_nominations")] - public BeatmapSetOnlineNominations[] CurrentNominations { get; set; } = Array.Empty(); + public BeatmapSetOnlineNomination[] CurrentNominations { get; set; } = Array.Empty(); [JsonProperty(@"related_users")] public APIUser[] RelatedUsers { get; set; } = Array.Empty(); diff --git a/osu.Game/Overlays/BeatmapSet/Info.cs b/osu.Game/Overlays/BeatmapSet/Info.cs index dbeea74f6f..58739eb471 100644 --- a/osu.Game/Overlays/BeatmapSet/Info.cs +++ b/osu.Game/Overlays/BeatmapSet/Info.cs @@ -125,7 +125,7 @@ namespace osu.Game.Overlays.BeatmapSet BeatmapSet.ValueChanged += b => { - nominators.Metadata = (b.NewValue?.CurrentNominations ?? Array.Empty(), b.NewValue?.RelatedUsers ?? Array.Empty()); + nominators.Metadata = (b.NewValue?.CurrentNominations ?? Array.Empty(), b.NewValue?.RelatedUsers ?? Array.Empty()); source.Metadata = b.NewValue?.Source ?? string.Empty; tags.Metadata = b.NewValue?.Tags ?? string.Empty; genre.Metadata = b.NewValue?.Genre ?? new BeatmapSetOnlineGenre { Id = (int)SearchGenre.Unspecified }; diff --git a/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs b/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs index 78a3fe7cd5..76dbda3d5e 100644 --- a/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs +++ b/osu.Game/Overlays/BeatmapSet/MetadataSectionNominators.cs @@ -4,15 +4,16 @@ using System; using System.Linq; using osu.Framework.Graphics; +using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; using osu.Game.Online.API.Requests.Responses; using osu.Game.Resources.Localisation.Web; namespace osu.Game.Overlays.BeatmapSet { - public partial class MetadataSectionNominators : MetadataSection<(BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers)> + public partial class MetadataSectionNominators : MetadataSection<(BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers)> { - public override (BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers) Metadata + public override (BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers) Metadata { set { @@ -26,12 +27,12 @@ namespace osu.Game.Overlays.BeatmapSet } } - public MetadataSectionNominators(Action<(BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers)>? searchAction = null) + public MetadataSectionNominators(Action<(BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers)>? searchAction = null) : base(MetadataType.Nominators, searchAction) { } - protected override void AddMetadata((BeatmapSetOnlineNominations[] CurrentNominations, APIUser[] RelatedUsers) metadata, LinkFlowContainer loaded) + protected override void AddMetadata((BeatmapSetOnlineNomination[] CurrentNominations, APIUser[] RelatedUsers) metadata, LinkFlowContainer loaded) { int[] nominatorIds = metadata.CurrentNominations.Select(n => n.UserId).ToArray(); From 9d32fde5928f1c77804090c3c1802397b58fa036 Mon Sep 17 00:00:00 2001 From: Joseph Madamba Date: Sat, 7 Jan 2023 11:04:42 -0800 Subject: [PATCH 18/18] Mark current nominations and related users as nullable --- osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs index fc740f1eec..aeae3edde2 100644 --- a/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs +++ b/osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs @@ -112,10 +112,10 @@ namespace osu.Game.Online.API.Requests.Responses public BeatmapSetOnlineLanguage Language { get; set; } [JsonProperty(@"current_nominations")] - public BeatmapSetOnlineNomination[] CurrentNominations { get; set; } = Array.Empty(); + public BeatmapSetOnlineNomination[]? CurrentNominations { get; set; } [JsonProperty(@"related_users")] - public APIUser[] RelatedUsers { get; set; } = Array.Empty(); + public APIUser[]? RelatedUsers { get; set; } public string Source { get; set; } = string.Empty;