Toggle mute/unmute keyboard shortcut

This commit is contained in:
aQaTL 2018-01-16 17:46:54 +01:00
parent 0ee9bcd70c
commit 9277586907
No known key found for this signature in database
GPG Key ID: 181719411A8555F0
3 changed files with 22 additions and 1 deletions

View File

@ -76,6 +76,10 @@ namespace osu.Game.Graphics.UserInterface.Volume
else
volumeMeterMaster.Increase();
return true;
case GlobalAction.ToggleMute:
Show();
volumeMeterMaster.ToogleMute();
return true;
}
return false;

View File

@ -18,6 +18,9 @@ namespace osu.Game.Graphics.UserInterface.Volume
private readonly Box meterFill;
public BindableDouble Bindable { get; } = new BindableDouble();
private double lastVolume;
public bool IsMuted { get; private set; }
public VolumeMeter(string meterName)
{
Size = new Vector2(40, 180);
@ -70,16 +73,19 @@ namespace osu.Game.Graphics.UserInterface.Volume
public double Volume
{
get { return Bindable.Value; }
get => Bindable.Value;
private set
{
Bindable.Value = value;
if (value > 0)
IsMuted = false;
}
}
public void Increase()
{
Volume += 0.05f;
IsMuted = false;
}
public void Decrease()
@ -87,6 +93,14 @@ namespace osu.Game.Graphics.UserInterface.Volume
Volume -= 0.05f;
}
public void ToogleMute()
{
IsMuted = !IsMuted;
if (IsMuted)
lastVolume = Volume;
Volume = IsMuted ? 0.0 : lastVolume;
}
private void updateFill() => meterFill.ScaleTo(new Vector2(1, (float)Volume), 300, Easing.OutQuint);
public bool OnPressed(GlobalAction action)

View File

@ -33,6 +33,7 @@ namespace osu.Game.Input.Bindings
new KeyBinding(new[] { InputKey.MouseWheelUp }, GlobalAction.IncreaseVolume),
new KeyBinding(new[] { InputKey.Down }, GlobalAction.DecreaseVolume),
new KeyBinding(new[] { InputKey.MouseWheelDown }, GlobalAction.DecreaseVolume),
new KeyBinding(InputKey.F4, GlobalAction.ToggleMute),
};
public IEnumerable<KeyBinding> InGameKeyBindings => new[]
@ -62,6 +63,8 @@ namespace osu.Game.Input.Bindings
IncreaseVolume,
[Description("Decrease Volume")]
DecreaseVolume,
[Description("Toggle mute")]
ToggleMute,
// In-Game Keybindings
[Description("Skip Cutscene")]