Remove Update method processing of samples in PopupDialogDangerousButton

This commit is contained in:
Dean Herbert 2022-06-15 16:50:23 +09:00
parent eac0ca4db6
commit 1f1633ddc2

View File

@ -4,10 +4,10 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Sample; using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Audio.Effects; using osu.Game.Audio.Effects;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -53,37 +53,33 @@ namespace osu.Game.Overlays.Dialog
private Sample tickSample; private Sample tickSample;
private Sample confirmSample; private Sample confirmSample;
private bool isTicking;
private double lastTickPlaybackTime; private double lastTickPlaybackTime;
private AudioFilter lowPassFilter = null!; private AudioFilter lowPassFilter = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)
{ {
lowPassFilter = new AudioFilter(audio.SampleMixer);
tickSample = audio.Samples.Get(@"UI/dialog-dangerous-tick"); tickSample = audio.Samples.Get(@"UI/dialog-dangerous-tick");
confirmSample = audio.Samples.Get(@"UI/dialog-dangerous-select"); confirmSample = audio.Samples.Get(@"UI/dialog-dangerous-select");
AddInternal(lowPassFilter = new AudioFilter(audio.SampleMixer));
} }
protected override void Update() protected override void LoadComplete()
{ {
base.Update(); base.LoadComplete();
Progress.BindValueChanged(progressChanged);
}
if (!isTicking) return; protected override void Confirm()
if (Precision.AlmostEquals(Progress.Value, 1))
{ {
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
confirmSample?.Play(); confirmSample?.Play();
isTicking = false; base.Confirm();
}
if (Clock.CurrentTime - lastTickPlaybackTime >= 30)
playTick(Progress.Value);
} }
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
startTickSound();
BeginConfirm(); BeginConfirm();
return true; return true;
} }
@ -92,34 +88,28 @@ namespace osu.Game.Overlays.Dialog
{ {
if (!e.HasAnyButtonPressed) if (!e.HasAnyButtonPressed)
{ {
stopTickSound();
AbortConfirm(); AbortConfirm();
} }
} }
private void playTick(double progress) private void progressChanged(ValueChangedEvent<double> progress)
{ {
lowPassFilter.CutoffTo((int)(Progress.Value * AudioFilter.MAX_LOWPASS_CUTOFF * 0.5f)); if (progress.NewValue < progress.OldValue)
{
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
return;
}
tickSample.Frequency.Value = 1 + progress * 0.5f; if (Clock.CurrentTime - lastTickPlaybackTime >= 30)
tickSample.Volume.Value = 0.5f + progress / 2f; {
lowPassFilter.CutoffTo((int)(progress.NewValue * AudioFilter.MAX_LOWPASS_CUTOFF * 0.5));
tickSample.Frequency.Value = 1 + progress.NewValue * 0.5f;
tickSample.Volume.Value = 0.5f + progress.NewValue / 2f;
tickSample.Play(); tickSample.Play();
lastTickPlaybackTime = Clock.CurrentTime; lastTickPlaybackTime = Clock.CurrentTime;
} }
private void startTickSound()
{
lowPassFilter.CutoffTo(0);
playTick(Progress.Value);
isTicking = true;
}
private void stopTickSound()
{
isTicking = false;
lastTickPlaybackTime = Clock.CurrentTime;
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
} }
} }
} }