1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-07 00:27:26 +08:00
osu-lazer/osu.Game/Overlays/DialogOverlay.cs

91 lines
2.4 KiB
C#
Raw Normal View History

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