diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs index 7abeed2cbf..a4856d1ee8 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneMultiSpectatorScreen.cs @@ -209,28 +209,28 @@ namespace osu.Game.Tests.Visual.Multiplayer start(new[] { PLAYER_1_ID, PLAYER_2_ID }); loadSpectateScreen(); - assertVolume(PLAYER_1_ID, 0); - assertVolume(PLAYER_2_ID, 0); + assertMuted(PLAYER_1_ID, true); + assertMuted(PLAYER_2_ID, true); sendFrames(PLAYER_1_ID, 10); sendFrames(PLAYER_2_ID, 20); - assertVolume(PLAYER_1_ID, 1); - assertVolume(PLAYER_2_ID, 0); + assertMuted(PLAYER_1_ID, false); + assertMuted(PLAYER_2_ID, true); checkPaused(PLAYER_1_ID, true); - assertVolume(PLAYER_1_ID, 0); - assertVolume(PLAYER_2_ID, 1); + assertMuted(PLAYER_1_ID, true); + assertMuted(PLAYER_2_ID, false); sendFrames(PLAYER_1_ID, 100); waitForCatchup(PLAYER_1_ID); checkPaused(PLAYER_2_ID, true); - assertVolume(PLAYER_1_ID, 1); - assertVolume(PLAYER_2_ID, 0); + assertMuted(PLAYER_1_ID, false); + assertMuted(PLAYER_2_ID, true); sendFrames(PLAYER_2_ID, 100); waitForCatchup(PLAYER_2_ID); - assertVolume(PLAYER_1_ID, 1); - assertVolume(PLAYER_2_ID, 0); + assertMuted(PLAYER_1_ID, false); + assertMuted(PLAYER_2_ID, true); } private void loadSpectateScreen(bool waitForPlayerLoad = true) @@ -292,8 +292,8 @@ namespace osu.Game.Tests.Visual.Multiplayer private void checkPausedInstant(int userId, bool state) => AddAssert($"{userId} is {(state ? "paused" : "playing")}", () => getPlayer(userId).ChildrenOfType().First().GameplayClock.IsRunning != state); - private void assertVolume(int userId, double volume) - => AddAssert($"{userId} volume is {volume}", () => getInstance(userId).Volume.Value == volume); + private void assertMuted(int userId, bool muted) + => AddAssert($"{userId} {(muted ? "is" : "is not")} muted", () => getInstance(userId).Mute == muted); private void waitForCatchup(int userId) => AddUntilStep($"{userId} not catching up", () => !getInstance(userId).GameplayClock.IsCatchingUp); diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorScreen.cs index 86c975d12f..2bd0ad8748 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/MultiSpectatorScreen.cs @@ -111,7 +111,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate .FirstOrDefault(); foreach (var instance in instances) - instance.Volume.Value = instance == currentAudioSource ? 1 : 0; + instance.Mute = instance != currentAudioSource; } } diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerArea.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerArea.cs index 3ef1693ca6..89c69cc666 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerArea.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Spectate/PlayerArea.cs @@ -23,7 +23,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate /// /// Provides an area for and manages the hierarchy of a spectated player within a . /// - public class PlayerArea : CompositeDrawable, IAdjustableAudioComponent + public class PlayerArea : CompositeDrawable { /// /// Whether a is loaded in the area. @@ -50,9 +50,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate [Resolved] private BeatmapManager beatmapManager { get; set; } + private readonly BindableDouble volumeAdjustment = new BindableDouble(); private readonly Container gameplayContent; private readonly LoadingLayer loadingLayer; - private readonly AudioContainer audioContainer; private OsuScreenStack stack; public PlayerArea(int userId, IFrameBasedClock masterClock) @@ -62,6 +62,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate RelativeSizeAxes = Axes.Both; Masking = true; + AudioContainer audioContainer; InternalChildren = new Drawable[] { audioContainer = new AudioContainer @@ -72,6 +73,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate loadingLayer = new LoadingLayer(true) { State = { Value = Visibility.Visible } } }; + audioContainer.AddAdjustment(AdjustableProperty.Volume, volumeAdjustment); + GameplayClock.Source = masterClock; } @@ -92,55 +95,22 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Spectate loadingLayer.Hide(); } + private bool mute = true; + + public bool Mute + { + get => mute; + set + { + mute = value; + volumeAdjustment.Value = value ? 0 : 1; + } + } + // Player interferes with global input, so disable input for now. public override bool PropagatePositionalInputSubTree => false; public override bool PropagateNonPositionalInputSubTree => false; - #region IAdjustableAudioComponent - - public IBindable AggregateVolume => audioContainer.AggregateVolume; - - public IBindable AggregateBalance => audioContainer.AggregateBalance; - - public IBindable AggregateFrequency => audioContainer.AggregateFrequency; - - public IBindable AggregateTempo => audioContainer.AggregateTempo; - - public void BindAdjustments(IAggregateAudioAdjustment component) - { - audioContainer.BindAdjustments(component); - } - - public void UnbindAdjustments(IAggregateAudioAdjustment component) - { - audioContainer.UnbindAdjustments(component); - } - - public void AddAdjustment(AdjustableProperty type, IBindable adjustBindable) - { - audioContainer.AddAdjustment(type, adjustBindable); - } - - public void RemoveAdjustment(AdjustableProperty type, IBindable adjustBindable) - { - audioContainer.RemoveAdjustment(type, adjustBindable); - } - - public void RemoveAllAdjustments(AdjustableProperty type) - { - audioContainer.RemoveAllAdjustments(type); - } - - public BindableNumber Volume => audioContainer.Volume; - - public BindableNumber Balance => audioContainer.Balance; - - public BindableNumber Frequency => audioContainer.Frequency; - - public BindableNumber Tempo => audioContainer.Tempo; - - #endregion - private class PlayerIsolationContainer : Container { [Cached]