diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index 23f7fd6ac1..0c90b2c2ec 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -39,6 +39,8 @@ namespace osu.Game.Configuration }; // Audio + Set(OsuSetting.MuteWhenInactive, false); + Set(OsuSetting.MenuVoice, true); Set(OsuSetting.MenuMusic, true); @@ -101,6 +103,7 @@ namespace osu.Game.Configuration MouseDisableButtons, MouseDisableWheel, AudioOffset, + MuteWhenInactive, MenuMusic, MenuVoice, CursorRotation, diff --git a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs index 63b14713e2..7a1a2de50d 100644 --- a/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs +++ b/osu.Game/Graphics/UserInterface/Volume/VolumeControl.cs @@ -91,6 +91,24 @@ namespace osu.Game.Graphics.UserInterface.Volume schedulePopOut(); } + public bool IsMuted => volumeMeterMaster.IsMuted; + + public void Mute() + { + if (!IsMuted) + { + volumeMeterMaster.ToogleMute(); + } + } + + public void Unmute() + { + if (IsMuted) + { + volumeMeterMaster.ToogleMute(); + } + } + [BackgroundDependencyLoader] private void load(AudioManager audio) { diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 124b9364b3..56cfffdeae 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -115,6 +115,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; + + muteWhenInactive = LocalConfig.GetBindable(OsuSetting.MuteWhenInactive); } private ScheduledDelegate scoreLoad; @@ -386,6 +388,28 @@ namespace osu.Game return false; } + private Bindable muteWhenInactive = new Bindable(); + private bool wasMuted; + + protected override void OnDeactivated() + { + base.OnDeactivated(); + if (muteWhenInactive) + { + wasMuted = volume.IsMuted; + volume.Mute(); + } + } + + protected override void OnActivated() + { + base.OnActivated(); + if (IsLoaded && muteWhenInactive && !wasMuted) + { + volume.Unmute(); + } + } + 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..01bcf989dc 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,13 +13,14 @@ 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 = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.1f }, new SettingsSlider { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.1f }, + new SettingsCheckbox { LabelText = "Mute osu! when inactive", Bindable = config.GetBindable(OsuSetting.MuteWhenInactive) } }; } }