osu/osu.Game/Screens/Play/PauseOverlay.cs

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

80 lines
2.1 KiB
C#
Raw Normal View History

2019-03-18 02:48:11 +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.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
2020-06-22 12:02:21 +00:00
using osu.Framework.Graphics;
using osu.Framework.Input.Events;
2023-05-27 10:29:14 +00:00
using osu.Framework.Localisation;
2020-06-25 11:26:42 +00:00
using osu.Game.Audio;
using osu.Game.Input.Bindings;
2023-05-27 10:29:14 +00:00
using osu.Game.Localisation;
2020-06-25 11:26:42 +00:00
using osu.Game.Skinning;
2019-03-18 02:48:11 +00:00
namespace osu.Game.Screens.Play
{
public partial class PauseOverlay : GameplayMenuOverlay
{
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
2023-05-29 01:24:59 +00:00
public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
2019-03-18 02:48:11 +00:00
2024-02-28 07:24:04 +00:00
private SkinnableSound pauseLoop = null!;
2020-06-22 12:02:21 +00:00
protected override Action BackAction => () =>
{
if (Buttons.Any())
Buttons.First().TriggerClick();
else
OnResume?.Invoke();
};
2019-03-18 02:48:11 +00:00
[BackgroundDependencyLoader]
private void load()
2019-03-18 02:48:11 +00:00
{
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
2020-06-22 12:02:21 +00:00
{
Looping = true,
Volume = { Value = 0 }
});
2020-06-22 12:02:21 +00:00
}
public void StopAllSamples()
{
if (!IsLoaded)
return;
pauseLoop.Stop();
}
2020-06-22 12:02:21 +00:00
protected override void PopIn()
{
base.PopIn();
pauseLoop.VolumeTo(1.0f, TRANSITION_DURATION, Easing.InQuint);
2020-07-01 11:30:23 +00:00
pauseLoop.Play();
2020-06-22 12:02:21 +00:00
}
protected override void PopOut()
{
base.PopOut();
pauseLoop.VolumeTo(0, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop());
2019-03-18 02:48:11 +00:00
}
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
{
case GlobalAction.PauseGameplay:
InternalButtons.First().TriggerClick();
return true;
}
return base.OnPressed(e);
}
2019-03-18 02:48:11 +00:00
}
}