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;
|
|
|
|
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
|
|
|
{
|
2019-12-10 15:00:09 +08:00
|
|
|
protected CircularDistanceSnapGrid(Vector2 startPosition, double startTime, double? endTime = null)
|
|
|
|
: base(startPosition, startTime, endTime)
|
2019-10-11 16:13:28 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-12-10 15:00:09 +08:00
|
|
|
protected override void CreateContent(Vector2 startPosition)
|
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,
|
2019-12-10 15:00:09 +08:00
|
|
|
Position = startPosition,
|
2019-10-23 16:56:09 +08:00
|
|
|
Width = crosshair_thickness,
|
|
|
|
EdgeSmoothness = new Vector2(1),
|
|
|
|
Height = Math.Min(crosshair_max_size, DistanceSpacing * 2),
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
2019-12-10 15:00:09 +08:00
|
|
|
Position = startPosition,
|
2019-10-23 16:56:09 +08:00
|
|
|
EdgeSmoothness = new Vector2(1),
|
|
|
|
Width = Math.Min(crosshair_max_size, DistanceSpacing * 2),
|
|
|
|
Height = crosshair_thickness,
|
|
|
|
}
|
2019-10-23 15:58:56 +08:00
|
|
|
});
|
|
|
|
|
2019-12-10 15:00:09 +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;
|
2019-11-06 13:55:05 +08:00
|
|
|
int requiredCircles = Math.Min(MaxIntervals, (int)(maxDistance / DistanceSpacing));
|
2019-10-11 16:13:28 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < requiredCircles; i++)
|
|
|
|
{
|
|
|
|
float radius = (i + 1) * DistanceSpacing * 2;
|
|
|
|
|
|
|
|
AddInternal(new CircularProgress
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
2019-12-10 15:00:09 +08:00
|
|
|
Position = startPosition,
|
2019-10-11 16:13:28 +08:00
|
|
|
Current = { Value = 1 },
|
|
|
|
Size = new Vector2(radius),
|
|
|
|
InnerRadius = 4 * 1f / radius,
|
|
|
|
Colour = GetColourForBeatIndex(i)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-12-10 15:00:09 +08:00
|
|
|
Vector2 direction = position - StartPosition;
|
2019-10-16 18:44:53 +08:00
|
|
|
if (direction == Vector2.Zero)
|
|
|
|
direction = new Vector2(0.001f, 0.001f);
|
|
|
|
|
2019-10-11 16:13:28 +08:00
|
|
|
float distance = direction.Length;
|
|
|
|
|
|
|
|
float radius = DistanceSpacing;
|
2019-11-25 07:45:42 +08:00
|
|
|
int radialCount = Math.Clamp((int)MathF.Round(distance / radius), 1, MaxIntervals);
|
2019-10-11 16:13:28 +08:00
|
|
|
|
|
|
|
Vector2 normalisedDirection = direction * new Vector2(1f / distance);
|
2019-12-10 15:00:09 +08:00
|
|
|
Vector2 snappedPosition = StartPosition + normalisedDirection * radialCount * radius;
|
2019-10-25 11:34:49 +08:00
|
|
|
|
2019-12-10 15:00:09 +08:00
|
|
|
return (snappedPosition, StartTime + SnapProvider.GetSnappedDurationFromDistance(StartTime, (snappedPosition - StartPosition).Length));
|
2019-10-11 16:13:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|