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