mirror of
https://github.com/ppy/osu.git
synced 2026-05-28 14:30:42 +08:00
Fade out pause loop sound when the game window is inactive
Closes https://github.com/ppy/osu/issues/32432.
This commit is contained in:
@@ -5,9 +5,12 @@ using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Localisation;
|
||||
@@ -31,14 +34,24 @@ namespace osu.Game.Screens.Play
|
||||
OnResume?.Invoke();
|
||||
};
|
||||
|
||||
private IBindable<bool>? windowActive;
|
||||
|
||||
private float targetVolume => windowActive?.Value != false && State.Value == Visibility.Visible ? 1.0f : 0;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
private void load(GameHost? host)
|
||||
{
|
||||
AddInternal(pauseLoop = new SkinnableSound(new SampleInfo("Gameplay/pause-loop"))
|
||||
{
|
||||
Looping = true,
|
||||
Volume = { Value = 0 }
|
||||
});
|
||||
|
||||
if (host != null)
|
||||
{
|
||||
windowActive = host.IsActive.GetBoundCopy();
|
||||
windowActive.BindValueChanged(_ => Schedule(() => pauseLoop.VolumeTo(targetVolume, 1000, Easing.Out)));
|
||||
}
|
||||
}
|
||||
|
||||
public void StopAllSamples()
|
||||
@@ -53,7 +66,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
base.PopIn();
|
||||
|
||||
pauseLoop.VolumeTo(1.0f, TRANSITION_DURATION, Easing.InQuint);
|
||||
pauseLoop.VolumeTo(targetVolume, TRANSITION_DURATION, Easing.InQuint);
|
||||
pauseLoop.Play();
|
||||
}
|
||||
|
||||
@@ -61,7 +74,7 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
base.PopOut();
|
||||
|
||||
pauseLoop.VolumeTo(0, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop());
|
||||
pauseLoop.VolumeTo(targetVolume, TRANSITION_DURATION, Easing.OutQuad).Finally(_ => pauseLoop.Stop());
|
||||
}
|
||||
|
||||
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
||||
|
||||
Reference in New Issue
Block a user