2020-03-17 16:25:24 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-07-22 18:48:29 +08:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Bindables;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Framework.Graphics;
|
2022-07-22 18:48:29 +08:00
|
|
|
using osu.Framework.Graphics.Audio;
|
2021-07-24 04:37:08 +08:00
|
|
|
using osu.Framework.Localisation;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Game.Graphics;
|
2020-08-04 01:14:17 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
2020-03-17 16:25:24 +08:00
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
using osu.Game.Screens.Ranking.Expanded.Accuracy;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Ranking.Expanded
|
|
|
|
{
|
2020-03-17 16:34:16 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A counter for the player's total score to be displayed in the <see cref="ExpandedPanelMiddleContent"/>.
|
|
|
|
/// </summary>
|
2020-03-17 16:25:24 +08:00
|
|
|
public partial class TotalScoreCounter : RollingCounter<long>
|
|
|
|
{
|
|
|
|
protected override double RollingDuration => AccuracyCircle.ACCURACY_TRANSFORM_DURATION;
|
|
|
|
|
|
|
|
protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;
|
|
|
|
|
2022-07-23 01:25:37 +08:00
|
|
|
private readonly bool playSamples;
|
|
|
|
|
2022-07-22 18:48:29 +08:00
|
|
|
private readonly Bindable<double> tickPlaybackRate = new Bindable<double>();
|
2022-07-23 01:25:37 +08:00
|
|
|
|
2022-07-22 18:48:29 +08:00
|
|
|
private double lastSampleTime;
|
2022-07-23 01:25:37 +08:00
|
|
|
|
2022-07-22 18:48:29 +08:00
|
|
|
private DrawableSample sampleTick;
|
|
|
|
|
2022-07-23 01:25:37 +08:00
|
|
|
public TotalScoreCounter(bool playSamples = false)
|
2020-03-17 16:25:24 +08:00
|
|
|
{
|
|
|
|
// Todo: AutoSize X removed here due to https://github.com/ppy/osu-framework/issues/3369
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
RelativeSizeAxes = Axes.X;
|
2022-07-23 01:25:37 +08:00
|
|
|
|
|
|
|
this.playSamples = playSamples;
|
2022-07-22 18:48:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
{
|
|
|
|
AddInternal(sampleTick = new DrawableSample(audio.Samples.Get(@"Results/score-tick-lesser")));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-07-23 01:25:37 +08:00
|
|
|
if (playSamples)
|
|
|
|
Current.BindValueChanged(_ => startTicking());
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
|
2021-07-24 04:37:08 +08:00
|
|
|
protected override LocalisableString FormatCount(long count) => count.ToString("N0");
|
2020-03-17 16:25:24 +08:00
|
|
|
|
2020-08-19 12:47:02 +08:00
|
|
|
protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().With(s =>
|
2020-08-04 01:14:17 +08:00
|
|
|
{
|
2020-08-19 12:47:02 +08:00
|
|
|
s.Anchor = Anchor.TopCentre;
|
|
|
|
s.Origin = Anchor.TopCentre;
|
2020-08-04 01:14:17 +08:00
|
|
|
|
2020-08-19 12:47:02 +08:00
|
|
|
s.Font = OsuFont.Torus.With(size: 60, weight: FontWeight.Light, fixedWidth: true);
|
|
|
|
s.Spacing = new Vector2(-5, 0);
|
|
|
|
});
|
2022-07-22 18:48:29 +08:00
|
|
|
|
2022-07-23 01:25:37 +08:00
|
|
|
public override long DisplayedCount
|
2022-07-22 18:48:29 +08:00
|
|
|
{
|
2022-07-23 01:25:37 +08:00
|
|
|
get => base.DisplayedCount;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (base.DisplayedCount == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
base.DisplayedCount = value;
|
2022-07-22 18:48:29 +08:00
|
|
|
|
2022-07-23 01:25:37 +08:00
|
|
|
if (playSamples && Time.Current > lastSampleTime + tickPlaybackRate.Value)
|
|
|
|
{
|
|
|
|
sampleTick?.Play();
|
|
|
|
lastSampleTime = Time.Current;
|
|
|
|
}
|
|
|
|
}
|
2022-07-22 18:48:29 +08:00
|
|
|
}
|
|
|
|
|
2022-07-23 01:25:37 +08:00
|
|
|
private void startTicking()
|
2022-07-22 18:48:29 +08:00
|
|
|
{
|
|
|
|
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;
|
2022-07-23 01:25:37 +08:00
|
|
|
|
2022-07-22 18:48:29 +08:00
|
|
|
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_start);
|
2022-07-23 01:38:00 +08:00
|
|
|
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_end, RollingDuration, Easing.OutSine);
|
|
|
|
sampleTick.VolumeTo(tick_volume_start).Then().VolumeTo(tick_volume_end, RollingDuration, Easing.OutSine);
|
2022-07-22 18:48:29 +08:00
|
|
|
}
|
2020-03-17 16:25:24 +08:00
|
|
|
}
|
|
|
|
}
|