mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 20:22:55 +08:00
Option in settings to toggle mute/unmute when losing/gaining window focus
This commit is contained in:
parent
9277586907
commit
0340e4f8dc
@ -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,
|
||||||
|
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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;
|
||||||
|
@ -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) }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user