2022-03-21 15:06:32 +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-03-21 15:06:32 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-06-15 11:43:21 +08:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2022-06-15 15:50:23 +08:00
|
|
|
using osu.Framework.Bindables;
|
2022-03-21 15:06:32 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-06-15 11:43:21 +08:00
|
|
|
using osu.Game.Audio.Effects;
|
2022-03-21 15:06:32 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dialog
|
|
|
|
{
|
|
|
|
public class PopupDialogDangerousButton : PopupDialogButton
|
|
|
|
{
|
2022-04-12 02:05:37 +08:00
|
|
|
private Box progressBox;
|
|
|
|
private DangerousConfirmContainer confirmContainer;
|
|
|
|
|
2022-03-21 15:06:32 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
ButtonColour = colours.Red3;
|
|
|
|
|
2022-04-12 02:05:37 +08:00
|
|
|
ColourContainer.Add(progressBox = new Box
|
2022-03-21 15:06:32 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
});
|
2022-04-12 02:05:37 +08:00
|
|
|
|
|
|
|
AddInternal(confirmContainer = new DangerousConfirmContainer
|
|
|
|
{
|
|
|
|
Action = () => Action(),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
});
|
2022-03-21 15:06:32 +08:00
|
|
|
}
|
|
|
|
|
2022-04-12 02:05:37 +08:00
|
|
|
protected override void LoadComplete()
|
2022-03-21 15:06:32 +08:00
|
|
|
{
|
2022-04-12 02:05:37 +08:00
|
|
|
base.LoadComplete();
|
2022-03-21 15:06:32 +08:00
|
|
|
|
2022-04-12 02:05:37 +08:00
|
|
|
confirmContainer.Progress.BindValueChanged(progress => progressBox.Width = (float)progress.NewValue, true);
|
|
|
|
}
|
2022-03-21 15:06:32 +08:00
|
|
|
|
2022-04-12 02:05:37 +08:00
|
|
|
private class DangerousConfirmContainer : HoldToConfirmContainer
|
|
|
|
{
|
2022-05-06 13:34:31 +08:00
|
|
|
public DangerousConfirmContainer()
|
|
|
|
: base(isDangerousAction: true)
|
|
|
|
{
|
|
|
|
}
|
2022-03-21 15:06:32 +08:00
|
|
|
|
2022-06-15 11:43:21 +08:00
|
|
|
private Sample tickSample;
|
|
|
|
private Sample confirmSample;
|
|
|
|
private double lastTickPlaybackTime;
|
|
|
|
private AudioFilter lowPassFilter = null!;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
{
|
|
|
|
tickSample = audio.Samples.Get(@"UI/dialog-dangerous-tick");
|
|
|
|
confirmSample = audio.Samples.Get(@"UI/dialog-dangerous-select");
|
2022-06-15 15:50:23 +08:00
|
|
|
|
|
|
|
AddInternal(lowPassFilter = new AudioFilter(audio.SampleMixer));
|
2022-06-15 11:43:21 +08:00
|
|
|
}
|
|
|
|
|
2022-06-15 15:50:23 +08:00
|
|
|
protected override void LoadComplete()
|
2022-06-15 11:43:21 +08:00
|
|
|
{
|
2022-06-15 15:50:23 +08:00
|
|
|
base.LoadComplete();
|
|
|
|
Progress.BindValueChanged(progressChanged);
|
|
|
|
}
|
2022-06-15 11:43:21 +08:00
|
|
|
|
2022-06-15 15:50:23 +08:00
|
|
|
protected override void Confirm()
|
|
|
|
{
|
|
|
|
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
|
|
|
|
confirmSample?.Play();
|
|
|
|
base.Confirm();
|
2022-06-15 11:43:21 +08:00
|
|
|
}
|
|
|
|
|
2022-03-21 15:06:32 +08:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
BeginConfirm();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
if (!e.HasAnyButtonPressed)
|
2022-06-15 11:43:21 +08:00
|
|
|
{
|
2022-06-15 16:31:45 +08:00
|
|
|
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
|
2022-03-21 15:06:32 +08:00
|
|
|
AbortConfirm();
|
2022-06-15 11:43:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-15 15:50:23 +08:00
|
|
|
private void progressChanged(ValueChangedEvent<double> progress)
|
2022-06-15 11:43:21 +08:00
|
|
|
{
|
2022-06-15 16:31:45 +08:00
|
|
|
if (progress.NewValue < progress.OldValue) return;
|
2022-06-15 11:43:21 +08:00
|
|
|
|
2022-06-15 16:31:45 +08:00
|
|
|
if (Clock.CurrentTime - lastTickPlaybackTime < 30) return;
|
2022-06-15 11:43:21 +08:00
|
|
|
|
2022-06-15 16:31:45 +08:00
|
|
|
lowPassFilter.CutoffTo((int)(progress.NewValue * AudioFilter.MAX_LOWPASS_CUTOFF * 0.5));
|
2022-06-15 11:43:21 +08:00
|
|
|
|
2022-06-15 16:33:05 +08:00
|
|
|
var channel = tickSample.GetChannel();
|
|
|
|
|
|
|
|
channel.Frequency.Value = 1 + progress.NewValue * 0.5f;
|
|
|
|
channel.Volume.Value = 0.5f + progress.NewValue / 2f;
|
|
|
|
|
|
|
|
channel.Play();
|
2022-06-15 16:31:45 +08:00
|
|
|
|
|
|
|
lastTickPlaybackTime = Clock.CurrentTime;
|
2022-03-21 15:06:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|