Skip to content

Commit

Permalink
Add total score counter sfx
Browse files Browse the repository at this point in the history
  • Loading branch information
nekodex committed Jul 22, 2022
1 parent 6ce8e74 commit 89da21b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void load(BeatmapDifficultyCache beatmapDifficultyCache)
FillMode = FillMode.Fit,
}
},
scoreCounter = new TotalScoreCounter
scoreCounter = new TotalScoreCounter(!withFlair)
{
Margin = new MarginPadding { Top = 0, Bottom = 5 },
Current = { Value = 0 },
Expand Down
62 changes: 61 additions & 1 deletion osu.Game/Screens/Ranking/Expanded/TotalScoreCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,11 +26,32 @@ public class TotalScoreCounter : RollingCounter<long>

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");
Expand All @@ -39,5 +64,40 @@ protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().W
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;
}
}
}
}

0 comments on commit 89da21b

Please sign in to comment.