mirror of
https://github.com/osukey/osukey.git
synced 2025-05-07 06:37:18 +09:00
Simplify TotalScoreCounter
tick playback logic
This commit is contained in:
parent
9f045209b9
commit
bb46ba66e0
@ -26,32 +26,35 @@ namespace osu.Game.Screens.Ranking.Expanded
|
|||||||
|
|
||||||
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
|
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
|
||||||
|
|
||||||
private readonly bool playSound;
|
private readonly bool playSamples;
|
||||||
private bool isTicking;
|
|
||||||
private readonly Bindable<double> tickPlaybackRate = new Bindable<double>();
|
private readonly Bindable<double> tickPlaybackRate = new Bindable<double>();
|
||||||
|
|
||||||
private double lastSampleTime;
|
private double lastSampleTime;
|
||||||
|
|
||||||
private DrawableSample sampleTick;
|
private DrawableSample sampleTick;
|
||||||
|
|
||||||
public TotalScoreCounter(bool playSound = false)
|
public TotalScoreCounter(bool playSamples = false)
|
||||||
{
|
{
|
||||||
// Todo: AutoSize X removed here due to https://github.com/ppy/osu-framework/issues/3369
|
// Todo: AutoSize X removed here due to https://github.com/ppy/osu-framework/issues/3369
|
||||||
AutoSizeAxes = Axes.Y;
|
AutoSizeAxes = Axes.Y;
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
this.playSound = playSound;
|
|
||||||
|
this.playSamples = playSamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(AudioManager audio)
|
private void load(AudioManager audio)
|
||||||
{
|
{
|
||||||
AddInternal(sampleTick = new DrawableSample(audio.Samples.Get(@"Results/score-tick-lesser")));
|
AddInternal(sampleTick = new DrawableSample(audio.Samples.Get(@"Results/score-tick-lesser")));
|
||||||
lastSampleTime = Time.Current;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
Current.BindValueChanged(startTickingPlayback);
|
if (playSamples)
|
||||||
|
Current.BindValueChanged(_ => startTicking());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override LocalisableString FormatCount(long count) => count.ToString("N0");
|
protected override LocalisableString FormatCount(long count) => count.ToString("N0");
|
||||||
@ -65,39 +68,36 @@ namespace osu.Game.Screens.Ranking.Expanded
|
|||||||
s.Spacing = new Vector2(-5, 0);
|
s.Spacing = new Vector2(-5, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
protected override void Update()
|
public override long DisplayedCount
|
||||||
{
|
{
|
||||||
base.Update();
|
get => base.DisplayedCount;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (base.DisplayedCount == value)
|
||||||
|
return;
|
||||||
|
|
||||||
if (playSound && isTicking) playTickSample();
|
base.DisplayedCount = value;
|
||||||
|
|
||||||
|
if (playSamples && Time.Current > lastSampleTime + tickPlaybackRate.Value)
|
||||||
|
{
|
||||||
|
sampleTick?.Play();
|
||||||
|
lastSampleTime = Time.Current;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTickingPlayback(ValueChangedEvent<long> _)
|
private void startTicking()
|
||||||
{
|
{
|
||||||
const double tick_debounce_rate_start = 10f;
|
const double tick_debounce_rate_start = 10f;
|
||||||
const double tick_debounce_rate_end = 100f;
|
const double tick_debounce_rate_end = 100f;
|
||||||
const double tick_volume_start = 0.5f;
|
const double tick_volume_start = 0.5f;
|
||||||
const double tick_volume_end = 1.0f;
|
const double tick_volume_end = 1.0f;
|
||||||
double tickDuration = RollingDuration - AccuracyCircle.ACCURACY_TRANSFORM_DELAY - AccuracyCircle.RANK_CIRCLE_TRANSFORM_DELAY;
|
|
||||||
|
double tickDuration = RollingDuration;
|
||||||
|
|
||||||
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_start);
|
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_start);
|
||||||
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_end, tickDuration, Easing.OutSine);
|
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_end, tickDuration, Easing.OutSine);
|
||||||
sampleTick.VolumeTo(tick_volume_start).Then().VolumeTo(tick_volume_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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user