1
1
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2
2
// See the LICENCE file in the repository root for full licence text.
3
3
4
- using System . Collections . Generic ;
5
4
using osu . Framework . Allocation ;
6
5
using osu . Framework . Audio ;
7
6
using osu . Framework . Audio . Sample ;
@@ -20,7 +19,6 @@ public partial class MultiplayerRoomSounds : CompositeDrawable
20
19
private Sample ? userJoinedSample ;
21
20
private Sample ? userLeftSample ;
22
21
private Sample ? userKickedSample ;
23
- private MultiplayerRoomUser ? host ;
24
22
25
23
[ BackgroundDependencyLoader ]
26
24
private void load ( AudioManager audio )
@@ -35,25 +33,10 @@ protected override void LoadComplete()
35
33
{
36
34
base . LoadComplete ( ) ;
37
35
38
- client . RoomUpdated += onRoomUpdated ;
39
36
client . UserJoined += onUserJoined ;
40
37
client . UserLeft += onUserLeft ;
41
38
client . UserKicked += onUserKicked ;
42
- updateState ( ) ;
43
- }
44
-
45
- private void onRoomUpdated ( ) => Scheduler . AddOnce ( updateState ) ;
46
-
47
- private void updateState ( )
48
- {
49
- if ( EqualityComparer < MultiplayerRoomUser > . Default . Equals ( host , client . Room ? . Host ) )
50
- return ;
51
-
52
- // only play sound when the host changes from an already-existing host.
53
- if ( host != null )
54
- Scheduler . AddOnce ( ( ) => hostChangedSample ? . Play ( ) ) ;
55
-
56
- host = client . Room ? . Host ;
39
+ client . HostChanged += onHostChanged ;
57
40
}
58
41
59
42
private void onUserJoined ( MultiplayerRoomUser user )
@@ -65,16 +48,22 @@ private void onUserLeft(MultiplayerRoomUser user)
65
48
private void onUserKicked ( MultiplayerRoomUser user )
66
49
=> Scheduler . AddOnce ( ( ) => userKickedSample ? . Play ( ) ) ;
67
50
51
+ private void onHostChanged ( MultiplayerRoomUser ? host )
52
+ {
53
+ if ( host != null )
54
+ Scheduler . AddOnce ( ( ) => hostChangedSample ? . Play ( ) ) ;
55
+ }
56
+
68
57
protected override void Dispose ( bool isDisposing )
69
58
{
70
59
base . Dispose ( isDisposing ) ;
71
60
72
61
if ( client . IsNotNull ( ) )
73
62
{
74
- client . RoomUpdated -= onRoomUpdated ;
75
63
client . UserJoined -= onUserJoined ;
76
64
client . UserLeft -= onUserLeft ;
77
65
client . UserKicked -= onUserKicked ;
66
+ client . HostChanged -= onHostChanged ;
78
67
}
79
68
}
80
69
}
0 commit comments