1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-30 06:12:58 +08:00

Add ghost ticks to exhibit current divisor on BeatDivisorControl

This commit is contained in:
Johannes vd Berg 2023-05-23 12:57:25 +02:00
parent 87ff28b022
commit ebda35c3c9

View File

@ -398,28 +398,25 @@ namespace osu.Game.Screens.Edit.Compose.Components
ClearInternal(); ClearInternal();
CurrentNumber.ValueChanged -= moveMarker; CurrentNumber.ValueChanged -= moveMarker;
foreach (int divisor in beatDivisor.ValidDivisors.Value.Presets) int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Max();
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
{ {
AddInternal(new Tick(divisor) int divisor = largestDivisor;
foreach (int validDivisor in beatDivisor.ValidDivisors.Value.Presets)
{
if (divisor > validDivisor && (tickIndex * validDivisor) % largestDivisor == 0)
divisor = validDivisor;
}
bool solidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
AddInternal(new Tick(solidTick, divisor)
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre, Origin = Anchor.Centre,
RelativePositionAxes = Axes.Both, RelativePositionAxes = Axes.Both,
Colour = BindableBeatDivisor.GetColourFor(divisor, colours), Colour = BindableBeatDivisor.GetColourFor(divisor, colours),
X = getMappedPosition(divisor), X = tickIndex / (float)largestDivisor,
}); });
} }
// Add a fake 1/1 at the end to give context.
AddInternal(new Tick(1)
{
Anchor = Anchor.CentreRight,
Origin = Anchor.Centre,
Depth = float.MaxValue,
Alpha = 0.05f,
Colour = BindableBeatDivisor.GetColourFor(1, colours),
});
AddInternal(marker = new Marker()); AddInternal(marker = new Marker());
CurrentNumber.ValueChanged += moveMarker; CurrentNumber.ValueChanged += moveMarker;
CurrentNumber.TriggerChange(); CurrentNumber.TriggerChange();
@ -428,6 +425,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void moveMarker(ValueChangedEvent<int> divisor) private void moveMarker(ValueChangedEvent<int> divisor)
{ {
marker.MoveToX(getMappedPosition(divisor.NewValue), 100, Easing.OutQuint); marker.MoveToX(getMappedPosition(divisor.NewValue), 100, Easing.OutQuint);
foreach (Tick child in InternalChildren.OfType<Tick>())
{
float newAlpha = child.Solid ? 1f : divisor.NewValue % child.Divisor == 0 ? 0.2f : 0f;
child.FadeTo(newAlpha);
}
} }
protected override void UpdateValue(float value) protected override void UpdateValue(float value)
@ -497,8 +500,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
private partial class Tick : Circle private partial class Tick : Circle
{ {
public Tick(int divisor) public bool Solid;
public int Divisor;
public Tick(bool solid, int divisor)
{ {
Solid = solid;
Divisor = divisor;
Size = new Vector2(6f, 12) * BindableBeatDivisor.GetSize(divisor); Size = new Vector2(6f, 12) * BindableBeatDivisor.GetSize(divisor);
InternalChild = new Box { RelativeSizeAxes = Axes.Both }; InternalChild = new Box { RelativeSizeAxes = Axes.Both };
} }