mirror of
https://github.com/ppy/osu
synced 2024-12-14 19:06:07 +00:00
Add audio feedback for 'Dangerous' dialog buttons
This commit is contained in:
parent
930ec2a197
commit
af87722be8
@ -2,9 +2,13 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
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.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
|
||||||
@ -47,8 +51,39 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Sample tickSample;
|
||||||
|
private Sample confirmSample;
|
||||||
|
private bool isTicking;
|
||||||
|
private double lastTickPlaybackTime;
|
||||||
|
private AudioFilter lowPassFilter = null!;
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(AudioManager audio)
|
||||||
|
{
|
||||||
|
lowPassFilter = new AudioFilter(audio.SampleMixer);
|
||||||
|
tickSample = audio.Samples.Get(@"UI/dialog-dangerous-tick");
|
||||||
|
confirmSample = audio.Samples.Get(@"UI/dialog-dangerous-select");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (!isTicking) return;
|
||||||
|
|
||||||
|
if (Precision.AlmostEquals(Progress.Value, 1))
|
||||||
|
{
|
||||||
|
confirmSample?.Play();
|
||||||
|
isTicking = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
@ -56,7 +91,35 @@ namespace osu.Game.Overlays.Dialog
|
|||||||
protected override void OnMouseUp(MouseUpEvent e)
|
protected override void OnMouseUp(MouseUpEvent e)
|
||||||
{
|
{
|
||||||
if (!e.HasAnyButtonPressed)
|
if (!e.HasAnyButtonPressed)
|
||||||
|
{
|
||||||
|
stopTickSound();
|
||||||
AbortConfirm();
|
AbortConfirm();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void playTick(double progress)
|
||||||
|
{
|
||||||
|
lowPassFilter.CutoffTo((int)(Progress.Value * AudioFilter.MAX_LOWPASS_CUTOFF * 0.5f));
|
||||||
|
|
||||||
|
tickSample.Frequency.Value = 1 + progress * 0.5f;
|
||||||
|
tickSample.Volume.Value = 0.5f + progress / 2f;
|
||||||
|
tickSample.Play();
|
||||||
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user