@@ -145,7 +145,7 @@ private void KeyStateChange( IOnClientKeyStateChangedEvent @event )
145145 if ( menu . Configuration . PlaySound )
146146 {
147147 scrollSound . Recipients . AddRecipient ( @event . PlayerId ) ;
148- scrollSound . Emit ( ) ;
148+ _ = scrollSound . Emit ( ) ;
149149 scrollSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
150150 }
151151 }
@@ -156,18 +156,18 @@ private void KeyStateChange( IOnClientKeyStateChangedEvent @event )
156156 if ( menu . Configuration . PlaySound )
157157 {
158158 scrollSound . Recipients . AddRecipient ( @event . PlayerId ) ;
159- scrollSound . Emit ( ) ;
159+ _ = scrollSound . Emit ( ) ;
160160 scrollSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
161161 }
162162 }
163163 else if ( exitKey . HasFlag ( @event . Key . ToKeyBind ( ) ) )
164164 {
165- CloseMenuForPlayer ( player , menu ) ;
165+ CloseMenuForPlayerInternal ( player , menu , true ) ;
166166
167167 if ( menu . Configuration . PlaySound )
168168 {
169169 exitSound . Recipients . AddRecipient ( @event . PlayerId ) ;
170- exitSound . Emit ( ) ;
170+ _ = exitSound . Emit ( ) ;
171171 exitSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
172172 }
173173 }
@@ -181,7 +181,7 @@ private void KeyStateChange( IOnClientKeyStateChangedEvent @event )
181181 if ( menu . Configuration . PlaySound && option . PlaySound )
182182 {
183183 useSound . Recipients . AddRecipient ( @event . PlayerId ) ;
184- useSound . Emit ( ) ;
184+ _ = useSound . Emit ( ) ;
185185 useSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
186186 }
187187 }
@@ -196,7 +196,7 @@ private void KeyStateChange( IOnClientKeyStateChangedEvent @event )
196196 if ( menu . Configuration . PlaySound )
197197 {
198198 scrollSound . Recipients . AddRecipient ( @event . PlayerId ) ;
199- scrollSound . Emit ( ) ;
199+ _ = scrollSound . Emit ( ) ;
200200 scrollSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
201201 }
202202 }
@@ -207,17 +207,17 @@ private void KeyStateChange( IOnClientKeyStateChangedEvent @event )
207207 if ( menu . Configuration . PlaySound )
208208 {
209209 scrollSound . Recipients . AddRecipient ( @event . PlayerId ) ;
210- scrollSound . Emit ( ) ;
210+ _ = scrollSound . Emit ( ) ;
211211 scrollSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
212212 }
213213 }
214214 else if ( KeyBind . A . HasFlag ( @event . Key . ToKeyBind ( ) ) )
215215 {
216- CloseMenuForPlayer ( player , menu ) ;
216+ CloseMenuForPlayerInternal ( player , menu , true ) ;
217217 if ( menu . Configuration . PlaySound )
218218 {
219219 exitSound . Recipients . AddRecipient ( @event . PlayerId ) ;
220- exitSound . Emit ( ) ;
220+ _ = exitSound . Emit ( ) ;
221221 exitSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
222222 }
223223 }
@@ -231,7 +231,7 @@ private void KeyStateChange( IOnClientKeyStateChangedEvent @event )
231231 if ( menu . Configuration . PlaySound && option . PlaySound )
232232 {
233233 useSound . Recipients . AddRecipient ( @event . PlayerId ) ;
234- useSound . Emit ( ) ;
234+ _ = useSound . Emit ( ) ;
235235 useSound . Recipients . RemoveRecipient ( @event . PlayerId ) ;
236236 }
237237 }
@@ -247,7 +247,7 @@ private void OnClientDisconnected( IOnClientDisconnectedEvent @event )
247247 openMenus
248248 . Where ( kvp => kvp . Key == player )
249249 . ToList ( )
250- . ForEach ( kvp => CloseMenuForPlayer ( player , kvp . Value ) ) ;
250+ . ForEach ( kvp => CloseMenuForPlayerInternal ( player , kvp . Value , true ) ) ;
251251 }
252252 }
253253
@@ -322,7 +322,7 @@ public void OpenMenuForPlayer( IPlayer player, IMenuAPI menu )
322322 if ( menu . Parent . ParentMenu == currentMenu )
323323 {
324324 // We are transitioning from the current menu to one of its submenus.
325- // To show the submenu, we first need to close the current (parent) menu, see CloseMenuForPlayer .
325+ // To show the submenu, we first need to close the current (parent) menu.
326326 // The parent menu may have an onClosed callback registered in onClosedCallbacks.
327327 // If we do not remove that callback temporarily, closing the parent menu here
328328 // would incorrectly invoke the callback even though the user is only navigating
@@ -333,12 +333,12 @@ public void OpenMenuForPlayer( IPlayer player, IMenuAPI menu )
333333 // 3. Re-register the callback so it will only be invoked later, when the
334334 // logical end of the menu flow is reached and the menu is truly closed.
335335 _ = onClosedCallbacks . TryRemove ( ( player , currentMenu ) , out var callback ) ;
336- CloseMenuForPlayer ( player , currentMenu ) ;
336+ CloseMenuForPlayerInternal ( player , currentMenu , false ) ;
337337 _ = onClosedCallbacks . AddOrUpdate ( ( player , currentMenu ) , callback , ( _ , _ ) => callback ) ;
338338 }
339339 else
340340 {
341- CloseMenuForPlayer ( player , currentMenu ) ;
341+ CloseMenuForPlayerInternal ( player , currentMenu , false ) ;
342342 }
343343 }
344344
@@ -358,15 +358,36 @@ public void CloseMenu( IMenuAPI menu )
358358 Core . PlayerManager
359359 . GetAllPlayers ( )
360360 . ToList ( )
361- . ForEach ( player => CloseMenuForPlayer ( player , menu ) ) ;
361+ . ForEach ( player => CloseMenuForPlayerInternal ( player , menu , true ) ) ;
362362 }
363363
364364 public void CloseMenuForPlayer ( IPlayer player , IMenuAPI menu )
365+ {
366+ CloseMenuForPlayerInternal ( player , menu , true ) ;
367+ }
368+
369+ public void CloseAllMenus ( )
370+ {
371+ openMenus . ToList ( ) . ForEach ( kvp =>
372+ {
373+ var currentMenu = kvp . Value ;
374+ while ( currentMenu != null )
375+ {
376+ currentMenu . HideForPlayer ( kvp . Key ) ;
377+ MenuClosed ? . Invoke ( this , new MenuManagerEventArgs { Player = kvp . Key , Menu = currentMenu } ) ;
378+ currentMenu = currentMenu . Parent . ParentMenu ;
379+ }
380+ _ = openMenus . TryRemove ( kvp . Key , out _ ) ;
381+ } ) ;
382+ }
383+
384+ private void CloseMenuForPlayerInternal ( IPlayer player , IMenuAPI menu , bool reopenParent )
365385 {
366386 if ( ! openMenus . TryGetValue ( player , out var currentMenu ) || currentMenu != menu )
367387 {
368388 return ;
369389 }
390+
370391 if ( onClosedCallbacks . TryRemove ( ( player , menu ) , out var onClosed ) && onClosed != null )
371392 {
372393 onClosed ( player , menu ) ;
@@ -377,25 +398,10 @@ public void CloseMenuForPlayer( IPlayer player, IMenuAPI menu )
377398 menu . HideForPlayer ( player ) ;
378399 MenuClosed ? . Invoke ( this , new MenuManagerEventArgs { Player = player , Menu = menu } ) ;
379400
380- if ( menu . Parent . ParentMenu != null )
401+ if ( reopenParent && menu . Parent . ParentMenu != null )
381402 {
382403 OpenMenuForPlayer ( player , menu . Parent . ParentMenu ) ;
383404 }
384405 }
385406 }
386-
387- public void CloseAllMenus ( )
388- {
389- openMenus . ToList ( ) . ForEach ( kvp =>
390- {
391- var currentMenu = kvp . Value ;
392- while ( currentMenu != null )
393- {
394- currentMenu . HideForPlayer ( kvp . Key ) ;
395- MenuClosed ? . Invoke ( this , new MenuManagerEventArgs { Player = kvp . Key , Menu = currentMenu } ) ;
396- currentMenu = currentMenu . Parent . ParentMenu ;
397- }
398- _ = openMenus . TryRemove ( kvp . Key , out _ ) ;
399- } ) ;
400- }
401407}
0 commit comments