2019-03-18 10:48:11 +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.
|
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2019-03-18 10:48:11 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Allocation;
|
2020-08-06 13:43:39 +08:00
|
|
|
|
using osu.Framework.Audio;
|
2020-06-22 20:02:21 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2023-01-09 06:08:36 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2023-05-27 18:29:14 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2020-06-25 19:26:42 +08:00
|
|
|
|
using osu.Game.Audio;
|
2019-03-18 10:48:11 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2023-01-09 06:08:36 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2023-05-27 18:29:14 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2020-06-25 19:26:42 +08:00
|
|
|
|
using osu.Game.Skinning;
|
2019-03-18 10:48:11 +08:00
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class PauseOverlay : GameplayMenuOverlay
|
2019-03-18 10:48:11 +08:00
|
|
|
|
{
|
|
|
|
|
public Action OnResume;
|
|
|
|
|
|
2020-07-17 18:08:50 +08:00
|
|
|
|
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
|
|
|
|
|
|
2023-05-29 09:24:59 +08:00
|
|
|
|
public override LocalisableString Header => GameplayMenuOverlayStrings.PausedHeader;
|
2019-03-18 10:48:11 +08:00
|
|
|
|
|
2020-06-26 00:58:04 +08:00
|
|
|
|
private SkinnableSound pauseLoop;
|
2020-06-22 20:02:21 +08:00
|
|
|
|
|
2023-01-17 16:34:52 +08:00
|
|
|
|
protected override Action BackAction => () => InternalButtons.First().TriggerClick();
|
2019-03-18 10:48:11 +08:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-06-26 00:58:04 +08:00
|
|
|
|
private void load(OsuColour colours)
|
2019-03-18 10:48:11 +08:00
|
|
|
|
{
|
2023-05-27 18:29:14 +08:00
|
|
|
|
AddButton(GameplayMenuOverlayStrings.Continue, colours.Green, () => OnResume?.Invoke());
|
|
|
|
|
AddButton(GameplayMenuOverlayStrings.Retry, colours.YellowDark, () => OnRetry?.Invoke());
|
|
|
|
|
AddButton(GameplayMenuOverlayStrings.Quit, new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
|
2020-06-22 20:02:21 +08:00
|
|
|
|
|
2020-10-30 10:52:25 +08:00
|
|
|
|
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
|
2020-06-22 20:02:21 +08:00
|
|
|
|
{
|
2020-06-26 00:58:04 +08:00
|
|
|
|
Looping = true,
|
2020-08-06 18:16:26 +08:00
|
|
|
|
Volume = { Value = 0 }
|
2020-06-26 00:58:04 +08:00
|
|
|
|
});
|
2020-06-22 20:02:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-06 17:22:51 +08:00
|
|
|
|
public void StopAllSamples()
|
|
|
|
|
{
|
|
|
|
|
if (!IsLoaded)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pauseLoop.Stop();
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-22 20:02:21 +08:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
base.PopIn();
|
2020-06-26 00:58:04 +08:00
|
|
|
|
|
2020-07-17 18:08:50 +08:00
|
|
|
|
pauseLoop.VolumeTo(1.0f, TRANSITION_DURATION, Easing.InQuint);
|
2020-07-01 19:30:23 +08:00
|
|
|
|
pauseLoop.Play();
|
2020-06-22 20:02:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
base.PopOut();
|
2020-06-26 20:07:27 +08:00
|
|
|
|
|
2020-08-06 18:16:26 +08:00
|
|
|
|
pauseLoop.VolumeTo(0, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop());
|
2019-03-18 10:48:11 +08:00
|
|
|
|
}
|
2023-01-09 06:08:36 +08:00
|
|
|
|
|
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
|
|
|
|
{
|
|
|
|
|
switch (e.Action)
|
|
|
|
|
{
|
|
|
|
|
case GlobalAction.PauseGameplay:
|
2023-01-17 16:34:52 +08:00
|
|
|
|
InternalButtons.First().TriggerClick();
|
2023-01-09 06:08:36 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.OnPressed(e);
|
|
|
|
|
}
|
2019-03-18 10:48:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|