2019-10-11 08:13:28 +00: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 07:58:56 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-10-11 08:13:28 +00:00
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Edit.Compose.Components
|
|
|
|
{
|
2019-10-17 06:32:02 +00:00
|
|
|
public abstract class CircularDistanceSnapGrid : DistanceSnapGrid
|
2019-10-11 08:13:28 +00:00
|
|
|
{
|
2019-10-17 06:32:02 +00:00
|
|
|
protected CircularDistanceSnapGrid(HitObject hitObject, Vector2 centrePosition)
|
2019-10-11 08:13:28 +00:00
|
|
|
: base(hitObject, centrePosition)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void CreateContent(Vector2 centrePosition)
|
|
|
|
{
|
2019-10-23 08:56:09 +00:00
|
|
|
const float crosshair_thickness = 1;
|
|
|
|
const float crosshair_max_size = 10;
|
2019-10-23 07:58:56 +00:00
|
|
|
|
2019-10-23 08:56:09 +00:00
|
|
|
AddRangeInternal(new[]
|
2019-10-23 07:58:56 +00:00
|
|
|
{
|
2019-10-23 08:56:09 +00:00
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Position = centrePosition,
|
|
|
|
Width = crosshair_thickness,
|
|
|
|
EdgeSmoothness = new Vector2(1),
|
|
|
|
Height = Math.Min(crosshair_max_size, DistanceSpacing * 2),
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Position = centrePosition,
|
|
|
|
EdgeSmoothness = new Vector2(1),
|
|
|
|
Width = Math.Min(crosshair_max_size, DistanceSpacing * 2),
|
|
|
|
Height = crosshair_thickness,
|
|
|
|
}
|
2019-10-23 07:58:56 +00:00
|
|
|
});
|
|
|
|
|
2019-10-16 10:32:45 +00:00
|
|
|
float dx = Math.Max(centrePosition.X, DrawWidth - centrePosition.X);
|
|
|
|
float dy = Math.Max(centrePosition.Y, DrawHeight - centrePosition.Y);
|
|
|
|
float maxDistance = new Vector2(dx, dy).Length;
|
2019-10-11 08:13:28 +00:00
|
|
|
int requiredCircles = (int)(maxDistance / DistanceSpacing);
|
|
|
|
|
|
|
|
for (int i = 0; i < requiredCircles; i++)
|
|
|
|
{
|
|
|
|
float radius = (i + 1) * DistanceSpacing * 2;
|
|
|
|
|
|
|
|
AddInternal(new CircularProgress
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Position = centrePosition,
|
|
|
|
Current = { Value = 1 },
|
|
|
|
Size = new Vector2(radius),
|
|
|
|
InnerRadius = 4 * 1f / radius,
|
|
|
|
Colour = GetColourForBeatIndex(i)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:17:54 +00:00
|
|
|
public override Vector2 GetSnappedPosition(Vector2 position)
|
2019-10-11 08:13:28 +00:00
|
|
|
{
|
|
|
|
Vector2 direction = position - CentrePosition;
|
2019-10-16 10:44:53 +00:00
|
|
|
|
|
|
|
if (direction == Vector2.Zero)
|
|
|
|
direction = new Vector2(0.001f, 0.001f);
|
|
|
|
|
2019-10-11 08:13:28 +00:00
|
|
|
float distance = direction.Length;
|
|
|
|
|
|
|
|
float radius = DistanceSpacing;
|
|
|
|
int radialCount = Math.Max(1, (int)Math.Round(distance / radius));
|
|
|
|
|
|
|
|
Vector2 normalisedDirection = direction * new Vector2(1f / distance);
|
|
|
|
return CentrePosition + normalisedDirection * radialCount * radius;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|