2019-10-11 16:13:28 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Graphics;
|
2019-10-23 15:58:56 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-10-11 16:13:28 +08:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-09-01 17:05:10 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
2019-10-11 16:13:28 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
2019-10-17 14:32:02 +08:00
|
|
|
public abstract class CircularDistanceSnapGrid : DistanceSnapGrid
|
2019-10-11 16:13:28 +08:00
|
|
|
{
|
2021-09-01 17:05:10 +08:00
|
|
|
protected CircularDistanceSnapGrid(HitObject referenceObject, Vector2 startPosition, double startTime, double? endTime = null)
|
|
|
|
: base(referenceObject, startPosition, startTime, endTime)
|
2019-10-11 16:13:28 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
protected override void CreateContent()
|
2019-10-11 16:13:28 +08:00
|
|
|
{
|
2019-10-23 16:56:09 +08:00
|
|
|
const float crosshair_thickness = 1;
|
|
|
|
const float crosshair_max_size = 10;
|
2019-10-23 15:58:56 +08:00
|
|
|
|
2019-10-23 16:56:09 +08:00
|
|
|
AddRangeInternal(new[]
|
2019-10-23 15:58:56 +08:00
|
|
|
{
|
2019-10-23 16:56:09 +08:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = StartPosition,
|
2019-10-23 16:56:09 +08:00
|
|
|
Width = crosshair_thickness,
|
|
|
|
EdgeSmoothness = new Vector2(1),
|
2022-05-05 16:00:36 +08:00
|
|
|
Height = Math.Min(crosshair_max_size, DistanceBetweenTick * 2),
|
2019-10-23 16:56:09 +08:00
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = StartPosition,
|
2019-10-23 16:56:09 +08:00
|
|
|
EdgeSmoothness = new Vector2(1),
|
2022-05-05 16:00:36 +08:00
|
|
|
Width = Math.Min(crosshair_max_size, DistanceBetweenTick * 2),
|
2019-10-23 16:56:09 +08:00
|
|
|
Height = crosshair_thickness,
|
|
|
|
}
|
2019-10-23 15:58:56 +08:00
|
|
|
});
|
|
|
|
|
2020-01-28 10:59:21 +08:00
|
|
|
float dx = Math.Max(StartPosition.X, DrawWidth - StartPosition.X);
|
|
|
|
float dy = Math.Max(StartPosition.Y, DrawHeight - StartPosition.Y);
|
2019-10-16 18:32:45 +08:00
|
|
|
float maxDistance = new Vector2(dx, dy).Length;
|
2022-05-05 16:00:36 +08:00
|
|
|
int requiredCircles = Math.Min(MaxIntervals, (int)(maxDistance / DistanceBetweenTick));
|
2019-10-11 16:13:28 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < requiredCircles; i++)
|
|
|
|
{
|
2022-05-05 16:00:36 +08:00
|
|
|
float radius = (i + 1) * DistanceBetweenTick * 2;
|
2019-10-11 16:13:28 +08:00
|
|
|
|
|
|
|
AddInternal(new CircularProgress
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
2020-01-28 10:59:21 +08:00
|
|
|
Position = StartPosition,
|
2019-10-11 16:13:28 +08:00
|
|
|
Current = { Value = 1 },
|
|
|
|
Size = new Vector2(radius),
|
|
|
|
InnerRadius = 4 * 1f / radius,
|
2020-01-28 10:59:21 +08:00
|
|
|
Colour = GetColourForIndexFromPlacement(i)
|
2019-10-11 16:13:28 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-25 11:34:49 +08:00
|
|
|
public override (Vector2 position, double time) GetSnappedPosition(Vector2 position)
|
2019-10-11 16:13:28 +08:00
|
|
|
{
|
2019-11-06 13:55:05 +08:00
|
|
|
if (MaxIntervals == 0)
|
2019-12-10 15:00:09 +08:00
|
|
|
return (StartPosition, StartTime);
|
2019-10-16 18:44:53 +08:00
|
|
|
|
2022-05-05 16:50:33 +08:00
|
|
|
// This grid implementation factors in the user's distance spacing specification,
|
|
|
|
// which is usually not considered by an `IDistanceSnapProvider`.
|
|
|
|
float distanceSpacing = (float)DistanceSpacingMultiplier.Value;
|
2019-10-16 18:44:53 +08:00
|
|
|
|
2022-05-05 16:50:33 +08:00
|
|
|
Vector2 travelVector = (position - StartPosition);
|
2019-10-11 16:13:28 +08:00
|
|
|
|
2022-05-05 16:50:33 +08:00
|
|
|
if (travelVector == Vector2.Zero)
|
|
|
|
return (StartPosition, StartTime);
|
|
|
|
|
|
|
|
float travelLength = travelVector.Length;
|
|
|
|
|
|
|
|
// FindSnappedDistance will always round down, but we want to potentially round upwards.
|
|
|
|
travelLength += DistanceBetweenTick / 2;
|
|
|
|
|
|
|
|
// When interacting with the resolved snap provider, the distance spacing multiplier should first be removed
|
|
|
|
// to allow for snapping at a non-multiplied ratio.
|
|
|
|
float snappedDistance = SnapProvider.FindSnappedDistance(ReferenceObject, travelLength / distanceSpacing);
|
|
|
|
double snappedTime = StartTime + SnapProvider.DistanceToDuration(ReferenceObject, snappedDistance);
|
2019-10-11 16:13:28 +08:00
|
|
|
|
2022-05-05 17:25:46 +08:00
|
|
|
if (snappedTime > LatestEndTime)
|
|
|
|
{
|
|
|
|
snappedDistance = SnapProvider.DurationToDistance(ReferenceObject, LatestEndTime.Value - ReferenceObject.StartTime);
|
|
|
|
}
|
|
|
|
|
2022-05-05 16:50:33 +08:00
|
|
|
// The multiplier can then be reapplied to the final position.
|
|
|
|
Vector2 snappedPosition = StartPosition + travelVector.Normalized() * snappedDistance * distanceSpacing;
|
2019-10-25 11:34:49 +08:00
|
|
|
|
2022-05-05 16:50:33 +08:00
|
|
|
return (snappedPosition, snappedTime);
|
2019-10-11 16:13:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|