From 335f0d577c38803d1952168f9925c13cdf5395f4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 31 Jan 2018 18:11:38 +0900 Subject: [PATCH] Add the ability to duck volume when the game is inactive --- osu.Game/Configuration/OsuConfigManager.cs | 3 +++ osu.Game/OsuGame.cs | 18 ++++++++++++++++++ .../Settings/Sections/Audio/VolumeSettings.cs | 4 +++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 33810c9712..c33dd91330 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -39,6 +39,8 @@ namespace osu.Game.Configuration }; // Audio + Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01); + Set(OsuSetting.MenuVoice, true); Set(OsuSetting.MenuMusic, true); @@ -101,6 +103,7 @@ namespace osu.Game.Configuration MouseDisableButtons, MouseDisableWheel, AudioOffset, + VolumeInactive, MenuMusic, MenuVoice, CursorRotation, diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index bd71d37f97..fed3392460 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -19,6 +19,7 @@ using OpenTK; using System.Linq; using System.Threading; using System.Threading.Tasks; +using osu.Framework.Audio; using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Framework.Threading; @@ -121,6 +122,8 @@ namespace osu.Game configRuleset = LocalConfig.GetBindable(OsuSetting.Ruleset); Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First(); Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0; + + LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveVolumeAdjust); } private ScheduledDelegate scoreLoad; @@ -398,6 +401,21 @@ namespace osu.Game return false; } + private readonly BindableDouble inactiveVolumeAdjust = new BindableDouble(); + + protected override void OnDeactivated() + { + base.OnDeactivated(); + Audio.AddAdjustment(AdjustableProperty.Volume, inactiveVolumeAdjust); + } + + protected override void OnActivated() + { + base.OnActivated(); + Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveVolumeAdjust); + + } + public bool OnReleased(GlobalAction action) => false; private Container mainContent; diff --git a/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs b/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs index 40b9ff069b..92ee01dd7a 100644 --- a/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs +++ b/osu.Game/Overlays/Settings/Sections/Audio/VolumeSettings.cs @@ -4,6 +4,7 @@ using osu.Framework.Allocation; using osu.Framework.Audio; using osu.Framework.Graphics; +using osu.Game.Configuration; namespace osu.Game.Overlays.Settings.Sections.Audio { @@ -12,11 +13,12 @@ namespace osu.Game.Overlays.Settings.Sections.Audio protected override string Header => "Volume"; [BackgroundDependencyLoader] - private void load(AudioManager audio) + private void load(AudioManager audio, OsuConfigManager config) { Children = new Drawable[] { new SettingsSlider { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.1f }, + new SettingsSlider { LabelText = "Master (Window Inactive)", Bindable = config.GetBindable(OsuSetting.VolumeInactive), KeyboardStep = 0.1f }, new SettingsSlider { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.1f }, new SettingsSlider { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.1f }, };