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
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2024-07-04 13:23:35 +08:00
|
|
|
|
using System;
|
2017-02-28 12:59:36 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Overlays.Dialog;
|
2017-06-29 01:18:12 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-09-12 06:35:47 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
using System.Linq;
|
2021-09-23 19:14:32 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-09-16 17:26:12 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-28 12:59:36 +08:00
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2022-04-18 17:09:14 +08:00
|
|
|
|
public partial class DialogOverlay : OsuFocusedOverlayContainer, IDialogOverlay
|
2017-02-28 12:59:36 +08:00
|
|
|
|
{
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container dialogContainer;
|
2019-09-19 19:17:58 +08:00
|
|
|
|
|
2021-01-15 13:57:46 +08:00
|
|
|
|
protected override string PopInSampleName => "UI/dialog-pop-in";
|
|
|
|
|
protected override string PopOutSampleName => "UI/dialog-pop-out";
|
|
|
|
|
|
2024-06-22 00:57:14 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private MusicController musicController { get; set; }
|
2021-09-23 19:14:32 +08:00
|
|
|
|
|
2019-09-19 19:17:58 +08:00
|
|
|
|
public PopupDialog CurrentDialog { get; private set; }
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2024-02-26 21:16:15 +08:00
|
|
|
|
public override bool IsPresent => Scheduler.HasPendingTasks
|
2024-06-22 00:57:14 +08:00
|
|
|
|
|| dialogContainer.Children.Count > 0;
|
2024-02-26 21:16:15 +08:00
|
|
|
|
|
2024-07-04 13:23:35 +08:00
|
|
|
|
private IDisposable? audioDucker;
|
|
|
|
|
|
2018-07-02 13:22:37 +08:00
|
|
|
|
public DialogOverlay()
|
|
|
|
|
{
|
2023-12-28 18:04:19 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2018-07-02 13:22:37 +08:00
|
|
|
|
|
|
|
|
|
Child = dialogContainer = new Container
|
|
|
|
|
{
|
2023-12-28 18:04:19 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2018-07-02 13:22:37 +08:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-28 18:04:19 +08:00
|
|
|
|
Width = 500;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
2018-07-02 13:22:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-04 13:23:35 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
audioDucker?.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 12:59:36 +08:00
|
|
|
|
public void Push(PopupDialog dialog)
|
|
|
|
|
{
|
2022-07-14 13:00:33 +08:00
|
|
|
|
if (dialog == CurrentDialog || dialog.State.Value == Visibility.Hidden) return;
|
2022-05-05 13:55:05 +08:00
|
|
|
|
|
|
|
|
|
// Immediately update the externally accessible property as this may be used for checks even before
|
|
|
|
|
// a DialogOverlay instance has finished loading.
|
2022-07-14 13:00:33 +08:00
|
|
|
|
var lastDialog = CurrentDialog;
|
2019-09-19 19:17:58 +08:00
|
|
|
|
CurrentDialog = dialog;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-14 12:06:03 +08:00
|
|
|
|
Schedule(() =>
|
2022-05-05 00:52:39 +08:00
|
|
|
|
{
|
|
|
|
|
// if any existing dialog is being displayed, dismiss it before showing a new one.
|
|
|
|
|
lastDialog?.Hide();
|
2022-07-14 12:04:46 +08:00
|
|
|
|
|
2022-07-15 10:56:49 +08:00
|
|
|
|
// if the new dialog is hidden before added to the dialogContainer, bypass any further operations.
|
2022-07-14 13:00:33 +08:00
|
|
|
|
if (dialog.State.Value == Visibility.Hidden)
|
|
|
|
|
{
|
|
|
|
|
dismiss();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-05-05 00:52:39 +08:00
|
|
|
|
|
2022-07-14 13:00:33 +08:00
|
|
|
|
dialogContainer.Add(dialog);
|
2022-05-05 00:52:39 +08:00
|
|
|
|
Show();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-14 13:00:33 +08:00
|
|
|
|
dialog.State.BindValueChanged(state =>
|
|
|
|
|
{
|
|
|
|
|
if (state.NewValue != Visibility.Hidden) return;
|
2021-09-23 18:19:03 +08:00
|
|
|
|
|
2022-07-14 13:00:33 +08:00
|
|
|
|
// Trigger the demise of the dialog as soon as it hides.
|
|
|
|
|
dialog.Delay(PopupDialog.EXIT_DURATION).Expire();
|
2018-07-02 13:22:37 +08:00
|
|
|
|
|
2022-07-14 13:00:33 +08:00
|
|
|
|
dismiss();
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-14 13:00:33 +08:00
|
|
|
|
void dismiss()
|
2019-09-19 19:17:58 +08:00
|
|
|
|
{
|
2022-07-14 13:00:33 +08:00
|
|
|
|
if (dialog != CurrentDialog) return;
|
|
|
|
|
|
|
|
|
|
// Handle the case where the dialog is the currently displayed dialog.
|
|
|
|
|
// In this scenario, the overlay itself should also be hidden.
|
2019-06-11 13:28:52 +08:00
|
|
|
|
Hide();
|
2019-09-19 19:17:58 +08:00
|
|
|
|
CurrentDialog = null;
|
|
|
|
|
}
|
2017-02-28 12:59:36 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-14 13:00:33 +08:00
|
|
|
|
protected override bool BlockNonPositionalInput => true;
|
|
|
|
|
|
2017-02-28 12:59:36 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
2024-07-04 13:23:35 +08:00
|
|
|
|
audioDucker = musicController.Duck(100, 1f, unduckDuration: 100);
|
2017-02-28 12:59:36 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-02-28 12:59:36 +08:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
2024-07-04 13:23:35 +08:00
|
|
|
|
audioDucker?.Dispose();
|
2018-07-02 13:22:37 +08:00
|
|
|
|
|
2022-07-14 12:06:57 +08:00
|
|
|
|
// PopOut gets called initially, but we only want to hide dialog when we have been loaded and are present.
|
|
|
|
|
if (IsLoaded && CurrentDialog?.State.Value == Visibility.Visible)
|
2022-05-05 14:02:23 +08:00
|
|
|
|
CurrentDialog.Hide();
|
2017-02-28 12:59:36 +08:00
|
|
|
|
}
|
2019-09-12 06:35:47 +08:00
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2019-09-12 06:35:47 +08:00
|
|
|
|
{
|
2021-11-18 11:35:47 +08:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
switch (e.Action)
|
2019-09-12 06:35:47 +08:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Select:
|
2022-07-26 16:46:23 +08:00
|
|
|
|
var clickableButton =
|
|
|
|
|
CurrentDialog?.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault() ??
|
|
|
|
|
CurrentDialog?.Buttons.First();
|
|
|
|
|
|
|
|
|
|
clickableButton?.TriggerClick();
|
2019-09-12 06:35:47 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
return base.OnPressed(e);
|
2019-09-12 06:35:47 +08:00
|
|
|
|
}
|
2017-02-28 12:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
}
|