mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 16:27:26 +08:00
Fade volume when game window becomes inactive (#5047)
Fade volume when game window becomes inactive Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
0d4c6d2cbc
@ -181,7 +181,7 @@ namespace osu.Game
|
||||
configSkin.ValueChanged += skinId => SkinManager.CurrentSkinInfo.Value = SkinManager.Query(s => s.ID == skinId.NewValue) ?? SkinInfo.Default;
|
||||
configSkin.TriggerChange();
|
||||
|
||||
LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveVolumeAdjust);
|
||||
LocalConfig.BindWith(OsuSetting.VolumeInactive, userInactiveVolume);
|
||||
|
||||
IsActive.BindValueChanged(active => updateActiveState(active.NewValue), true);
|
||||
}
|
||||
@ -686,16 +686,28 @@ namespace osu.Game
|
||||
return false;
|
||||
}
|
||||
|
||||
private readonly BindableDouble inactiveVolumeAdjust = new BindableDouble();
|
||||
#region Inactive audio dimming
|
||||
|
||||
private readonly BindableDouble userInactiveVolume = new BindableDouble();
|
||||
|
||||
private readonly BindableDouble inactiveVolumeFade = new BindableDouble();
|
||||
|
||||
private void updateActiveState(bool isActive)
|
||||
{
|
||||
if (isActive)
|
||||
Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveVolumeAdjust);
|
||||
{
|
||||
this.TransformBindableTo(inactiveVolumeFade, 1, 500, Easing.OutQuint)
|
||||
.Finally(_ => Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveVolumeFade)); //wait for the transition to finish to remove the inactive audio adjustment
|
||||
}
|
||||
else
|
||||
Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeAdjust);
|
||||
{
|
||||
Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeFade);
|
||||
this.TransformBindableTo(inactiveVolumeFade, userInactiveVolume.Value, 1500, Easing.OutSine);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public bool OnReleased(GlobalAction action) => false;
|
||||
|
||||
private Container overlayContent;
|
||||
|
Loading…
Reference in New Issue
Block a user