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 04:59:36 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Overlays.Dialog;
|
2017-06-28 17:18:12 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-09-11 22:35:47 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
|
|
|
|
using System.Linq;
|
2021-09-23 11:14:32 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-09-23 11:14:32 +00:00
|
|
|
|
using osu.Game.Audio.Effects;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-28 04:59:36 +00:00
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
2022-04-18 09:09:14 +00:00
|
|
|
|
public class DialogOverlay : OsuFocusedOverlayContainer, IDialogOverlay
|
2017-02-28 04:59:36 +00:00
|
|
|
|
{
|
2017-03-23 04:41:50 +00:00
|
|
|
|
private readonly Container dialogContainer;
|
2019-09-19 11:17:58 +00:00
|
|
|
|
|
2021-01-15 05:57:46 +00:00
|
|
|
|
protected override string PopInSampleName => "UI/dialog-pop-in";
|
|
|
|
|
protected override string PopOutSampleName => "UI/dialog-pop-out";
|
|
|
|
|
|
2021-10-07 09:49:30 +00:00
|
|
|
|
private AudioFilter lowPassFilter;
|
2021-09-23 11:14:32 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 11:14:32 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
2021-10-07 09:49:30 +00:00
|
|
|
|
AddInternal(lowPassFilter = new AudioFilter(audio.TrackMixer));
|
2021-09-23 11:14:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-02-28 04:59:36 +00:00
|
|
|
|
public void Push(PopupDialog dialog)
|
|
|
|
|
{
|
2021-05-19 07:52:34 +00:00
|
|
|
|
if (dialog == CurrentDialog || dialog.State.Value != Visibility.Visible) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-05-04 16:52:39 +00:00
|
|
|
|
var lastDialog = CurrentDialog;
|
2022-05-05 05:55:05 +00:00
|
|
|
|
|
|
|
|
|
// Immediately update the externally accessible property as this may be used for checks even before
|
|
|
|
|
// a DialogOverlay instance has finished loading.
|
2019-09-19 11:17:58 +00:00
|
|
|
|
CurrentDialog = dialog;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-05-04 16:52:39 +00:00
|
|
|
|
Scheduler.Add(() =>
|
|
|
|
|
{
|
|
|
|
|
// if any existing dialog is being displayed, dismiss it before showing a new one.
|
|
|
|
|
lastDialog?.Hide();
|
2022-05-05 05:55:05 +00:00
|
|
|
|
dialog.State.ValueChanged += state => onDialogOnStateChanged(dialog, state.NewValue);
|
|
|
|
|
dialogContainer.Add(dialog);
|
2022-05-04 16:52:39 +00:00
|
|
|
|
|
|
|
|
|
Show();
|
|
|
|
|
}, false);
|
2017-03-02 08:08:00 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-05-04 11:22:52 +00:00
|
|
|
|
public override bool IsPresent => Scheduler.HasPendingTasks || dialogContainer.Children.Count > 0;
|
2021-09-23 10:19:03 +00:00
|
|
|
|
|
2018-09-26 05:01:15 +00:00
|
|
|
|
protected override bool BlockNonPositionalInput => true;
|
2018-07-02 05:22:37 +00:00
|
|
|
|
|
2017-06-12 07:40:53 +00:00
|
|
|
|
private void onDialogOnStateChanged(VisibilityContainer dialog, Visibility v)
|
2017-03-02 08:08:00 +00:00
|
|
|
|
{
|
|
|
|
|
if (v != Visibility.Hidden) return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-05-05 01:31:11 +00:00
|
|
|
|
// handle the dialog being dismissed.
|
2017-07-17 13:51:21 +00:00
|
|
|
|
dialog.Delay(PopupDialog.EXIT_DURATION).Expire();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
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;
|
|
|
|
|
}
|
2017-02-28 04:59:36 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-28 04:59:36 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
2021-10-07 09:49:30 +00:00
|
|
|
|
lowPassFilter.CutoffTo(300, 100, Easing.OutCubic);
|
2017-02-28 04:59:36 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-02-28 04:59:36 +00:00
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
2022-05-04 11:22:52 +00:00
|
|
|
|
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 100, Easing.InCubic);
|
2018-07-02 05:22:37 +00:00
|
|
|
|
|
2022-05-05 06:02:23 +00:00
|
|
|
|
if (CurrentDialog?.State.Value == Visibility.Visible)
|
|
|
|
|
CurrentDialog.Hide();
|
2017-02-28 04:59:36 +00:00
|
|
|
|
}
|
2019-09-11 22:35:47 +00:00
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2019-09-11 22:35:47 +00:00
|
|
|
|
{
|
2021-11-18 03:35:47 +00:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
switch (e.Action)
|
2019-09-11 22:35:47 +00:00
|
|
|
|
{
|
|
|
|
|
case GlobalAction.Select:
|
2021-08-04 08:27:44 +00:00
|
|
|
|
CurrentDialog?.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.TriggerClick();
|
2019-09-11 22:35:47 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
return base.OnPressed(e);
|
2019-09-11 22:35:47 +00:00
|
|
|
|
}
|
2017-02-28 04:59:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|