99# Source.Python
1010from listeners .tick import GameThread
1111from menus import PagedMenu , PagedOption , SimpleMenu , SimpleOption , Text
12+ from players .dictionary import PlayerDictionary
1213from players .helpers import get_client_language
1314from steam import SteamID
1415from translations .manager import language_manager
@@ -380,7 +381,7 @@ class LiftAnyBanPopupFeature(Feature):
380381
381382 def __init__ (self ):
382383 # (_BannedPlayerInfo instance, whether confirmed or not)
383- self ._selected_ban = ( None , False )
384+ self ._selected_bans = PlayerDictionary ( lambda index : ( None , False ) )
384385
385386 self .ban_popup = PagedMenu (title = self .popup_title )
386387 self .confirm_popup = SimpleMenu ()
@@ -402,41 +403,41 @@ def build_callback(popup, index):
402403
403404 @self .ban_popup .register_select_callback
404405 def select_callback (popup , index , option ):
405- self ._selected_ban = option .value
406+ self ._selected_bans [ index ] = option .value
406407 clients [index ].send_popup (self .confirm_popup )
407408
408409 @self .confirm_popup .register_build_callback
409410 def build_callback (popup , index ):
410411 popup .clear ()
411412
412413 popup .append (Text (plugin_strings ['ban_record' ].tokenized (
413- name = self ._selected_ban [0 ].name ,
414- id = self ._selected_ban [0 ].uniqueid
414+ name = self ._selected_bans [ index ] [0 ].name ,
415+ id = self ._selected_bans [ index ] [0 ].uniqueid
415416 )))
416417
417418 popup .append (Text (
418419 plugin_strings ['ban_record admin_steamid' ].tokenized (
419- admin_steamid = self ._selected_ban [0 ].banned_by )))
420+ admin_steamid = self ._selected_bans [ index ] [0 ].banned_by )))
420421
421422 popup .append (Text (plugin_strings ['ban_record reason' ].tokenized (
422- reason = self ._selected_ban [0 ].reason )))
423+ reason = self ._selected_bans [ index ] [0 ].reason )))
423424
424- if self ._selected_ban [0 ].notes :
425+ if self ._selected_bans [ index ] [0 ].notes :
425426 popup .append (Text (plugin_strings ['ban_record notes' ].tokenized (
426- notes = self ._selected_ban [0 ].notes )))
427+ notes = self ._selected_bans [ index ] [0 ].notes )))
427428
428429 popup .append (Text (
429430 plugin_strings ['lift_reviewed_ban_confirmation' ]))
430431
431432 popup .append (SimpleOption (
432433 choice_index = 1 ,
433434 text = plugin_strings ['lift_reviewed_ban_confirmation no' ],
434- value = (self ._selected_ban [0 ], False ),
435+ value = (self ._selected_bans [ index ] [0 ], False ),
435436 ))
436437 popup .append (SimpleOption (
437438 choice_index = 2 ,
438439 text = plugin_strings ['lift_reviewed_ban_confirmation yes' ],
439- value = (self ._selected_ban [0 ], True ),
440+ value = (self ._selected_bans [ index ] [0 ], True ),
440441 ))
441442
442443 @self .confirm_popup .register_select_callback
@@ -498,15 +499,13 @@ class ReviewBanPopupFeature(Feature):
498499
499500 def __init__ (self ):
500501 # (_BannedPlayerInfo instance, reason, duration)
501- self ._selected_ban = ( None , "" , - 1 )
502+ self ._selected_bans = PlayerDictionary ( lambda index : ( None , "" , - 1 ) )
502503
503504 self .ban_popup = PagedMenu (title = self .popup_title )
504505 self .reason_popup = PagedMenu (title = self .popup_title ,
505506 parent_menu = self .ban_popup )
506507
507- # We do not allow returning back to reason popup from duration popup,
508- # because we won't have valid self._selected_ban to build a reason
509- # popup with. Hence we don't provide parent_menu here.
508+ # TODO: Provide parent menu
510509 self .duration_popup = PagedMenu (title = self .popup_title )
511510
512511 @self .ban_popup .register_build_callback
@@ -527,7 +526,7 @@ def build_callback(popup, index):
527526
528527 @self .ban_popup .register_select_callback
529528 def select_callback (popup , index , option ):
530- self ._selected_ban = option .value
529+ self ._selected_bans [ index ] = option .value
531530 clients [index ].send_popup (self .reason_popup )
532531
533532 @self .reason_popup .register_build_callback
@@ -538,7 +537,7 @@ def build_callback(popup, index):
538537 popup .append (PagedOption (
539538 text = stock_ban_reason .translation ,
540539 value = (
541- self ._selected_ban [0 ],
540+ self ._selected_bans [ index ] [0 ],
542541 stock_ban_reason .translation .get_string (
543542 language_manager .default ),
544543 stock_ban_reason .duration ,
@@ -547,26 +546,27 @@ def build_callback(popup, index):
547546
548547 @self .reason_popup .register_select_callback
549548 def select_callback (popup , index , option ):
550- self ._selected_ban = option .value
549+ self ._selected_bans [ index ] = option .value
551550 clients [index ].send_popup (self .duration_popup )
552551
553552 @self .duration_popup .register_build_callback
554553 def build_callback (popup , index ):
555554 popup .clear ()
556555
557- if self ._selected_ban [2 ] is not None :
556+ if self ._selected_bans [ index ] [2 ] is not None :
558557 popup .append (PagedOption (
559558 text = plugin_strings ['default_duration' ].tokenized (
560- default = format_ban_duration (self ._selected_ban [2 ])),
561- value = self ._selected_ban
559+ default = format_ban_duration (
560+ self ._selected_bans [index ][2 ])),
561+ value = self ._selected_bans [index ]
562562 ))
563563
564564 for stock_ban_duration in stock_ban_durations :
565565 popup .append (PagedOption (
566566 text = format_ban_duration (stock_ban_duration ),
567567 value = (
568- self ._selected_ban [0 ],
569- self ._selected_ban [1 ],
568+ self ._selected_bans [ index ] [0 ],
569+ self ._selected_bans [ index ] [1 ],
570570 stock_ban_duration ,
571571 )
572572 ))
@@ -597,7 +597,7 @@ class SearchBadBansPopupFeature(Feature):
597597
598598 def __init__ (self ):
599599 # (_BannedPlayerInfo instance, whether to remove or not)
600- self ._selected_ban = None
600+ self ._selected_bans = PlayerDictionary ( lambda index : ( None , False ))
601601
602602 self .ban_popup = PagedMenu (title = self .popup_title )
603603 self .remove_popup = SimpleMenu ()
@@ -620,38 +620,38 @@ def build_callback(popup, index):
620620
621621 @self .ban_popup .register_select_callback
622622 def select_callback (popup , index , option ):
623- self ._selected_ban = option .value
623+ self ._selected_bans [ index ] = option .value
624624 clients [index ].send_popup (self .remove_popup )
625625
626626 @self .remove_popup .register_build_callback
627627 def build_callback (popup , index ):
628628 popup .clear ()
629629
630630 popup .append (Text (plugin_strings ['ban_record' ].tokenized (
631- name = self ._selected_ban [0 ].name ,
632- id = self ._selected_ban [0 ].uniqueid
631+ name = self ._selected_bans [ index ] [0 ].name ,
632+ id = self ._selected_bans [ index ] [0 ].uniqueid
633633 )))
634634
635635 popup .append (Text (
636636 plugin_strings ['ban_record admin_steamid' ].tokenized (
637- admin_steamid = self ._selected_ban [0 ].banned_by )))
637+ admin_steamid = self ._selected_bans [ index ] [0 ].banned_by )))
638638
639- if self ._selected_ban [0 ].notes :
639+ if self ._selected_bans [ index ] [0 ].notes :
640640 popup .append (Text (plugin_strings ['ban_record notes' ].tokenized (
641- notes = self ._selected_ban [0 ].notes )))
641+ notes = self ._selected_bans [ index ] [0 ].notes )))
642642
643643 popup .append (Text (
644644 plugin_strings ['remove_bad_ban_confirmation' ]))
645645
646646 popup .append (SimpleOption (
647647 choice_index = 1 ,
648648 text = plugin_strings ['remove_bad_ban_confirmation no' ],
649- value = (self ._selected_ban [0 ], False ),
649+ value = (self ._selected_bans [ index ] [0 ], False ),
650650 ))
651651 popup .append (SimpleOption (
652652 choice_index = 2 ,
653653 text = plugin_strings ['remove_bad_ban_confirmation yes' ],
654- value = (self ._selected_ban [0 ], True ),
654+ value = (self ._selected_bans [ index ] [0 ], True ),
655655 ))
656656
657657 @self .remove_popup .register_select_callback
0 commit comments