mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 07:32:55 +08:00
Use AudioManager adjustments to mute volume
This commit is contained in:
parent
ac41cb59ea
commit
1440edbf8b
@ -7,12 +7,15 @@ using osu.Framework.Threading;
|
||||
using OpenTK;
|
||||
using osu.Framework.Audio;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Game.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Graphics.UserInterface.Volume
|
||||
{
|
||||
public class VolumeControl : OverlayContainer
|
||||
{
|
||||
private AudioManager audio;
|
||||
|
||||
private readonly VolumeMeter volumeMeterMaster;
|
||||
|
||||
protected override bool BlockPassThroughMouse => false;
|
||||
@ -77,8 +80,10 @@ namespace osu.Game.Graphics.UserInterface.Volume
|
||||
volumeMeterMaster.Increase();
|
||||
return true;
|
||||
case GlobalAction.ToggleMute:
|
||||
Show();
|
||||
volumeMeterMaster.ToggleMute();
|
||||
if (IsMuted)
|
||||
Unmute();
|
||||
else
|
||||
Mute();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -91,23 +96,32 @@ namespace osu.Game.Graphics.UserInterface.Volume
|
||||
schedulePopOut();
|
||||
}
|
||||
|
||||
public bool IsMuted => volumeMeterMaster.IsMuted;
|
||||
private readonly BindableDouble muteBindable = new BindableDouble();
|
||||
|
||||
public bool IsMuted { get; private set; }
|
||||
|
||||
public void Mute()
|
||||
{
|
||||
if (!IsMuted)
|
||||
volumeMeterMaster.ToggleMute();
|
||||
if (IsMuted)
|
||||
return;
|
||||
|
||||
audio.AddAdjustment(AdjustableProperty.Volume, muteBindable);
|
||||
IsMuted = true;
|
||||
}
|
||||
|
||||
public void Unmute()
|
||||
{
|
||||
if (IsMuted)
|
||||
volumeMeterMaster.ToggleMute();
|
||||
if (!IsMuted)
|
||||
return;
|
||||
|
||||
audio.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
|
||||
IsMuted = false;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(AudioManager audio)
|
||||
{
|
||||
this.audio = audio;
|
||||
volumeMeterMaster.Bindable.BindTo(audio.Volume);
|
||||
volumeMeterEffect.Bindable.BindTo(audio.VolumeSample);
|
||||
volumeMeterMusic.Bindable.BindTo(audio.VolumeTrack);
|
||||
|
@ -19,7 +19,6 @@ namespace osu.Game.Graphics.UserInterface.Volume
|
||||
public BindableDouble Bindable { get; } = new BindableDouble();
|
||||
|
||||
private double lastVolume;
|
||||
public bool IsMuted { get; private set; }
|
||||
|
||||
public VolumeMeter(string meterName)
|
||||
{
|
||||
@ -74,18 +73,12 @@ namespace osu.Game.Graphics.UserInterface.Volume
|
||||
public double Volume
|
||||
{
|
||||
get => Bindable.Value;
|
||||
private set
|
||||
{
|
||||
Bindable.Value = value;
|
||||
if (value > 0)
|
||||
IsMuted = false;
|
||||
}
|
||||
private set => Bindable.Value = value;
|
||||
}
|
||||
|
||||
public void Increase()
|
||||
{
|
||||
Volume += 0.05f;
|
||||
IsMuted = false;
|
||||
}
|
||||
|
||||
public void Decrease()
|
||||
@ -93,14 +86,6 @@ namespace osu.Game.Graphics.UserInterface.Volume
|
||||
Volume -= 0.05f;
|
||||
}
|
||||
|
||||
public void ToggleMute()
|
||||
{
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user