mirror of
https://github.com/ppy/osu.git
synced 2026-06-04 02:13:39 +08:00
Merge pull request #32450 from peppy/no-pause-loop-when-inactive-window
Fade out pause loop sound when the game window is inactive
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,29 @@ namespace osu.Game.Screens.Play
|
||||
OnResume?.Invoke();
|
||||
};
|
||||
|
||||
private readonly IBindable<bool> windowActive = new Bindable<bool>(true);
|
||||
|
||||
private float targetVolume => windowActive.Value && 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.BindTo(host.IsActive);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
// Schedule required because host.IsActive doesn't seem to always run on the update thread.
|
||||
windowActive.BindValueChanged(_ => Schedule(() => pauseLoop.VolumeTo(targetVolume, 1000, Easing.Out)));
|
||||
}
|
||||
|
||||
public void StopAllSamples()
|
||||
@@ -53,7 +71,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 +79,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