2022-03-21 07:06:32 +00: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 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2022-03-21 07:06:32 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-06-15 03:43:21 +00:00
|
|
|
using osu.Framework.Audio;
|
|
|
|
using osu.Framework.Audio.Sample;
|
2022-06-15 07:50:23 +00:00
|
|
|
using osu.Framework.Bindables;
|
2022-03-21 07:06:32 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Input.Events;
|
2022-06-15 03:43:21 +00:00
|
|
|
using osu.Game.Audio.Effects;
|
2022-03-21 07:06:32 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dialog
|
|
|
|
{
|
|
|
|
public partial class PopupDialogDangerousButton : PopupDialogButton
|
|
|
|
{
|
2022-04-11 18:05:37 +00:00
|
|
|
private Box progressBox;
|
|
|
|
private DangerousConfirmContainer confirmContainer;
|
|
|
|
|
2022-03-21 07:06:32 +00:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
ButtonColour = colours.Red3;
|
|
|
|
|
2022-04-11 18:05:37 +00:00
|
|
|
ColourContainer.Add(progressBox = new Box
|
2022-03-21 07:06:32 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
});
|
2022-04-11 18:05:37 +00:00
|
|
|
|
|
|
|
AddInternal(confirmContainer = new DangerousConfirmContainer
|
|
|
|
{
|
|
|
|
Action = () => Action(),
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
});
|
2022-03-21 07:06:32 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 18:05:37 +00:00
|
|
|
protected override void LoadComplete()
|
2022-03-21 07:06:32 +00:00
|
|
|
{
|
2022-04-11 18:05:37 +00:00
|
|
|
base.LoadComplete();
|
2022-03-21 07:06:32 +00:00
|
|
|
|
2022-04-11 18:05:37 +00:00
|
|
|
confirmContainer.Progress.BindValueChanged(progress => progressBox.Width = (float)progress.NewValue, true);
|
|
|
|
}
|
2022-03-21 07:06:32 +00:00
|
|
|
|
2022-04-11 18:05:37 +00:00
|
|
|
private partial class DangerousConfirmContainer : HoldToConfirmContainer
|
|
|
|
{
|
2022-05-06 05:34:31 +00:00
|
|
|
public DangerousConfirmContainer()
|
|
|
|
: base(isDangerousAction: true)
|
|
|
|
{
|
|
|
|
}
|
2022-03-21 07:06:32 +00:00
|
|
|
|
2022-06-15 03:43:21 +00:00
|
|
|
private Sample tickSample;
|
|
|
|
private Sample confirmSample;
|
|
|
|
private double lastTickPlaybackTime;
|
|
|
|
private AudioFilter lowPassFilter = null!;
|
2023-02-11 03:09:30 +00:00
|
|
|
private bool mouseDown;
|
2022-06-15 03:43:21 +00:00
|
|
|
|
|
|
|
[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 07:50:23 +00:00
|
|
|
|
|
|
|
AddInternal(lowPassFilter = new AudioFilter(audio.SampleMixer));
|
2022-06-15 03:43:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-15 07:50:23 +00:00
|
|
|
protected override void LoadComplete()
|
2022-06-15 03:43:21 +00:00
|
|
|
{
|
2022-06-15 07:50:23 +00:00
|
|
|
base.LoadComplete();
|
|
|
|
Progress.BindValueChanged(progressChanged);
|
|
|
|
}
|
2022-06-15 03:43:21 +00:00
|
|
|
|
2023-02-11 20:54:16 +00:00
|
|
|
protected override void AbortConfirm()
|
|
|
|
{
|
|
|
|
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
|
|
|
|
base.AbortConfirm();
|
|
|
|
}
|
|
|
|
|
2022-06-15 07:50:23 +00:00
|
|
|
protected override void Confirm()
|
|
|
|
{
|
|
|
|
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF);
|
|
|
|
confirmSample?.Play();
|
|
|
|
base.Confirm();
|
2022-06-15 03:43:21 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 07:06:32 +00:00
|
|
|
protected override bool OnMouseDown(MouseDownEvent e)
|
|
|
|
{
|
|
|
|
BeginConfirm();
|
2023-02-11 03:09:30 +00:00
|
|
|
mouseDown = true;
|
2022-03-21 07:06:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnMouseUp(MouseUpEvent e)
|
|
|
|
{
|
|
|
|
if (!e.HasAnyButtonPressed)
|
2022-06-15 03:43:21 +00:00
|
|
|
{
|
2022-03-21 07:06:32 +00:00
|
|
|
AbortConfirm();
|
2023-02-11 03:09:30 +00:00
|
|
|
mouseDown = false;
|
2022-06-15 03:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-11 03:09:30 +00:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
if (mouseDown)
|
|
|
|
BeginConfirm();
|
|
|
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
2023-02-10 05:28:51 +00:00
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
2023-02-11 03:09:30 +00:00
|
|
|
if (!mouseDown) return;
|
2023-02-10 05:28:51 +00:00
|
|
|
|
|
|
|
AbortConfirm();
|
|
|
|
}
|
|
|
|
|
2022-06-15 07:50:23 +00:00
|
|
|
private void progressChanged(ValueChangedEvent<double> progress)
|
2022-06-15 03:43:21 +00:00
|
|
|
{
|
2022-06-15 08:31:45 +00:00
|
|
|
if (progress.NewValue < progress.OldValue) return;
|
2022-06-15 03:43:21 +00:00
|
|
|
|
2022-06-15 08:31:45 +00:00
|
|
|
if (Clock.CurrentTime - lastTickPlaybackTime < 30) return;
|
2022-06-15 03:43:21 +00:00
|
|
|
|
2022-06-15 08:31:45 +00:00
|
|
|
lowPassFilter.CutoffTo((int)(progress.NewValue * AudioFilter.MAX_LOWPASS_CUTOFF * 0.5));
|
2022-06-15 03:43:21 +00:00
|
|
|
|
2022-06-15 08:33:05 +00: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 08:31:45 +00:00
|
|
|
|
|
|
|
lastTickPlaybackTime = Clock.CurrentTime;
|
2022-03-21 07:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|