Highlight distance snap grid rings that are close to the current time value

This commit is contained in:
Dean Herbert
2022-05-06 18:25:02 +09:00
parent 118e58888b
commit 69592722f8
2 changed files with 45 additions and 7 deletions

View File

@ -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));
}
}
}
}