1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Add inactive volume ducking, rather than outright mute

This commit is contained in:
Dean Herbert 2018-01-31 16:57:26 +09:00
parent 97ae44f23c
commit 86f5c9d6f1
3 changed files with 9 additions and 13 deletions

View File

@ -39,7 +39,7 @@ namespace osu.Game.Configuration
};
// Audio
Set(OsuSetting.MuteWhenInactive, false);
Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
Set(OsuSetting.MenuVoice, true);
Set(OsuSetting.MenuMusic, true);
@ -103,7 +103,7 @@ namespace osu.Game.Configuration
MouseDisableButtons,
MouseDisableWheel,
AudioOffset,
MuteWhenInactive,
VolumeInactive,
MenuMusic,
MenuVoice,
CursorRotation,

View File

@ -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;
@ -122,7 +123,7 @@ namespace osu.Game
Ruleset.Value = RulesetStore.GetRuleset(configRuleset.Value) ?? RulesetStore.AvailableRulesets.First();
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;
muteWhenInactive = LocalConfig.GetBindable<bool>(OsuSetting.MuteWhenInactive);
LocalConfig.BindWith(OsuSetting.VolumeInactive, inactiveDuckVolume);
}
private ScheduledDelegate scoreLoad;
@ -400,24 +401,19 @@ namespace osu.Game
return false;
}
private Bindable<bool> muteWhenInactive = new Bindable<bool>();
private bool wasMuted;
private readonly BindableDouble inactiveDuckVolume = new BindableDouble();
protected override void OnDeactivated()
{
base.OnDeactivated();
if (muteWhenInactive)
{
wasMuted = volume.Muted;
volume.Muted = true;
}
Audio.AddAdjustment(AdjustableProperty.Volume, inactiveDuckVolume);
}
protected override void OnActivated()
{
base.OnActivated();
if (IsLoaded && muteWhenInactive && !wasMuted)
volume.Muted = false;
Audio.RemoveAdjustment(AdjustableProperty.Volume, inactiveDuckVolume);
}
public bool OnReleased(GlobalAction action) => false;

View File

@ -18,9 +18,9 @@ namespace osu.Game.Overlays.Settings.Sections.Audio
Children = new Drawable[]
{
new SettingsSlider<double> { LabelText = "Master", Bindable = audio.Volume, KeyboardStep = 0.1f },
new SettingsSlider<double> { LabelText = "Master (Window Inactive)", Bindable = config.GetBindable<double>(OsuSetting.VolumeInactive), 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) }
};
}
}