diff --git a/osu.Game.Tests/Visual/Editor/TestSceneDistanceSnapGrid.cs b/osu.Game.Tests/Visual/Editor/TestSceneDistanceSnapGrid.cs index 847d168e51..f49256a633 100644 --- a/osu.Game.Tests/Visual/Editor/TestSceneDistanceSnapGrid.cs +++ b/osu.Game.Tests/Visual/Editor/TestSceneDistanceSnapGrid.cs @@ -85,64 +85,64 @@ namespace osu.Game.Tests.Visual.Editor { } - protected override void CreateContent(Vector2 startPosition) + protected override void CreateContent() { AddInternal(new Circle { Origin = Anchor.Centre, Size = new Vector2(5), - Position = startPosition + Position = StartPosition }); - int beatIndex = 0; + int indexFromPlacement = 0; - for (float s = startPosition.X + DistanceSpacing; s <= DrawWidth && beatIndex < MaxIntervals; s += DistanceSpacing, beatIndex++) + for (float s = StartPosition.X + DistanceSpacing; s <= DrawWidth && indexFromPlacement < MaxIntervals; s += DistanceSpacing, indexFromPlacement++) { AddInternal(new Circle { Origin = Anchor.Centre, Size = new Vector2(5, 10), - Position = new Vector2(s, startPosition.Y), - Colour = GetColourForBeatIndex(beatIndex) + Position = new Vector2(s, StartPosition.Y), + Colour = GetColourForIndexFromPlacement(indexFromPlacement) }); } - beatIndex = 0; + indexFromPlacement = 0; - for (float s = startPosition.X - DistanceSpacing; s >= 0 && beatIndex < MaxIntervals; s -= DistanceSpacing, beatIndex++) + for (float s = StartPosition.X - DistanceSpacing; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceSpacing, indexFromPlacement++) { AddInternal(new Circle { Origin = Anchor.Centre, Size = new Vector2(5, 10), - Position = new Vector2(s, startPosition.Y), - Colour = GetColourForBeatIndex(beatIndex) + Position = new Vector2(s, StartPosition.Y), + Colour = GetColourForIndexFromPlacement(indexFromPlacement) }); } - beatIndex = 0; + indexFromPlacement = 0; - for (float s = startPosition.Y + DistanceSpacing; s <= DrawHeight && beatIndex < MaxIntervals; s += DistanceSpacing, beatIndex++) + for (float s = StartPosition.Y + DistanceSpacing; s <= DrawHeight && indexFromPlacement < MaxIntervals; s += DistanceSpacing, indexFromPlacement++) { AddInternal(new Circle { Origin = Anchor.Centre, Size = new Vector2(10, 5), - Position = new Vector2(startPosition.X, s), - Colour = GetColourForBeatIndex(beatIndex) + Position = new Vector2(StartPosition.X, s), + Colour = GetColourForIndexFromPlacement(indexFromPlacement) }); } - beatIndex = 0; + indexFromPlacement = 0; - for (float s = startPosition.Y - DistanceSpacing; s >= 0 && beatIndex < MaxIntervals; s -= DistanceSpacing, beatIndex++) + for (float s = StartPosition.Y - DistanceSpacing; s >= 0 && indexFromPlacement < MaxIntervals; s -= DistanceSpacing, indexFromPlacement++) { AddInternal(new Circle { Origin = Anchor.Centre, Size = new Vector2(10, 5), - Position = new Vector2(startPosition.X, s), - Colour = GetColourForBeatIndex(beatIndex) + Position = new Vector2(StartPosition.X, s), + Colour = GetColourForIndexFromPlacement(indexFromPlacement) }); } } diff --git a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs index 23ed10b92d..730f482f83 100644 --- a/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/CircularDistanceSnapGrid.cs @@ -16,7 +16,7 @@ namespace osu.Game.Screens.Edit.Compose.Components { } - protected override void CreateContent(Vector2 startPosition) + protected override void CreateContent() { const float crosshair_thickness = 1; const float crosshair_max_size = 10; @@ -26,7 +26,7 @@ namespace osu.Game.Screens.Edit.Compose.Components new Box { Origin = Anchor.Centre, - Position = startPosition, + Position = StartPosition, Width = crosshair_thickness, EdgeSmoothness = new Vector2(1), Height = Math.Min(crosshair_max_size, DistanceSpacing * 2), @@ -34,15 +34,15 @@ namespace osu.Game.Screens.Edit.Compose.Components new Box { Origin = Anchor.Centre, - Position = startPosition, + Position = StartPosition, EdgeSmoothness = new Vector2(1), Width = Math.Min(crosshair_max_size, DistanceSpacing * 2), Height = crosshair_thickness, } }); - float dx = Math.Max(startPosition.X, DrawWidth - startPosition.X); - float dy = Math.Max(startPosition.Y, DrawHeight - startPosition.Y); + float dx = Math.Max(StartPosition.X, DrawWidth - StartPosition.X); + float dy = Math.Max(StartPosition.Y, DrawHeight - StartPosition.Y); float maxDistance = new Vector2(dx, dy).Length; int requiredCircles = Math.Min(MaxIntervals, (int)(maxDistance / DistanceSpacing)); @@ -53,11 +53,11 @@ namespace osu.Game.Screens.Edit.Compose.Components AddInternal(new CircularProgress { Origin = Anchor.Centre, - Position = startPosition, + Position = StartPosition, Current = { Value = 1 }, Size = new Vector2(radius), InnerRadius = 4 * 1f / radius, - Colour = GetColourForBeatIndex(i) + Colour = GetColourForIndexFromPlacement(i) }); } } diff --git a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs index 3bbccd612b..bce8878766 100644 --- a/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs +++ b/osu.Game/Screens/Edit/Compose/Components/DistanceSnapGrid.cs @@ -1,6 +1,7 @@ // 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 osu.Framework.Allocation; using osu.Framework.Caching; using osu.Framework.Graphics; @@ -106,7 +107,7 @@ namespace osu.Game.Screens.Edit.Compose.Components if (!gridCache.IsValid) { ClearInternal(); - CreateContent(StartPosition); + CreateContent(); gridCache.Validate(); } } @@ -114,7 +115,7 @@ namespace osu.Game.Screens.Edit.Compose.Components /// /// Creates the content which visualises the grid ticks. /// - protected abstract void CreateContent(Vector2 startPosition); + protected abstract void CreateContent(); /// /// Snaps a position to this grid. @@ -126,13 +127,15 @@ namespace osu.Game.Screens.Edit.Compose.Components /// /// Retrieves the applicable colour for a beat index. /// - /// The 0-based beat index. + /// The 0-based beat index from the point of placement. /// The applicable colour. - protected ColourInfo GetColourForBeatIndex(int index) + protected ColourInfo GetColourForIndexFromPlacement(int placementIndex) { - var colour = BindableBeatDivisor.GetColourFor(BindableBeatDivisor.GetDivisorForBeatIndex(index + 1, beatDivisor.Value), Colours); + var timingPoint = beatmap.ControlPointInfo.TimingPointAt(StartTime); + var beatIndex = (int)Math.Round((StartTime - timingPoint.Time) / timingPoint.BeatLength * beatDivisor.Value); + var colour = BindableBeatDivisor.GetColourFor(BindableBeatDivisor.GetDivisorForBeatIndex(beatIndex + placementIndex + 1, beatDivisor.Value), Colours); - int repeatIndex = index / beatDivisor.Value; + int repeatIndex = placementIndex / beatDivisor.Value; return colour.MultiplyAlpha(0.5f / (repeatIndex + 1)); } }