From 69592722f80f0869a1ddbe42fbe76564c6252c5e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 6 May 2022 18:25:02 +0900 Subject: [PATCH 1/5] Highlight distance snap grid rings that are close to the current time value --- .../Components/CircularDistanceSnapGrid.cs | 45 +++++++++++++++++-- .../Compose/Components/DistanceSnapGrid.cs | 7 +-- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs index 91fad08aff..5682b5563e 100644 --- a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs @@ -2,11 +2,15 @@ // See the LICENCE file in the repository root for full licence text. using System; +using osu.Framework.Allocation; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.UserInterface; +using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Objects; using osuTK; +using osuTK.Graphics; namespace osu.Game.Screens.Edit.Compose.Components { @@ -51,14 +55,12 @@ namespace osu.Game.Screens.Edit.Compose.Components { float diameter = (i + 1) * DistanceBetweenTicks * 2; - AddInternal(new CircularProgress + AddInternal(new Ring(ReferenceObject, GetColourForIndexFromPlacement(i)) { - Origin = Anchor.Centre, Position = StartPosition, - Current = { Value = 1 }, + Origin = Anchor.Centre, Size = new Vector2(diameter), InnerRadius = 4 * 1f / diameter, - Colour = GetColourForIndexFromPlacement(i) }); } } @@ -100,5 +102,40 @@ namespace osu.Game.Screens.Edit.Compose.Components return (snappedPosition, snappedTime); } + + public class Ring : CircularProgress + { + [Resolved] + private IDistanceSnapProvider snapProvider { get; set; } + + [Resolved(canBeNull: true)] + private EditorClock editorClock { get; set; } + + private readonly HitObject referenceObject; + + private readonly Color4 baseColour; + + public Ring(HitObject referenceObject, Color4 baseColour) + { + this.referenceObject = referenceObject; + + Colour = this.baseColour = baseColour; + + Current.Value = 1; + } + + protected override void Update() + { + base.Update(); + + if (editorClock == null) + return; + + float distanceForCurrentTime = snapProvider.DurationToDistance(referenceObject, editorClock.CurrentTime - referenceObject.StartTime); + float timeBasedAlpha = Math.Clamp(1 - Math.Abs(distanceForCurrentTime - Size.X / 2) / 30, 0, 1); + + Colour = baseColour.Opacity(Math.Max(baseColour.A, timeBasedAlpha)); + } + } } } diff --git a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs index 2f39db06d4..1f64a50c02 100644 --- a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs @@ -4,14 +4,15 @@ using System; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; -using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Containers; using osu.Framework.Layout; using osu.Game.Graphics; using osu.Game.Rulesets.Edit; using osu.Game.Rulesets.Objects; using osuTK; +using osuTK.Graphics; namespace osu.Game.Screens.Edit.Compose.Components { @@ -135,7 +136,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// /// The 0-based beat index from the point of placement. /// The applicable colour. - protected ColourInfo GetColourForIndexFromPlacement(int placementIndex) + protected Color4 GetColourForIndexFromPlacement(int placementIndex) { var timingPoint = Beatmap.ControlPointInfo.TimingPointAt(StartTime); double beatLength = timingPoint.BeatLength / beatDivisor.Value; @@ -144,7 +145,7 @@ namespace osu.Game.Screens.Edit.Compose.Components var colour = BindableBeatDivisor.GetColourFor(BindableBeatDivisor.GetDivisorForBeatIndex(beatIndex + placementIndex + 1, beatDivisor.Value), Colours); int repeatIndex = placementIndex / beatDivisor.Value; - return ColourInfo.SingleColour(colour).MultiplyAlpha(0.5f / (repeatIndex + 1)); + return colour.Opacity(0.5f / (repeatIndex + 1)); } } } From 112496204d26f8709428b9eab026969953330910 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 6 May 2022 18:50:28 +0300 Subject: [PATCH 2/5] Make nested class private --- .../Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs index 5682b5563e..b3df72f827 100644 --- a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs @@ -103,7 +103,7 @@ namespace osu.Game.Screens.Edit.Compose.Components return (snappedPosition, snappedTime); } - public class Ring : CircularProgress + private class Ring : CircularProgress { [Resolved] private IDistanceSnapProvider snapProvider { get; set; } From d78f1d158d3f5582fc99efd20a92c48e5e73331d Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 6 May 2022 18:51:34 +0300 Subject: [PATCH 3/5] Use `GetEndTime()` instead of `StartTime` Companion to https://github.com/ppy/osu/pull/18103/commits/246479bf34c725d886742017099f9d509e58b2f7 --- .../Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs index b3df72f827..6cb05f0596 100644 --- a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs @@ -131,7 +131,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (editorClock == null) return; - float distanceForCurrentTime = snapProvider.DurationToDistance(referenceObject, editorClock.CurrentTime - referenceObject.StartTime); + float distanceForCurrentTime = snapProvider.DurationToDistance(referenceObject, editorClock.CurrentTime - referenceObject.GetEndTime()); float timeBasedAlpha = Math.Clamp(1 - Math.Abs(distanceForCurrentTime - Size.X / 2) / 30, 0, 1); Colour = baseColour.Opacity(Math.Max(baseColour.A, timeBasedAlpha)); From 723fce81741de8b858edb0a60090b850fc18f67a Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Fri, 6 May 2022 18:54:08 +0300 Subject: [PATCH 4/5] Move inverting value to happen outside clamp Looks to have no effect, but makes sense to happen outside instead. --- .../Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs index 6cb05f0596..c0a3f7d97f 100644 --- a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs @@ -132,7 +132,7 @@ namespace osu.Game.Screens.Edit.Compose.Components return; float distanceForCurrentTime = snapProvider.DurationToDistance(referenceObject, editorClock.CurrentTime - referenceObject.GetEndTime()); - float timeBasedAlpha = Math.Clamp(1 - Math.Abs(distanceForCurrentTime - Size.X / 2) / 30, 0, 1); + float timeBasedAlpha = 1 - Math.Clamp(Math.Abs(distanceForCurrentTime - Size.X / 2) / 30, 0, 1); Colour = baseColour.Opacity(Math.Max(baseColour.A, timeBasedAlpha)); } From 71758390b5db8186bd149647d162417e5607e730 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 7 May 2022 13:37:36 +0900 Subject: [PATCH 5/5] Fix time based distance grid alpha not correctly accounting for distance spacing multiplier --- .../Edit/Compose/Components/CircularDistanceSnapGrid.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs index c0a3f7d97f..2c6bb766ad 100644 --- a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs @@ -131,7 +131,12 @@ namespace osu.Game.Screens.Edit.Compose.Components if (editorClock == null) return; - float distanceForCurrentTime = snapProvider.DurationToDistance(referenceObject, editorClock.CurrentTime - referenceObject.GetEndTime()); + float distanceSpacingMultiplier = (float)snapProvider.DistanceSpacingMultiplier.Value; + double timeFromReferencePoint = editorClock.CurrentTime - referenceObject.GetEndTime(); + + float distanceForCurrentTime = snapProvider.DurationToDistance(referenceObject, timeFromReferencePoint) + * distanceSpacingMultiplier; + float timeBasedAlpha = 1 - Math.Clamp(Math.Abs(distanceForCurrentTime - Size.X / 2) / 30, 0, 1); Colour = baseColour.Opacity(Math.Max(baseColour.A, timeBasedAlpha));