2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-02-28 02:31:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-02-24 04:05:37 +00:00
|
|
|
|
using System.Linq;
|
2017-03-04 18:42:37 +00:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-02-24 04:05:37 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-07-02 05:22:37 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-03-27 10:29:27 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-10-30 16:50:13 +00:00
|
|
|
|
using osu.Framework.Localisation;
|
2017-02-24 04:05:37 +00:00
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2018-07-02 05:22:37 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osuTK.Input;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-24 04:05:37 +00:00
|
|
|
|
namespace osu.Game.Overlays.Dialog
|
|
|
|
|
{
|
2019-09-13 06:27:29 +00:00
|
|
|
|
public abstract class PopupDialog : VisibilityContainer
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2019-11-12 12:07:01 +00:00
|
|
|
|
public const float ENTER_DURATION = 500;
|
|
|
|
|
public const float EXIT_DURATION = 200;
|
2018-07-02 05:22:37 +00:00
|
|
|
|
|
2017-02-28 00:55:10 +00:00
|
|
|
|
private readonly Vector2 ringSize = new Vector2(100f);
|
|
|
|
|
private readonly Vector2 ringMinifiedSize = new Vector2(20f);
|
|
|
|
|
private readonly Vector2 buttonsEnterSpacing = new Vector2(0f, 50f);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Container content;
|
|
|
|
|
private readonly Container ring;
|
|
|
|
|
private readonly FillFlowContainer<PopupDialogButton> buttonsContainer;
|
2017-08-03 05:36:21 +00:00
|
|
|
|
private readonly SpriteIcon icon;
|
2018-11-23 06:18:40 +00:00
|
|
|
|
private readonly TextFlowContainer header;
|
2017-12-25 15:34:40 +00:00
|
|
|
|
private readonly TextFlowContainer body;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-02 05:22:37 +00:00
|
|
|
|
private bool actionInvoked;
|
|
|
|
|
|
2019-03-27 10:29:27 +00:00
|
|
|
|
public IconUsage Icon
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2018-07-02 05:22:37 +00:00
|
|
|
|
get => icon.Icon;
|
|
|
|
|
set => icon.Icon = value;
|
2017-02-24 04:05:37 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-30 16:50:13 +00:00
|
|
|
|
private LocalisableString headerText;
|
2018-11-23 06:18:40 +00:00
|
|
|
|
|
2021-10-30 16:50:13 +00:00
|
|
|
|
public LocalisableString HeaderText
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2020-07-06 13:01:45 +00:00
|
|
|
|
get => headerText;
|
2018-11-23 06:18:40 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2020-07-06 13:01:45 +00:00
|
|
|
|
if (headerText == value)
|
2018-11-23 06:18:40 +00:00
|
|
|
|
return;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
|
2020-07-06 13:01:45 +00:00
|
|
|
|
headerText = value;
|
2018-11-23 06:18:40 +00:00
|
|
|
|
header.Text = value;
|
|
|
|
|
}
|
2017-02-24 04:05:37 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-30 16:50:13 +00:00
|
|
|
|
private LocalisableString bodyText;
|
2020-07-06 13:01:45 +00:00
|
|
|
|
|
2021-10-30 16:50:13 +00:00
|
|
|
|
public LocalisableString BodyText
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2020-07-06 13:01:45 +00:00
|
|
|
|
get => bodyText;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (bodyText == value)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
bodyText = value;
|
|
|
|
|
body.Text = value;
|
|
|
|
|
}
|
2017-02-24 04:05:37 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-03-02 08:14:05 +00:00
|
|
|
|
public IEnumerable<PopupDialogButton> Buttons
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2018-07-02 05:22:37 +00:00
|
|
|
|
get => buttonsContainer.Children;
|
2017-02-24 04:05:37 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-24 10:56:35 +00:00
|
|
|
|
buttonsContainer.ChildrenEnumerable = value;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2017-02-24 04:05:37 +00:00
|
|
|
|
foreach (PopupDialogButton b in value)
|
|
|
|
|
{
|
|
|
|
|
var action = b.Action;
|
|
|
|
|
b.Action = () =>
|
|
|
|
|
{
|
2018-07-02 05:22:37 +00:00
|
|
|
|
if (actionInvoked) return;
|
|
|
|
|
|
2022-04-14 08:51:50 +00:00
|
|
|
|
actionInvoked = true;
|
|
|
|
|
|
2022-04-14 06:58:03 +00: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();
|
|
|
|
|
|
2017-02-24 04:05:37 +00:00
|
|
|
|
action?.Invoke();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-13 06:42:36 +00:00
|
|
|
|
protected PopupDialog()
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2017-02-28 06:09:36 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-24 04:05:37 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
content = new Container
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-28 04:59:36 +00:00
|
|
|
|
Alpha = 0f,
|
2017-02-24 04:05:37 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
new Container
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Masking = true,
|
2017-06-12 03:48:47 +00:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-02-27 03:35:13 +00:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
|
|
|
|
Radius = 8,
|
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 01:18:41 +00:00
|
|
|
|
Colour = Color4Extensions.FromHex(@"221a21"),
|
2017-02-27 03:35:13 +00:00
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-03-11 01:18:41 +00:00
|
|
|
|
ColourLight = Color4Extensions.FromHex(@"271e26"),
|
|
|
|
|
ColourDark = Color4Extensions.FromHex(@"1e171e"),
|
2017-02-27 03:35:13 +00:00
|
|
|
|
TriangleScale = 4,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-02-24 04:05:37 +00:00
|
|
|
|
},
|
2017-03-02 07:54:55 +00:00
|
|
|
|
new FillFlowContainer
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-03-04 10:00:17 +00:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2019-06-24 02:43:30 +00:00
|
|
|
|
Spacing = new Vector2(0f, 10f),
|
|
|
|
|
Padding = new MarginPadding { Bottom = 10 },
|
2017-02-24 04:05:37 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2017-02-28 00:55:10 +00:00
|
|
|
|
Size = ringSize,
|
2017-02-24 04:05:37 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
ring = new CircularContainer
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-22 06:27:22 +00:00
|
|
|
|
Masking = true,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
BorderThickness = 5f,
|
2017-02-24 04:05:37 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
new Box
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0),
|
2017-02-24 04:05:37 +00:00
|
|
|
|
},
|
2017-08-03 05:36:21 +00:00
|
|
|
|
icon = new SpriteIcon
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-24 04:05:37 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
2019-04-02 10:55:24 +00:00
|
|
|
|
Icon = FontAwesome.Solid.TimesCircle,
|
2017-08-03 05:36:21 +00:00
|
|
|
|
Size = new Vector2(50),
|
2017-02-24 04:05:37 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2019-02-20 10:32:30 +00:00
|
|
|
|
header = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 25))
|
2017-02-27 03:35:13 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2018-11-23 06:18:40 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
},
|
2019-02-20 10:32:30 +00:00
|
|
|
|
body = new OsuTextFlowContainer(t => t.Font = t.Font.With(size: 18))
|
2017-02-27 03:35:13 +00:00
|
|
|
|
{
|
2019-06-24 02:43:30 +00:00
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
2017-12-25 15:34:40 +00:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-02-27 03:35:13 +00:00
|
|
|
|
},
|
2017-02-24 04:05:37 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
2017-03-02 07:54:55 +00:00
|
|
|
|
buttonsContainer = new FillFlowContainer<PopupDialogButton>
|
2017-02-24 04:05:37 +00:00
|
|
|
|
{
|
2017-02-27 03:35:13 +00:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-03-04 10:00:17 +00:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-02-24 04:05:37 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
2021-05-19 07:52:34 +00:00
|
|
|
|
|
|
|
|
|
// It's important we start in a visible state so our state fires on hide, even before load.
|
2022-04-18 18:07:20 +00:00
|
|
|
|
// This is used by the dialog overlay to know when the dialog was dismissed.
|
2021-05-19 07:52:34 +00:00
|
|
|
|
Show();
|
2017-02-24 04:05:37 +00:00
|
|
|
|
}
|
2018-07-02 05:22:37 +00:00
|
|
|
|
|
2021-05-19 07:26:27 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Programmatically clicks the first <see cref="PopupDialogOkButton"/>.
|
|
|
|
|
/// </summary>
|
2022-03-22 05:46:57 +00:00
|
|
|
|
public void PerformOkAction() => PerformAction<PopupDialogOkButton>();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Programmatically clicks the first button of the provided type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void PerformAction<T>() where T : PopupDialogButton => Buttons.OfType<T>().First().TriggerClick();
|
2021-05-19 07:26:27 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
2018-07-03 09:37:21 +00:00
|
|
|
|
{
|
2018-10-02 03:02:47 +00:00
|
|
|
|
if (e.Repeat) return false;
|
2018-07-03 09:37:21 +00:00
|
|
|
|
|
2018-07-02 05:22:37 +00:00
|
|
|
|
// press button at number if 1-9 on number row or keypad are pressed
|
2018-10-02 03:02:47 +00:00
|
|
|
|
var k = e.Key;
|
2019-04-01 03:16:05 +00:00
|
|
|
|
|
2018-07-02 05:22:37 +00: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 03:02:47 +00:00
|
|
|
|
return base.OnKeyDown(e);
|
2018-07-02 05:22:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
actionInvoked = false;
|
|
|
|
|
|
|
|
|
|
// Reset various animations but only if the dialog animation fully completed
|
|
|
|
|
if (content.Alpha == 0)
|
|
|
|
|
{
|
|
|
|
|
buttonsContainer.TransformSpacingTo(buttonsEnterSpacing);
|
|
|
|
|
buttonsContainer.MoveToY(buttonsEnterSpacing.Y);
|
|
|
|
|
ring.ResizeTo(ringMinifiedSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content.FadeIn(ENTER_DURATION, Easing.OutQuint);
|
|
|
|
|
ring.ResizeTo(ringSize, ENTER_DURATION, Easing.OutQuint);
|
|
|
|
|
buttonsContainer.TransformSpacingTo(Vector2.Zero, ENTER_DURATION, Easing.OutQuint);
|
|
|
|
|
buttonsContainer.MoveToY(0, ENTER_DURATION, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2022-05-04 16:27:53 +00:00
|
|
|
|
if (!actionInvoked)
|
2018-07-02 08:48:16 +00: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 08:27:44 +00:00
|
|
|
|
buttonsContainer.Last().TriggerClick();
|
2018-07-02 05:22:37 +00:00
|
|
|
|
|
|
|
|
|
content.FadeOut(EXIT_DURATION, Easing.InSine);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void pressButtonAtIndex(int index)
|
|
|
|
|
{
|
|
|
|
|
if (index < Buttons.Count())
|
2021-08-04 08:27:44 +00:00
|
|
|
|
Buttons.Skip(index).First().TriggerClick();
|
2018-07-02 05:22:37 +00:00
|
|
|
|
}
|
2017-02-24 04:05:37 +00:00
|
|
|
|
}
|
2017-03-02 08:14:05 +00:00
|
|
|
|
}
|