1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 20:22:55 +08:00

Merge pull request #15999 from peppy/restore-user-volume-muted-notification

Fix the unmute notification potentially overwriting user's volume levels unnecessarily
This commit is contained in:
Dan Balasescu 2021-12-10 02:58:59 +09:00 committed by GitHub
commit 35a208a478
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 5 deletions

View File

@ -251,7 +251,12 @@ namespace osu.Game.Tests.Visual.Gameplay
[Test] [Test]
public void TestMutedNotificationMuteButton() public void TestMutedNotificationMuteButton()
{ {
addVolumeSteps("mute button", () => volumeOverlay.IsMuted.Value = true, () => !volumeOverlay.IsMuted.Value); addVolumeSteps("mute button", () =>
{
// Importantly, in the case the volume is muted but the user has a volume level set, it should be retained.
audioManager.VolumeTrack.Value = 0.5f;
volumeOverlay.IsMuted.Value = true;
}, () => !volumeOverlay.IsMuted.Value && audioManager.VolumeTrack.Value == 0.5f);
} }
/// <remarks> /// <remarks>

View File

@ -468,12 +468,14 @@ namespace osu.Game.Screens.Play
private int restartCount; private int restartCount;
private const double volume_requirement = 0.05;
private void showMuteWarningIfNeeded() private void showMuteWarningIfNeeded()
{ {
if (!muteWarningShownOnce.Value) if (!muteWarningShownOnce.Value)
{ {
// Checks if the notification has not been shown yet and also if master volume is muted, track/music volume is muted or if the whole game is muted. // Checks if the notification has not been shown yet and also if master volume is muted, track/music volume is muted or if the whole game is muted.
if (volumeOverlay?.IsMuted.Value == true || audioManager.Volume.Value <= audioManager.Volume.MinValue || audioManager.VolumeTrack.Value <= audioManager.VolumeTrack.MinValue) if (volumeOverlay?.IsMuted.Value == true || audioManager.Volume.Value <= volume_requirement || audioManager.VolumeTrack.Value <= volume_requirement)
{ {
notificationOverlay?.Post(new MutedNotification()); notificationOverlay?.Post(new MutedNotification());
muteWarningShownOnce.Value = true; muteWarningShownOnce.Value = true;
@ -487,7 +489,7 @@ namespace osu.Game.Screens.Play
public MutedNotification() public MutedNotification()
{ {
Text = "Your music volume is set to 0%! Click here to restore it."; Text = "Your game volume is too low to hear anything! Click here to restore it.";
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -501,8 +503,12 @@ namespace osu.Game.Screens.Play
notificationOverlay.Hide(); notificationOverlay.Hide();
volumeOverlay.IsMuted.Value = false; volumeOverlay.IsMuted.Value = false;
audioManager.Volume.SetDefault();
audioManager.VolumeTrack.SetDefault(); // Check values before resetting, as the user may have only had mute enabled, in which case we might not need to adjust volumes.
if (audioManager.Volume.Value <= volume_requirement)
audioManager.Volume.SetDefault();
if (audioManager.VolumeTrack.Value <= volume_requirement)
audioManager.VolumeTrack.SetDefault();
return true; return true;
}; };