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
|
|
|
|
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Overlays.Dialog;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-09-11 22:35:47 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
using System.Linq;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class DialogOverlay : OsuFocusedOverlayContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly Container dialogContainer;
|
2019-09-19 11:17:58 +00:00
|
|
|
|
|
|
|
|
|
public PopupDialog CurrentDialog { get; private set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-07-02 05:22:37 +00:00
|
|
|
|
public DialogOverlay()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Child = dialogContainer = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Width = 0.4f;
|
|
|
|
|
Anchor = Anchor.BottomCentre;
|
|
|
|
|
Origin = Anchor.BottomCentre;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
public void Push(PopupDialog dialog)
|
|
|
|
|
{
|
2019-09-19 11:17:58 +00:00
|
|
|
|
if (dialog == CurrentDialog) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
|
CurrentDialog?.Hide();
|
|
|
|
|
CurrentDialog = dialog;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
|
dialogContainer.Add(CurrentDialog);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
|
CurrentDialog.Show();
|
|
|
|
|
CurrentDialog.State.ValueChanged += state => onDialogOnStateChanged(dialog, state.NewValue);
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Show();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
protected override bool BlockNonPositionalInput => true;
|
2018-07-02 05:22:37 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private void onDialogOnStateChanged(VisibilityContainer dialog, Visibility v)
|
|
|
|
|
{
|
|
|
|
|
if (v != Visibility.Hidden) return;
|
|
|
|
|
|
|
|
|
|
//handle the dialog being dismissed.
|
|
|
|
|
dialog.Delay(PopupDialog.EXIT_DURATION).Expire();
|
|
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
|
if (dialog == CurrentDialog)
|
|
|
|
|
{
|
2019-06-11 05:28:52 +00:00
|
|
|
|
Hide();
|
2019-09-19 11:17:58 +00:00
|
|
|
|
CurrentDialog = null;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
|
|
|
|
this.FadeIn(PopupDialog.ENTER_DURATION, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
|
|
|
|
|
2019-09-19 11:17:58 +00:00
|
|
|
|
if (CurrentDialog?.State.Value == Visibility.Visible)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-09-19 11:17:58 +00:00
|
|
|
|
CurrentDialog.Hide();
|
2018-07-02 05:22:37 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.FadeOut(PopupDialog.EXIT_DURATION, Easing.InSine);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
2019-09-11 22:35:47 +00:00
|
|
|
|
|
|
|
|
|
public override bool OnPressed(GlobalAction action)
|
|
|
|
|
{
|
|
|
|
|
switch (action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Select:
|
2019-09-19 11:17:58 +00:00
|
|
|
|
CurrentDialog?.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.Click();
|
2019-09-11 22:35:47 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnPressed(action);
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|