1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 17:52:56 +08:00

Merge pull request #66 from Gyoshi/beat-divisor-visual-improvements

Add ghost ticks to exhibit current divisor on `BeatDivisorControl`
This commit is contained in:
Dean Herbert 2023-05-24 13:41:48 +09:00 committed by GitHub
commit 8f1f1955df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 16 deletions

View File

@ -154,12 +154,15 @@ namespace osu.Game.Screens.Edit
/// </summary>
/// <param name="index">The 0-based beat index.</param>
/// <param name="beatDivisor">The beat divisor.</param>
/// <param name="validDivisors">The list of valid divisors which can be chosen from. Assumes ordered from low to high.</param>
/// <returns>The applicable divisor.</returns>
public static int GetDivisorForBeatIndex(int index, int beatDivisor)
public static int GetDivisorForBeatIndex(int index, int beatDivisor, int[] validDivisors = null)
{
validDivisors ??= PREDEFINED_DIVISORS;
int beat = index % beatDivisor;
foreach (int divisor in PREDEFINED_DIVISORS)
foreach (int divisor in validDivisors)
{
if ((beat * divisor) % beatDivisor == 0)
return divisor;

View File

@ -399,28 +399,22 @@ namespace osu.Game.Screens.Edit.Compose.Components
ClearInternal();
CurrentNumber.ValueChanged -= moveMarker;
foreach (int divisor in beatDivisor.ValidDivisors.Value.Presets)
int largestDivisor = beatDivisor.ValidDivisors.Value.Presets.Last();
for (int tickIndex = 0; tickIndex <= largestDivisor; tickIndex++)
{
AddInternal(new Tick(divisor)
int divisor = BindableBeatDivisor.GetDivisorForBeatIndex(tickIndex, largestDivisor, (int[])beatDivisor.ValidDivisors.Value.Presets);
bool isSolidTick = divisor * (largestDivisor - tickIndex) == largestDivisor;
AddInternal(new Tick(isSolidTick, divisor)
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.Both,
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());
CurrentNumber.ValueChanged += moveMarker;
CurrentNumber.TriggerChange();
@ -429,6 +423,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
private void moveMarker(ValueChangedEvent<int> divisor)
{
marker.MoveToX(getMappedPosition(divisor.NewValue), 100, Easing.OutQuint);
foreach (Tick child in InternalChildren.OfType<Tick>())
{
float newAlpha = child.IsSolid ? 1f : divisor.NewValue % child.Divisor == 0 ? 0.2f : 0f;
child.FadeTo(newAlpha);
}
}
protected override void UpdateValue(float value)
@ -498,8 +498,12 @@ namespace osu.Game.Screens.Edit.Compose.Components
private partial class Tick : Circle
{
public Tick(int divisor)
public bool IsSolid;
public int Divisor;
public Tick(bool isSolid, int divisor)
{
IsSolid = isSolid;
Divisor = divisor;
Size = new Vector2(6f, 12) * BindableBeatDivisor.GetSize(divisor);
InternalChild = new Box { RelativeSizeAxes = Axes.Both };
}