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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
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
|
|
|
|
{
|
|
|
|
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
|
|
|
|
{
|
|
|
|
protected override double? HoldActivationDelay => 500;
|
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)
|
|
|
|
AbortConfirm();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|