2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2023-09-28 14:15:09 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-07-02 13:22:37 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 18:29:27 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-10-31 00:50:13 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2023-12-28 18:04:19 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2018-07-02 13:22:37 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dialog
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public abstract partial class PopupDialog : VisibilityContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-11-12 20:07:01 +08:00
|
|
|
|
public const float ENTER_DURATION = 500;
|
2023-12-28 18:04:19 +08:00
|
|
|
|
public const float EXIT_DURATION = 500;
|
2018-07-02 13:22:37 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly Vector2 ringSize = new Vector2(100f);
|
|
|
|
|
private readonly Vector2 ringMinifiedSize = new Vector2(20f);
|
|
|
|
|
|
2023-09-28 14:15:09 +08:00
|
|
|
|
private readonly Box flashLayer;
|
2024-01-04 14:22:25 +08:00
|
|
|
|
private Sample? flashSample;
|
2023-09-28 14:15:09 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly Container content;
|
|
|
|
|
private readonly Container ring;
|
|
|
|
|
private readonly FillFlowContainer<PopupDialogButton> buttonsContainer;
|
|
|
|
|
private readonly SpriteIcon icon;
|
2018-11-23 14:18:40 +08:00
|
|
|
|
private readonly TextFlowContainer header;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private readonly TextFlowContainer body;
|
|
|
|
|
|
2018-07-02 13:22:37 +08:00
|
|
|
|
private bool actionInvoked;
|
|
|
|
|
|
2019-03-27 18:29:27 +08:00
|
|
|
|
public IconUsage Icon
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-07-02 13:22:37 +08:00
|
|
|
|
get => icon.Icon;
|
|
|
|
|
set => icon.Icon = value;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-31 00:50:13 +08:00
|
|
|
|
private LocalisableString headerText;
|
2018-11-23 14:18:40 +08:00
|
|
|
|
|
2021-10-31 00:50:13 +08:00
|
|
|
|
public LocalisableString HeaderText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-07-06 21:01:45 +08:00
|
|
|
|
get => headerText;
|
2018-11-23 14:18:40 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-07-06 21:01:45 +08:00
|
|
|
|
if (headerText == value)
|
2018-11-23 14:18:40 +08:00
|
|
|
|
return;
|
2019-02-28 12:31:40 +08:00
|
|
|
|
|
2020-07-06 21:01:45 +08:00
|
|
|
|
headerText = value;
|
2018-11-23 14:18:40 +08:00
|
|
|
|
header.Text = value;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-31 00:50:13 +08:00
|
|
|
|
private LocalisableString bodyText;
|
2020-07-06 21:01:45 +08:00
|
|
|
|
|
2021-10-31 00:50:13 +08:00
|
|
|
|
public LocalisableString BodyText
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2020-07-06 21:01:45 +08:00
|
|
|
|
get => bodyText;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (bodyText == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bodyText = value;
|
|
|
|
|
body.Text = value;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<PopupDialogButton> Buttons
|
|
|
|
|
{
|
2018-07-02 13:22:37 +08:00
|
|
|
|
get => buttonsContainer.Children;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
buttonsContainer.ChildrenEnumerable = value;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
foreach (PopupDialogButton b in value)
|
|
|
|
|
{
|
|
|
|
|
var action = b.Action;
|
|
|
|
|
b.Action = () =>
|
|
|
|
|
{
|
2018-07-02 13:22:37 +08:00
|
|
|
|
if (actionInvoked) return;
|
|
|
|
|
|
2022-04-14 16:51:50 +08:00
|
|
|
|
actionInvoked = true;
|
|
|
|
|
|
2022-04-14 14:58:03 +08:00
|
|
|
|
// Hide the dialog before running the action.
|
|
|
|
|
// This is important as the code which is performed may check for a dialog being present (ie. `OsuGame.PerformFromScreen`)
|
|
|
|
|
// and we don't want it to see the already dismissed dialog.
|
|
|
|
|
Hide();
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
action?.Invoke();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 14:42:36 +08:00
|
|
|
|
protected PopupDialog()
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2023-12-28 18:04:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
content = new Container
|
|
|
|
|
{
|
2023-12-28 18:04:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Alpha = 0f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
2023-12-28 18:04:19 +08:00
|
|
|
|
CornerRadius = 20,
|
|
|
|
|
CornerExponent = 2.5f,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
2023-12-28 18:04:19 +08:00
|
|
|
|
Colour = Color4.Black.Opacity(0.2f),
|
|
|
|
|
Radius = 14,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 09:18:41 +08:00
|
|
|
|
Colour = Color4Extensions.FromHex(@"221a21"),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 09:18:41 +08:00
|
|
|
|
ColourLight = Color4Extensions.FromHex(@"271e26"),
|
|
|
|
|
ColourDark = Color4Extensions.FromHex(@"1e171e"),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
TriangleScale = 4,
|
|
|
|
|
},
|
2023-12-28 18:04:19 +08:00
|
|
|
|
flashLayer = new Box
|
|
|
|
|
{
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
|
Colour = Color4Extensions.FromHex(@"221a21"),
|
|
|
|
|
},
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
2019-06-24 10:43:30 +08:00
|
|
|
|
Spacing = new Vector2(0f, 10f),
|
2023-12-28 18:04:19 +08:00
|
|
|
|
Padding = new MarginPadding { Vertical = 60 },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2023-12-28 18:04:19 +08:00
|
|
|
|
Padding = new MarginPadding { Bottom = 30 },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Size = ringSize,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
ring = new CircularContainer
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
BorderThickness = 5f,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0),
|
|
|
|
|
},
|
|
|
|
|
icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.TimesCircle,
|
2023-12-28 18:04:19 +08:00
|
|
|
|
Y = -2,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Size = new Vector2(50),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-02-20 18:32:30 +08:00
|
|
|
|
header = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 25))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2018-11-23 14:18:40 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
2023-12-28 19:29:56 +08:00
|
|
|
|
Padding = new MarginPadding { Horizontal = 5 },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2019-02-20 18:32:30 +08:00
|
|
|
|
body = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 18))
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-06-24 10:43:30 +08:00
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2023-12-28 19:29:56 +08:00
|
|
|
|
Padding = new MarginPadding { Horizontal = 5 },
|
2023-12-28 18:04:19 +08:00
|
|
|
|
},
|
|
|
|
|
buttonsContainer = new FillFlowContainer<PopupDialogButton>
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Padding = new MarginPadding { Top = 30 },
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-05-19 15:52:34 +08:00
|
|
|
|
|
|
|
|
|
// It's important we start in a visible state so our state fires on hide, even before load.
|
2022-04-19 02:07:20 +08:00
|
|
|
|
// This is used by the dialog overlay to know when the dialog was dismissed.
|
2021-05-19 15:52:34 +08:00
|
|
|
|
Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
2018-07-02 13:22:37 +08:00
|
|
|
|
|
2023-09-28 14:15:09 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2023-12-28 18:04:19 +08:00
|
|
|
|
private void load(AudioManager audio, OsuColour colours)
|
2023-09-28 14:15:09 +08:00
|
|
|
|
{
|
|
|
|
|
flashSample = audio.Samples.Get(@"UI/default-select-disabled");
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 15:26:27 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Programmatically clicks the first <see cref="PopupDialogOkButton"/>.
|
|
|
|
|
/// </summary>
|
2022-03-22 13:46:57 +08:00
|
|
|
|
public void PerformOkAction() => PerformAction<PopupDialogOkButton>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Programmatically clicks the first button of the provided type.
|
|
|
|
|
/// </summary>
|
2023-07-06 16:58:27 +08:00
|
|
|
|
public void PerformAction<T>() where T : PopupDialogButton
|
|
|
|
|
{
|
|
|
|
|
// Buttons are regularly added in BDL or LoadComplete, so let's schedule to ensure
|
|
|
|
|
// they are ready to be pressed.
|
2023-07-17 01:43:37 +08:00
|
|
|
|
Scheduler.AddOnce(() => Buttons.OfType<T>().FirstOrDefault()?.TriggerClick());
|
2023-07-06 16:58:27 +08:00
|
|
|
|
}
|
2021-05-19 15:26:27 +08:00
|
|
|
|
|
2023-09-28 14:15:09 +08:00
|
|
|
|
public void Flash()
|
|
|
|
|
{
|
|
|
|
|
flashLayer.FadeInFromZero(80, Easing.OutQuint)
|
|
|
|
|
.Then()
|
|
|
|
|
.FadeOutFromOne(1500, Easing.OutQuint);
|
2024-01-04 14:22:25 +08:00
|
|
|
|
flashSample?.Play();
|
2023-09-28 14:15:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-07-03 17:37:21 +08:00
|
|
|
|
{
|
2018-10-02 11:02:47 +08:00
|
|
|
|
if (e.Repeat) return false;
|
2018-07-03 17:37:21 +08:00
|
|
|
|
|
2018-07-02 13:22:37 +08:00
|
|
|
|
// press button at number if 1-9 on number row or keypad are pressed
|
2018-10-02 11:02:47 +08:00
|
|
|
|
var k = e.Key;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-07-02 13:22:37 +08:00
|
|
|
|
if (k >= Key.Number1 && k <= Key.Number9)
|
|
|
|
|
{
|
|
|
|
|
pressButtonAtIndex(k - Key.Number1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (k >= Key.Keypad1 && k <= Key.Keypad9)
|
|
|
|
|
{
|
|
|
|
|
pressButtonAtIndex(k - Key.Keypad1);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnKeyDown(e);
|
2018-07-02 13:22:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
actionInvoked = false;
|
|
|
|
|
|
|
|
|
|
// Reset various animations but only if the dialog animation fully completed
|
|
|
|
|
if (content.Alpha == 0)
|
|
|
|
|
{
|
2023-12-28 18:04:19 +08:00
|
|
|
|
content.ScaleTo(0.7f);
|
2018-07-02 13:22:37 +08:00
|
|
|
|
ring.ResizeTo(ringMinifiedSize);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-28 18:04:19 +08:00
|
|
|
|
content
|
|
|
|
|
.ScaleTo(1, 750, Easing.OutElasticHalf)
|
|
|
|
|
.FadeIn(ENTER_DURATION, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
ring.ResizeTo(ringSize, ENTER_DURATION * 1.5f, Easing.OutQuint);
|
2018-07-02 13:22:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2022-05-05 00:27:53 +08:00
|
|
|
|
if (!actionInvoked)
|
2018-07-02 16:48:16 +08:00
|
|
|
|
// In the case a user did not choose an action before a hide was triggered, press the last button.
|
|
|
|
|
// This is presumed to always be a sane default "cancel" action.
|
2021-08-04 16:27:44 +08:00
|
|
|
|
buttonsContainer.Last().TriggerClick();
|
2018-07-02 13:22:37 +08:00
|
|
|
|
|
2023-12-28 18:04:19 +08:00
|
|
|
|
content
|
|
|
|
|
.ScaleTo(0.7f, EXIT_DURATION, Easing.Out)
|
|
|
|
|
.FadeOut(EXIT_DURATION, Easing.OutQuint);
|
2018-07-02 13:22:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pressButtonAtIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index < Buttons.Count())
|
2021-08-04 16:27:44 +08:00
|
|
|
|
Buttons.Skip(index).First().TriggerClick();
|
2018-07-02 13:22:37 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|