1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 08:22:56 +08:00

Option in settings to toggle mute/unmute when losing/gaining window focus

This commit is contained in:
aQaTL 2018-01-16 20:33:30 +01:00
parent 9277586907
commit 0340e4f8dc
No known key found for this signature in database
GPG Key ID: 181719411A8555F0
4 changed files with 48 additions and 1 deletions
osu.Game
Configuration
Graphics/UserInterface/Volume
OsuGame.cs
Overlays/Settings/Sections/Audio

View File

@ -39,6 +39,8 @@ namespace osu.Game.Configuration
}; };
// Audio // Audio
Set(OsuSetting.MuteWhenInactive, false);
Set(OsuSetting.MenuVoice, true); Set(OsuSetting.MenuVoice, true);
Set(OsuSetting.MenuMusic, true); Set(OsuSetting.MenuMusic, true);
@ -101,6 +103,7 @@ namespace osu.Game.Configuration
MouseDisableButtons, MouseDisableButtons,
MouseDisableWheel, MouseDisableWheel,
AudioOffset, AudioOffset,
MuteWhenInactive,
MenuMusic, MenuMusic,
MenuVoice, MenuVoice,
CursorRotation, CursorRotation,

View File

@ -91,6 +91,24 @@ namespace osu.Game.Graphics.UserInterface.Volume
schedulePopOut(); schedulePopOut();
} }
public bool IsMuted => volumeMeterMaster.IsMuted;
public void Mute()
{
if (!IsMuted)
{
volumeMeterMaster.ToogleMute();
}
}
public void Unmute()
{
if (IsMuted)
{
volumeMeterMaster.ToogleMute();
}
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio)
{ {

View File

@ -115,6 +115,8 @@ namespace osu.Game
configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset); configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset);
Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First(); Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0; Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
muteWhenInactive = LocalConfig.GetBindable<bool>(OsuSetting.MuteWhenInactive);
} }
private ScheduledDelegate scoreLoad; private ScheduledDelegate scoreLoad;
@ -386,6 +388,28 @@ namespace osu.Game
return false; return false;
} }
private Bindable<bool> muteWhenInactive = new Bindable<bool>();
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; public bool OnReleased(GlobalAction action) => false;
private Container mainContent; private Container mainContent;

View File

@ -4,6 +4,7 @@
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Configuration;
namespace osu.Game.Overlays.Settings.Sections.Audio namespace osu.Game.Overlays.Settings.Sections.Audio
{ {
@ -12,13 +13,14 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
protected override string Header => "Volume"; protected override string Header => "Volume";
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio, OsuConfigManager config)
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
new SettingsSlider<double> { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.1f }, new SettingsSlider<double> { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.1f },
new SettingsSlider<double> { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.1f }, new SettingsSlider<double> { LabelText = "Effect", Bindable = audio.VolumeSample, KeyboardStep = 0.1f },
new SettingsSlider<double> { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.1f }, new SettingsSlider<double> { LabelText = "Music", Bindable = audio.VolumeTrack, KeyboardStep = 0.1f },
new SettingsCheckbox { LabelText = "Mute osu! when inactive", Bindable = config.GetBindable<bool>(OsuSetting.MuteWhenInactive) }
}; };
} }
} }