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

Using field properties to set mute / unmute instead of separate methods

This commit is contained in:
aQaTL 2018-01-20 11:45:04 +01:00
parent 4a85266fca
commit c4feb67bce
No known key found for this signature in database
GPG Key ID: 181719411A8555F0
2 changed files with 14 additions and 20 deletions

View File

@ -85,12 +85,8 @@ namespace osu.Game.Graphics.UserInterface.Volume
volumeMeterMaster.Increase(); volumeMeterMaster.Increase();
return true; return true;
case GlobalAction.ToggleMute: case GlobalAction.ToggleMute:
if (State == Visibility.Hidden) Show();
Show(); Muted = !Muted;
if (IsMuted)
Unmute();
else
Mute();
return true; return true;
} }
@ -107,16 +103,10 @@ namespace osu.Game.Graphics.UserInterface.Volume
private readonly BindableBool muted = new BindableBool(); private readonly BindableBool muted = new BindableBool();
public bool IsMuted => muted.Value; public bool Muted
public void Mute()
{ {
muted.Value = true; get => muted.Value;
} set => muted.Value = value;
public void Unmute()
{
muted.Value = false;
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -129,11 +119,15 @@ namespace osu.Game.Graphics.UserInterface.Volume
muted.ValueChanged += mute => muted.ValueChanged += mute =>
{ {
if (mute) if (mute)
{
audio.AddAdjustment(AdjustableProperty.Volume, muteBindable); audio.AddAdjustment(AdjustableProperty.Volume, muteBindable);
muteIcon.Icon = FontAwesome.fa_volume_off;
}
else else
{
audio.RemoveAdjustment(AdjustableProperty.Volume, muteBindable); audio.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
muteIcon.Icon = FontAwesome.fa_volume_up;
muteIcon.Icon = mute ? FontAwesome.fa_volume_off : FontAwesome.fa_volume_up; }
}; };
} }

View File

@ -396,8 +396,8 @@ namespace osu.Game
base.OnDeactivated(); base.OnDeactivated();
if (muteWhenInactive) if (muteWhenInactive)
{ {
wasMuted = volume.IsMuted; wasMuted = volume.Muted;
volume.Mute(); volume.Muted = true;
} }
} }
@ -405,7 +405,7 @@ namespace osu.Game
{ {
base.OnActivated(); base.OnActivated();
if (IsLoaded && muteWhenInactive && !wasMuted) if (IsLoaded && muteWhenInactive && !wasMuted)
volume.Unmute(); volume.Muted = false;
} }
public bool OnReleased(GlobalAction action) => false; public bool OnReleased(GlobalAction action) => false;