2018-01-05 19:21:19 +08:00
|
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
2017-02-24 12:05:37 +08:00
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2017-02-28 10:31:23 +08:00
|
|
|
|
using System.Collections.Generic;
|
2017-02-24 12:05:37 +08:00
|
|
|
|
using System.Linq;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-02-24 12:05:37 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2017-03-02 16:08:00 +08:00
|
|
|
|
using osu.Framework.Input;
|
2017-02-24 12:05:37 +08:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
2017-03-03 19:27:53 +08:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-03-02 16:14:05 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using OpenTK.Input;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-06-29 01:18:12 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-02-24 12:05:37 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Dialog
|
|
|
|
|
{
|
2017-06-29 01:18:12 +08:00
|
|
|
|
public class PopupDialog : OsuFocusedOverlayContainer
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-03-02 06:41:00 +08:00
|
|
|
|
public static readonly float ENTER_DURATION = 500;
|
|
|
|
|
public static readonly float EXIT_DURATION = 200;
|
2017-02-28 08:55:10 +08:00
|
|
|
|
private readonly Vector2 ringSize = new Vector2(100f);
|
|
|
|
|
private readonly Vector2 ringMinifiedSize = new Vector2(20f);
|
|
|
|
|
private readonly Vector2 buttonsEnterSpacing = new Vector2(0f, 50f);
|
2017-02-24 12:05:37 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container content;
|
|
|
|
|
private readonly Container ring;
|
|
|
|
|
private readonly FillFlowContainer<PopupDialogButton> buttonsContainer;
|
2017-08-03 13:36:21 +08:00
|
|
|
|
private readonly SpriteIcon icon;
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly SpriteText header;
|
2017-12-25 23:34:40 +08:00
|
|
|
|
private readonly TextFlowContainer body;
|
2017-02-24 12:05:37 +08:00
|
|
|
|
|
|
|
|
|
public FontAwesome Icon
|
|
|
|
|
{
|
2017-08-03 13:36:21 +08:00
|
|
|
|
get { return icon.Icon; }
|
|
|
|
|
set { icon.Icon = value; }
|
2017-02-24 12:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string HeaderText
|
|
|
|
|
{
|
2017-03-02 16:14:05 +08:00
|
|
|
|
get { return header.Text; }
|
|
|
|
|
set { header.Text = value; }
|
2017-02-24 12:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string BodyText
|
|
|
|
|
{
|
2017-03-02 16:14:05 +08:00
|
|
|
|
set { body.Text = value; }
|
2017-02-24 12:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 16:14:05 +08:00
|
|
|
|
public IEnumerable<PopupDialogButton> Buttons
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-03-02 16:14:05 +08:00
|
|
|
|
get { return buttonsContainer.Children; }
|
2017-02-24 12:05:37 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
2017-06-24 18:56:35 +08:00
|
|
|
|
buttonsContainer.ChildrenEnumerable = value;
|
2017-02-24 12:05:37 +08:00
|
|
|
|
foreach (PopupDialogButton b in value)
|
|
|
|
|
{
|
|
|
|
|
var action = b.Action;
|
|
|
|
|
b.Action = () =>
|
|
|
|
|
{
|
|
|
|
|
Hide();
|
|
|
|
|
action?.Invoke();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 10:31:23 +08:00
|
|
|
|
private void pressButtonAtIndex(int index)
|
|
|
|
|
{
|
2017-03-02 16:14:05 +08:00
|
|
|
|
if (index < Buttons.Count())
|
2017-05-28 17:34:12 +08:00
|
|
|
|
Buttons.Skip(index).First().TriggerOnClick();
|
2017-02-28 10:31:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 16:08:00 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
2017-02-28 10:31:23 +08:00
|
|
|
|
{
|
|
|
|
|
if (args.Repeat) return false;
|
|
|
|
|
|
2017-06-16 05:06:28 +08:00
|
|
|
|
if (args.Key == Key.Enter || args.Key == Key.KeypadEnter)
|
2017-02-28 10:31:23 +08:00
|
|
|
|
{
|
2017-05-28 17:34:12 +08:00
|
|
|
|
Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.TriggerOnClick();
|
2017-03-02 16:08:00 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-02-28 10:31:23 +08:00
|
|
|
|
|
2017-03-02 16:08:00 +08:00
|
|
|
|
// press button at number if 1-9 on number row or keypad are pressed
|
|
|
|
|
var k = args.Key;
|
|
|
|
|
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;
|
2017-02-28 10:32:30 +08:00
|
|
|
|
}
|
2017-02-28 10:31:23 +08:00
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(state, args);
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-24 12:05:37 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2017-02-28 10:31:23 +08:00
|
|
|
|
base.PopIn();
|
|
|
|
|
|
2017-02-27 11:35:13 +08:00
|
|
|
|
// Reset various animations but only if the dialog animation fully completed
|
|
|
|
|
if (content.Alpha == 0)
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-02-28 08:55:10 +08:00
|
|
|
|
buttonsContainer.TransformSpacingTo(buttonsEnterSpacing);
|
|
|
|
|
buttonsContainer.MoveToY(buttonsEnterSpacing.Y);
|
|
|
|
|
ring.ResizeTo(ringMinifiedSize);
|
2017-02-24 12:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
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);
|
2017-02-24 12:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
2017-02-28 10:31:23 +08:00
|
|
|
|
base.PopOut();
|
|
|
|
|
|
2017-07-23 02:50:25 +08:00
|
|
|
|
content.FadeOut(EXIT_DURATION, Easing.InSine);
|
2017-02-24 12:05:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PopupDialog()
|
|
|
|
|
{
|
2017-02-28 14:09:36 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
content = new Container
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Origin = Anchor.BottomCentre,
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Width = 0.4f,
|
2017-02-28 12:59:36 +08:00
|
|
|
|
Alpha = 0f,
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
new Container
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Masking = true,
|
2017-06-12 11:48:47 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2017-02-27 11:35:13 +08:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.5f),
|
|
|
|
|
Radius = 8,
|
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.FromHex(@"221a21"),
|
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColourLight = OsuColour.FromHex(@"271e26"),
|
|
|
|
|
ColourDark = OsuColour.FromHex(@"1e171e"),
|
|
|
|
|
TriangleScale = 4,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-02-24 12:05:37 +08:00
|
|
|
|
},
|
2017-03-02 15:54:55 +08:00
|
|
|
|
new FillFlowContainer
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Position = new Vector2(0f, -50f),
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Spacing = new Vector2(0f, 10f),
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
2017-02-28 08:55:10 +08:00
|
|
|
|
Size = ringSize,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Bottom = 30,
|
|
|
|
|
},
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
ring = new CircularContainer
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2017-03-22 14:27:22 +08:00
|
|
|
|
Masking = true,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
BorderColour = Color4.White,
|
|
|
|
|
BorderThickness = 5f,
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
new Box
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(0),
|
2017-02-24 12:05:37 +08:00
|
|
|
|
},
|
2017-08-03 13:36:21 +08:00
|
|
|
|
icon = new SpriteIcon
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
2017-02-24 12:05:37 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Icon = FontAwesome.fa_close,
|
2017-08-03 13:36:21 +08:00
|
|
|
|
Size = new Vector2(50),
|
2017-02-24 12:05:37 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-03-03 19:27:53 +08:00
|
|
|
|
header = new OsuSpriteText
|
2017-02-27 11:35:13 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
TextSize = 25,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
},
|
2017-12-25 23:34:40 +08:00
|
|
|
|
body = new OsuTextFlowContainer(t => t.TextSize = 18)
|
2017-02-27 11:35:13 +08:00
|
|
|
|
{
|
2017-12-25 23:34:40 +08:00
|
|
|
|
Padding = new MarginPadding(15),
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
TextAnchor = Anchor.TopCentre,
|
2017-02-27 11:35:13 +08:00
|
|
|
|
},
|
2017-02-24 12:05:37 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
2017-03-02 15:54:55 +08:00
|
|
|
|
buttonsContainer = new FillFlowContainer<PopupDialogButton>
|
2017-02-24 12:05:37 +08:00
|
|
|
|
{
|
2017-02-27 11:35:13 +08:00
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2017-02-24 12:05:37 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-03-02 16:14:05 +08:00
|
|
|
|
}
|