From 7e9b5dd1506cf0f09cf4bd42a4c648dea244df20 Mon Sep 17 00:00:00 2001 From: Jamie Taylor Date: Fri, 14 Jan 2022 18:06:19 +0900 Subject: [PATCH 1/4] Add audio feedback for host change in multiplayer --- .../Screens/OnlinePlay/Match/RoomSubScreen.cs | 2 + .../Multiplayer/MultiplayerRoomSounds.cs | 66 +++++++++++++++++++ .../Participants/ParticipantsList.cs | 31 --------- 3 files changed, 68 insertions(+), 31 deletions(-) create mode 100644 osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index c31239616c..2d5225639f 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -21,6 +21,7 @@ using osu.Game.Overlays.Mods; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Screens.OnlinePlay.Match.Components; +using osu.Game.Screens.OnlinePlay.Multiplayer; namespace osu.Game.Screens.OnlinePlay.Match { @@ -101,6 +102,7 @@ namespace osu.Game.Screens.OnlinePlay.Match InternalChildren = new Drawable[] { beatmapAvailabilityTracker, + new MultiplayerRoomSounds(), new GridContainer { RelativeSizeAxes = Axes.Both, diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs new file mode 100644 index 0000000000..42e3716e5a --- /dev/null +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs @@ -0,0 +1,66 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; +using osu.Framework.Bindables; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Online.Multiplayer; + +namespace osu.Game.Screens.OnlinePlay.Multiplayer +{ + public class MultiplayerRoomSounds : MultiplayerRoomComposite + { + private Sample hostChangedSample; + private Sample userJoinedSample; + private Sample userLeftSample; + private Sample userKickedSample; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + hostChangedSample = audio.Samples.Get(@"Multiplayer/host-changed"); + userJoinedSample = audio.Samples.Get(@"Multiplayer/player-joined"); + userLeftSample = audio.Samples.Get(@"Multiplayer/player-left"); + userKickedSample = audio.Samples.Get(@"Multiplayer/player-kicked"); + + Host.ValueChanged += hostChanged; + } + + private void hostChanged(ValueChangedEvent value) + { + if (value.OldValue == null) return; + + hostChangedSample?.Play(); + } + + protected override void UserJoined(MultiplayerRoomUser user) + { + base.UserJoined(user); + + userJoinedSample?.Play(); + } + + protected override void UserLeft(MultiplayerRoomUser user) + { + base.UserLeft(user); + + userLeftSample?.Play(); + } + + protected override void UserKicked(MultiplayerRoomUser user) + { + base.UserKicked(user); + + userKickedSample?.Play(); + } + + protected override void Dispose(bool isDisposing) + { + base.Dispose(isDisposing); + + Host.ValueChanged -= hostChanged; + } + } +} diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantsList.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantsList.cs index d36c556fac..fe40a4bfe6 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantsList.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Participants/ParticipantsList.cs @@ -4,12 +4,10 @@ using System.Linq; using osu.Framework.Allocation; using osu.Framework.Audio; -using osu.Framework.Audio.Sample; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Cursor; -using osu.Game.Online.Multiplayer; using osuTK; namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants @@ -18,10 +16,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants { private FillFlowContainer panels; - private Sample userJoinSample; - private Sample userLeftSample; - private Sample userKickedSample; - [BackgroundDependencyLoader] private void load(AudioManager audio) { @@ -41,31 +35,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Participants } } }; - - userJoinSample = audio.Samples.Get(@"Multiplayer/player-joined"); - userLeftSample = audio.Samples.Get(@"Multiplayer/player-left"); - userKickedSample = audio.Samples.Get(@"Multiplayer/player-kicked"); - } - - protected override void UserJoined(MultiplayerRoomUser user) - { - base.UserJoined(user); - - userJoinSample?.Play(); - } - - protected override void UserLeft(MultiplayerRoomUser user) - { - base.UserLeft(user); - - userLeftSample?.Play(); - } - - protected override void UserKicked(MultiplayerRoomUser user) - { - base.UserKicked(user); - - userKickedSample?.Play(); } protected override void OnRoomUpdated() From c4976e9db83fccd34534515523a77eb9168f6fa1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 15 Jan 2022 20:08:08 +0900 Subject: [PATCH 2/4] Update resources --- osu.Android.props | 2 +- osu.Game/osu.Game.csproj | 2 +- osu.iOS.props | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Android.props b/osu.Android.props index 4198cf2bf4..b2e3b32916 100644 --- a/osu.Android.props +++ b/osu.Android.props @@ -51,7 +51,7 @@ - + diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 2609f17c73..2e5c9f4548 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -37,7 +37,7 @@ - + diff --git a/osu.iOS.props b/osu.iOS.props index 0064a597fd..897be33c18 100644 --- a/osu.iOS.props +++ b/osu.iOS.props @@ -61,7 +61,7 @@ - + From ea8e49c543ab5e516d2f41ff9de6185f7760c0f0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 15 Jan 2022 21:19:02 +0900 Subject: [PATCH 3/4] Reorder private/protected methods --- .../Multiplayer/MultiplayerRoomSounds.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs index 42e3716e5a..e673bbcc8c 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs @@ -28,13 +28,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer Host.ValueChanged += hostChanged; } - private void hostChanged(ValueChangedEvent value) - { - if (value.OldValue == null) return; - - hostChangedSample?.Play(); - } - protected override void UserJoined(MultiplayerRoomUser user) { base.UserJoined(user); @@ -56,6 +49,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer userKickedSample?.Play(); } + private void hostChanged(ValueChangedEvent value) + { + // only play sound when the host changes from an already-existing host. + if (value.OldValue == null) return; + + hostChangedSample?.Play(); + } + protected override void Dispose(bool isDisposing) { base.Dispose(isDisposing); From 671a3d47b8a131e97ebfd5800c3194667a0f956e Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 15 Jan 2022 21:20:27 +0900 Subject: [PATCH 4/4] Move bindable binding to `LoadComplete` and remove unnecessary unbind --- .../Multiplayer/MultiplayerRoomSounds.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs index e673bbcc8c..d467a32acb 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerRoomSounds.cs @@ -24,8 +24,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer userJoinedSample = audio.Samples.Get(@"Multiplayer/player-joined"); userLeftSample = audio.Samples.Get(@"Multiplayer/player-left"); userKickedSample = audio.Samples.Get(@"Multiplayer/player-kicked"); + } - Host.ValueChanged += hostChanged; + protected override void LoadComplete() + { + base.LoadComplete(); + + Host.BindValueChanged(hostChanged); } protected override void UserJoined(MultiplayerRoomUser user) @@ -56,12 +61,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer hostChangedSample?.Play(); } - - protected override void Dispose(bool isDisposing) - { - base.Dispose(isDisposing); - - Host.ValueChanged -= hostChanged; - } } }