1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +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

View File

@ -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,

View File

@ -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)
{

View File

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

View File

@ -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<double> { LabelText = "Master", Bindable = audio.Volume, 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 SettingsCheckbox { LabelText = "Mute osu! when inactive", Bindable = config.GetBindable<bool>(OsuSetting.MuteWhenInactive) }
};
}
}