From d7d6feb00182330a55bb77b6032703546e27b892 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Mon, 17 Jun 2019 12:31:23 +0200 Subject: [PATCH] Fade volume in / out when game window becomes active / inactive --- osu.Game/OsuGame.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index d5fbcdfee3..978d9cc20c 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -181,7 +181,7 @@ private void load(FrameworkConfigManager frameworkConfig) 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, inactiveVolume); IsActive.BindValueChanged(active => updateActiveState(active.NewValue), true); } @@ -686,14 +686,22 @@ public bool OnPressed(GlobalAction action) return false; } - private readonly BindableDouble inactiveVolumeAdjust = new BindableDouble(); + private readonly BindableDouble inactiveVolume = new BindableDouble(); + + private readonly BindableDouble inactiveVolAdjust = new BindableDouble(); private void updateActiveState(bool isActive) { if (isActive) - Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveVolumeAdjust); + { + this.TransformBindableTo(inactiveVolAdjust, 1, 750, Easing.In) + .Finally(_ => Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveVolAdjust)); //wait for the transition to finish to remove the inactive audio adjustement + } else - Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeAdjust); + { + Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolAdjust); + this.TransformBindableTo(inactiveVolAdjust, inactiveVolume.Value, 750, Easing.Out); + } } public bool OnReleased(GlobalAction action) => false;