osu/osu.Game/Overlays/DialogOverlay.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

119 lines
3.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 09:19:50 +00: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;
using osu.Framework.Allocation;
using osu.Framework.Audio;
2021-09-16 09:26:12 +00:00
using osu.Framework.Input.Events;
using osu.Game.Audio.Effects;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Overlays
{
public class DialogOverlay : OsuFocusedOverlayContainer, IDialogOverlay
{
private readonly Container dialogContainer;
2019-09-19 11:17:58 +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;
2019-09-19 11:17:58 +00:00
public PopupDialog CurrentDialog { get; private set; }
2018-04-13 09:19:50 +00:00
public DialogOverlay()
{
RelativeSizeAxes = Axes.Both;
Child = dialogContainer = new Container
{
RelativeSizeAxes = Axes.Both,
};
Width = 0.4f;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
}
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
2021-10-07 09:49:30 +00:00
AddInternal(lowPassFilter = new AudioFilter(audio.TrackMixer));
}
public void Push(PopupDialog dialog)
{
if (dialog == CurrentDialog || dialog.State.Value != Visibility.Visible) return;
2018-04-13 09:19:50 +00:00
// if any existing dialog is being displayed, dismiss it before showing a new one.
2019-09-19 11:17:58 +00:00
CurrentDialog?.Hide();
2019-09-19 11:17:58 +00:00
CurrentDialog = dialog;
CurrentDialog.State.ValueChanged += state => onDialogOnStateChanged(dialog, state.NewValue);
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
Show();
}
2018-04-13 09:19:50 +00:00
public override bool IsPresent => dialogContainer.Children.Count > 0;
protected override bool BlockNonPositionalInput => true;
private void onDialogOnStateChanged(VisibilityContainer dialog, Visibility v)
{
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.
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)
{
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();
2017-07-22 18:50:25 +00:00
this.FadeIn(PopupDialog.ENTER_DURATION, Easing.OutQuint);
2021-10-07 09:49:30 +00:00
lowPassFilter.CutoffTo(300, 100, Easing.OutCubic);
}
2018-04-13 09:19:50 +00:00
protected override void PopOut()
{
base.PopOut();
2018-04-13 09:19:50 +00:00
2021-10-07 09:49:30 +00:00
lowPassFilter.CutoffTo(AudioFilter.MAX_LOWPASS_CUTOFF, 100, Easing.InCubic);
2021-10-06 02:50:14 +00:00
2019-09-19 11:17:58 +00:00
if (CurrentDialog?.State.Value == Visibility.Visible)
{
2019-09-19 11:17:58 +00:00
CurrentDialog.Hide();
return;
}
this.FadeOut(PopupDialog.EXIT_DURATION, Easing.InSine);
}
2021-09-16 09:26:12 +00:00
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;
2021-09-16 09:26:12 +00:00
switch (e.Action)
{
case GlobalAction.Select:
2021-08-04 08:27:44 +00:00
CurrentDialog?.Buttons.OfType<PopupDialogOkButton>().FirstOrDefault()?.TriggerClick();
return true;
}
2021-09-16 09:26:12 +00:00
return base.OnPressed(e);
}
}
}