11from  __future__ import  annotations 
22import  time 
3+ import  sys 
34from  typing  import  Any 
45import  typing 
56from  worlds  import  AutoWorldRegister , network_data_package 
@@ -80,7 +81,8 @@ class ManualContext(SuperContext):
8081        'category_in_logic' : [2 / 255 , 82 / 255 , 2 / 255 , 1 ],
8182        'deathlink_received' : [1 , 0 , 0 , 1 ],
8283        'deathlink_primed' : [1 , 1 , 1 , 1 ],
83-         'deathlink_sent' : [0 , 1 , 0 , 1 ]
84+         'deathlink_sent' : [0 , 1 , 0 , 1 ],
85+         'game_select_button' : [200 / 255 , 200 / 255 , 200 / 255 , 1 ],
8486    }
8587
8688    def  __init__ (self , server_address , password , game , player_name ) ->  None :
@@ -211,21 +213,20 @@ def on_tracker_events(self, events: list[str]):
211213        if  events :
212214            self .ui .update_tracker_and_locations_table (update_highlights = True )
213215
214-     def  run_gui (self ):
215-         """Import kivy UI system and start running it as self.ui_task.""" 
216-         from  kvui  import  GameManager 
216+     def  make_gui (self ) ->  typing .Type ["kvui.GameManager" ]:
217+         ui  =  super ().make_gui ()  # before the kivy imports so kvui gets loaded first 
217218
218219        from  kivy .metrics  import  dp 
219220        from  kivy .uix .button  import  Button 
220-         from  kivy .uix .label  import  Label 
221-         from  kivy .uix .layout  import  Layout 
222221        from  kivy .uix .boxlayout  import  BoxLayout 
222+         from  kivy .uix .dropdown  import  DropDown 
223223        from  kivy .uix .gridlayout  import  GridLayout 
224+         from  kivy .uix .label  import  Label 
225+         from  kivy .uix .layout  import  Layout 
224226        from  kivy .uix .scrollview  import  ScrollView 
227+         from  kivy .uix .spinner  import  Spinner , SpinnerOption 
225228        from  kivy .uix .textinput  import  TextInput 
226-         from  kivy .uix .tabbedpanel  import  TabbedPanelItem 
227229        from  kivy .uix .treeview  import  TreeView , TreeViewNode , TreeViewLabel 
228-         from  kivy .clock  import  Clock 
229230        from  kivy .core .window  import  Window 
230231
231232        class  TrackerAndLocationsLayout (GridLayout ):
@@ -244,7 +245,14 @@ class TreeViewButton(Button, TreeViewNode):
244245        class  TreeViewScrollView (ScrollView , TreeViewNode ):
245246            pass 
246247
247-         class  ManualManager (GameManager ):
248+         class  GameSelectOption (SpinnerOption ):
249+             background_color  =  self .colors ['game_select_button' ]
250+ 
251+         class  GameSelectDropDown (DropDown ):
252+             # If someone can figure out how to give this a solid background, I'd be very happy. 
253+             pass 
254+ 
255+         class  ManualManager (ui ):
248256            logging_pairs  =  [
249257                ("Client" , "Archipelago" ),
250258                ("Manual" , "Manual" ),
@@ -269,9 +277,11 @@ def build(self) -> Layout:
269277                self .manual_game_layout  =  BoxLayout (orientation = "horizontal" , size_hint_y = None , height = dp (30 ))
270278
271279                game_bar_label  =  Label (text = "Manual Game ID" , size = (dp (150 ), dp (30 )), size_hint_y = None , size_hint_x = None )
280+                 manuals  =  [w  for  w  in  AutoWorldRegister .world_types .keys () if  "Manual_"  in  w ]
281+                 manuals .sort ()  # Sort by alphabetical order, not load order 
272282                self .manual_game_layout .add_widget (game_bar_label )
273-                 self .game_bar_text  =  TextInput (text = self .ctx .suggested_game ,
274-                                                  size_hint_y = None ,  height = dp ( 30 ),  multiline = False ,  write_tab = False )
283+                 self .game_bar_text  =  Spinner (text = self .ctx .suggested_game ,  size_hint_y = None ,  height = dp ( 30 ),  sync_height = True ,
284+                                              values = manuals ,  option_cls = GameSelectOption ,  dropdown_cls = GameSelectDropDown )
275285                self .manual_game_layout .add_widget (self .game_bar_text )
276286
277287                self .grid .add_widget (self .manual_game_layout , 3 )
@@ -284,9 +294,6 @@ def build(self) -> Layout:
284294
285295                self .build_tracker_and_locations_table ()
286296
287-                 if  tracker_loaded :
288-                     self .ctx .build_gui (self )
289- 
290297                return  self .container 
291298
292299            def  clear_lists (self ):
@@ -660,12 +667,7 @@ def victory_button_callback(self, button):
660667                self .ctx .items_received .append ("__Victory__" )
661668                self .ctx .syncing  =  True 
662669
663-         self .ui  =  ManualManager (self )
664- 
665-         if  tracker_loaded :
666-             self .load_kv ()
667- 
668-         self .ui_task  =  asyncio .create_task (self .ui .async_run (), name = "UI" )
670+         return  ManualManager 
669671
670672async  def  game_watcher_manual (ctx : ManualContext ):
671673    while  not  ctx .exit_event .is_set ():
@@ -736,7 +738,10 @@ def launch() -> None:
736738    parser .add_argument ('apmanual_file' , default = "" , type = str , nargs = "?" ,
737739                        help = 'Path to an APMANUAL file' )
738740
739-     args , rest  =  parser .parse_known_args ()
741+     args  =  sys .argv [1 :]
742+     if  "Manual Client"  in  args :
743+         args .remove ("Manual Client" )
744+     args , rest  =  parser .parse_known_args (args = args )
740745    colorama .init ()
741746    asyncio .run (main (args ))
742747    colorama .deinit ()
0 commit comments