Add DangerousButton for use in popup dialogs

This commit is contained in:
Dean Herbert 2022-03-21 16:06:32 +09:00
parent 31570d3114
commit b42081dd9b
3 changed files with 73 additions and 9 deletions

View File

@ -40,6 +40,10 @@ namespace osu.Game.Tests.Visual.UserInterface
{ {
Text = @"You're a fake!", Text = @"You're a fake!",
}, },
new PopupDialogDangerousButton
{
Text = @"Careful with this one..",
},
}; };
} }
} }

View File

@ -45,8 +45,9 @@ namespace osu.Game.Graphics.UserInterface
} }
} }
protected readonly Container ColourContainer;
private readonly Container backgroundContainer; private readonly Container backgroundContainer;
private readonly Container colourContainer;
private readonly Container glowContainer; private readonly Container glowContainer;
private readonly Box leftGlow; private readonly Box leftGlow;
private readonly Box centerGlow; private readonly Box centerGlow;
@ -113,7 +114,7 @@ namespace osu.Game.Graphics.UserInterface
Masking = true, Masking = true,
Children = new Drawable[] Children = new Drawable[]
{ {
colourContainer = new Container ColourContainer = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -182,7 +183,7 @@ namespace osu.Game.Graphics.UserInterface
{ {
buttonColour = value; buttonColour = value;
updateGlow(); updateGlow();
colourContainer.Colour = value; ColourContainer.Colour = value;
} }
} }
@ -230,11 +231,11 @@ namespace osu.Game.Graphics.UserInterface
Alpha = 0.05f Alpha = 0.05f
}; };
colourContainer.Add(flash); ColourContainer.Add(flash);
flash.FadeOutFromOne(100).Expire(); flash.FadeOutFromOne(100).Expire();
clickAnimating = true; clickAnimating = true;
colourContainer.ResizeWidthTo(colourContainer.Width * 1.05f, 100, Easing.OutQuint) ColourContainer.ResizeWidthTo(ColourContainer.Width * 1.05f, 100, Easing.OutQuint)
.OnComplete(_ => .OnComplete(_ =>
{ {
clickAnimating = false; clickAnimating = false;
@ -246,14 +247,14 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnMouseDown(MouseDownEvent e) protected override bool OnMouseDown(MouseDownEvent e)
{ {
colourContainer.ResizeWidthTo(hover_width * 0.98f, click_duration * 4, Easing.OutQuad); ColourContainer.ResizeWidthTo(hover_width * 0.98f, click_duration * 4, Easing.OutQuad);
return base.OnMouseDown(e); return base.OnMouseDown(e);
} }
protected override void OnMouseUp(MouseUpEvent e) protected override void OnMouseUp(MouseUpEvent e)
{ {
if (State == SelectionState.Selected) if (State == SelectionState.Selected)
colourContainer.ResizeWidthTo(hover_width, click_duration, Easing.In); ColourContainer.ResizeWidthTo(hover_width, click_duration, Easing.In);
base.OnMouseUp(e); base.OnMouseUp(e);
} }
@ -279,12 +280,12 @@ namespace osu.Game.Graphics.UserInterface
if (newState == SelectionState.Selected) if (newState == SelectionState.Selected)
{ {
spriteText.TransformSpacingTo(hoverSpacing, hover_duration, Easing.OutElastic); spriteText.TransformSpacingTo(hoverSpacing, hover_duration, Easing.OutElastic);
colourContainer.ResizeWidthTo(hover_width, hover_duration, Easing.OutElastic); ColourContainer.ResizeWidthTo(hover_width, hover_duration, Easing.OutElastic);
glowContainer.FadeIn(hover_duration, Easing.OutQuint); glowContainer.FadeIn(hover_duration, Easing.OutQuint);
} }
else else
{ {
colourContainer.ResizeWidthTo(idle_width, hover_duration, Easing.OutElastic); ColourContainer.ResizeWidthTo(idle_width, hover_duration, Easing.OutElastic);
spriteText.TransformSpacingTo(Vector2.Zero, hover_duration, Easing.OutElastic); spriteText.TransformSpacingTo(Vector2.Zero, hover_duration, Easing.OutElastic);
glowContainer.FadeOut(hover_duration, Easing.OutQuint); glowContainer.FadeOut(hover_duration, Easing.OutQuint);
} }

View File

@ -0,0 +1,59 @@
// 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
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
ButtonColour = colours.Red3;
ColourContainer.Add(new ConfirmFillBox
{
Action = () => Action(),
RelativeSizeAxes = Axes.Both,
Blending = BlendingParameters.Additive,
});
}
private class ConfirmFillBox : HoldToConfirmContainer
{
private Box box;
protected override double? HoldActivationDelay => 500;
protected override void LoadComplete()
{
base.LoadComplete();
Child = box = new Box
{
RelativeSizeAxes = Axes.Both,
};
Progress.BindValueChanged(progress => box.Width = (float)progress.NewValue, true);
}
protected override bool OnMouseDown(MouseDownEvent e)
{
BeginConfirm();
return true;
}
protected override void OnMouseUp(MouseUpEvent e)
{
if (!e.HasAnyButtonPressed)
AbortConfirm();
}
}
}
}