Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display up to 2 decimal places for bpm in timing screen metronome #31586

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions osu.Game/Screens/Edit/Timing/MetronomeDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
using osu.Framework.Timing;
using osu.Framework.Utils;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Utils;
using osuTK;

namespace osu.Game.Screens.Edit.Timing
Expand All @@ -28,7 +29,7 @@ public partial class MetronomeDisplay : BeatSyncedContainer
{
private Container swing = null!;

private OsuSpriteText bpmText = null!;
private OsuTextFlowContainer bpmText = null!;

private Drawable weight = null!;
private Drawable stick = null!;
Expand Down Expand Up @@ -213,10 +214,15 @@ private void load(AudioManager audio)
},
}
},
bpmText = new OsuSpriteText
bpmText = new OsuTextFlowContainer(st =>
{
st.Font = OsuFont.Default.With(fixedWidth: true);
st.Spacing = new Vector2(-2.2f, 0);
})
{
Name = @"BPM display",
Colour = overlayColourProvider.Content1,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Y = -3,
Expand All @@ -228,11 +234,13 @@ private void load(AudioManager audio)

private double effectiveBeatLength;

private double effectiveBpm => 60_000 / effectiveBeatLength;

private TimingControlPoint timingPoint = null!;

private bool isSwinging;

private readonly BindableInt interpolatedBpm = new BindableInt();
private readonly BindableDouble interpolatedBpm = new BindableDouble();

private ScheduledDelegate? latchDelegate;

Expand All @@ -255,7 +263,25 @@ protected override void LoadComplete()
{
base.LoadComplete();

interpolatedBpm.BindValueChanged(_ => bpmText.Text = interpolatedBpm.Value.ToLocalisableString());
interpolatedBpm.BindValueChanged(_ => updateBpmText());
}

private void updateBpmText()
{
int intPart = (int)interpolatedBpm.Value;

bpmText.Text = intPart.ToLocalisableString();

// While interpolating between two integer values, showing the decimal places would look a bit odd
// so rounding is applied until we're close to the final value.
int decimalPlaces = FormatUtils.FindPrecision((decimal)effectiveBpm);

if (decimalPlaces > 0)
{
bool reachedFinalNumber = intPart == (int)effectiveBpm;

bpmText.AddText((effectiveBpm % 1).ToLocalisableString("." + new string('0', decimalPlaces)), cp => cp.Alpha = reachedFinalNumber ? 0.5f : 0.1f);
}
}

protected override void Update()
Expand All @@ -277,12 +303,11 @@ protected override void Update()

EarlyActivationMilliseconds = timingPoint.BeatLength / 2;

double effectiveBpm = 60000 / effectiveBeatLength;

float bpmRatio = (float)Interpolation.ApplyEasing(Easing.OutQuad, Math.Clamp((effectiveBpm - 30) / 480, 0, 1));

weight.MoveToY((float)Interpolation.Lerp(0.1f, 0.83f, bpmRatio), 600, Easing.OutQuint);
this.TransformBindableTo(interpolatedBpm, (int)Math.Round(effectiveBpm), 600, Easing.OutQuint);

this.TransformBindableTo(interpolatedBpm, effectiveBpm, 300, Easing.OutExpo);
}

if (!BeatSyncSource.Clock.IsRunning && isSwinging)
Expand Down
Loading