Add total score counter sfx

This commit is contained in:
Jamie Taylor 2022-07-22 19:48:29 +09:00
parent 6ce8e74e6b
commit 89da21b6de
No known key found for this signature in database
GPG Key ID: 2ACFA8B6370B8C8C
2 changed files with 62 additions and 2 deletions

View File

@ -133,7 +133,7 @@ namespace osu.Game.Screens.Ranking.Expanded
FillMode = FillMode.Fit,
}
},
scoreCounter = new TotalScoreCounter
scoreCounter = new TotalScoreCounter(!withFlair)
{
Margin = new MarginPadding { Top = 0, Bottom = 5 },
Current = { Value = 0 },

View File

@ -3,7 +3,11 @@
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
@ -22,11 +26,32 @@ namespace osu.Game.Screens.Ranking.Expanded
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
public TotalScoreCounter()
private readonly bool playSound;
private bool isTicking;
private readonly Bindable<double> tickPlaybackRate = new Bindable<double>();
private double lastSampleTime;
private DrawableSample sampleTick;
public TotalScoreCounter(bool playSound = false)
{
// Todo: AutoSize X removed here due to https://github.com/ppy/osu-framework/issues/3369
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
this.playSound = playSound;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
AddInternal(sampleTick = new DrawableSample(audio.Samples.Get(@"Results/score-tick-lesser")));
lastSampleTime = Time.Current;
}
protected override void LoadComplete()
{
base.LoadComplete();
Current.BindValueChanged(startTickingPlayback);
}
protected override LocalisableString FormatCount(long count) => count.ToString("N0");
@ -39,5 +64,40 @@ namespace osu.Game.Screens.Ranking.Expanded
s.Font = OsuFont.Torus.With(size: 60, weight: FontWeight.Light, fixedWidth: true);
s.Spacing = new Vector2(-5, 0);
});
protected override void Update()
{
base.Update();
if (playSound && isTicking) playTickSample();
}
private void startTickingPlayback(ValueChangedEvent<long> _)
{
const double tick_debounce_rate_start = 10f;
const double tick_debounce_rate_end = 100f;
const double tick_volume_start = 0.5f;
const double tick_volume_end = 1.0f;
double tickDuration = RollingDuration - AccuracyCircle.ACCURACY_TRANSFORM_DELAY - AccuracyCircle.RANK_CIRCLE_TRANSFORM_DELAY;
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_start);
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_end, tickDuration, Easing.OutSine);
sampleTick.VolumeTo(tick_volume_start).Then().VolumeTo(tick_volume_end, tickDuration, Easing.OutSine);
Scheduler.AddDelayed(stopTickingPlayback, tickDuration);
isTicking = true;
}
private void stopTickingPlayback() => isTicking = false;
private void playTickSample()
{
if (Time.Current > lastSampleTime + tickPlaybackRate.Value)
{
sampleTick?.Play();
lastSampleTime = Time.Current;
}
}
}
}