1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 19:27:24 +08:00
This commit is contained in:
Dean Herbert 2020-07-28 15:06:23 +09:00 committed by GitHub
commit d42a4e943a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 5 deletions

View File

@ -11,6 +11,7 @@ using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
using osuTK;
using osuTK.Input;
@ -221,6 +222,31 @@ namespace osu.Game.Tests.Visual.Gameplay
confirmExited();
}
[Test]
public void TestPauseSoundLoop()
{
AddStep("seek before gameplay", () => Player.GameplayClockContainer.Seek(-5000));
SkinnableSound getLoop() => Player.ChildrenOfType<PauseOverlay>().FirstOrDefault()?.ChildrenOfType<SkinnableSound>().FirstOrDefault();
pauseAndConfirm();
AddAssert("loop is playing", () => getLoop().IsPlaying);
resumeAndConfirm();
AddUntilStep("loop is stopped", () => !getLoop().IsPlaying);
AddUntilStep("pause again", () =>
{
Player.Pause();
return !Player.GameplayClockContainer.GameplayClock.IsRunning;
});
AddAssert("loop is playing", () => getLoop().IsPlaying);
resumeAndConfirm();
AddUntilStep("loop is stopped", () => !getLoop().IsPlaying);
}
private void pauseAndConfirm()
{
pause();

View File

@ -24,7 +24,8 @@ namespace osu.Game.Screens.Play
{
public abstract class GameplayMenuOverlay : OverlayContainer, IKeyBindingHandler<GlobalAction>
{
private const int transition_duration = 200;
protected const int TRANSITION_DURATION = 200;
private const int button_height = 70;
private const float background_alpha = 0.75f;
@ -156,8 +157,8 @@ namespace osu.Game.Screens.Play
}
}
protected override void PopIn() => this.FadeIn(transition_duration, Easing.In);
protected override void PopOut() => this.FadeOut(transition_duration, Easing.In);
protected override void PopIn() => this.FadeIn(TRANSITION_DURATION, Easing.In);
protected override void PopOut() => this.FadeOut(TRANSITION_DURATION, Easing.In);
// Don't let mouse down events through the overlay or people can click circles while paused.
protected override bool OnMouseDown(MouseDownEvent e) => true;

View File

@ -4,7 +4,10 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Skinning;
using osuTK.Graphics;
namespace osu.Game.Screens.Play
@ -13,17 +16,46 @@ namespace osu.Game.Screens.Play
{
public Action OnResume;
public override bool IsPresent => base.IsPresent || pauseLoop.IsPlaying;
public override string Header => "paused";
public override string Description => "you're not going to do what i think you're going to do, are ya?";
private SkinnableSound pauseLoop;
protected override Action BackAction => () => InternalButtons.Children.First().Click();
private const float minimum_volume = 0.0001f;
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AddButton("Continue", colours.Green, () => OnResume?.Invoke());
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("pause-loop"))
{
Looping = true,
});
// SkinnableSound only plays a sound if its aggregate volume is > 0, so the volume must be turned up before playing it
pauseLoop.VolumeTo(minimum_volume);
}
protected override void PopIn()
{
base.PopIn();
pauseLoop.VolumeTo(1.0f, TRANSITION_DURATION, Easing.InQuint);
pauseLoop.Play();
}
protected override void PopOut()
{
base.PopOut();
pauseLoop.VolumeTo(minimum_volume, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop());
}
}
}

View File

@ -48,6 +48,10 @@ namespace osu.Game.Skinning
public BindableNumber<double> Tempo => samplesContainer.Tempo;
public override bool IsPresent => Scheduler.HasPendingTasks || IsPlaying;
public bool IsPlaying => samplesContainer.Any(s => s.Playing);
/// <summary>
/// Smoothly adjusts <see cref="Volume"/> over time.
/// </summary>
@ -97,8 +101,6 @@ namespace osu.Game.Skinning
public void Stop() => samplesContainer.ForEach(c => c.Stop());
public override bool IsPresent => Scheduler.HasPendingTasks;
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
bool wasPlaying = samplesContainer.Any(s => s.Playing);