def handle_chat_events(self):
     
     if pygame.K_t in wotsuievents.keys_pressed:
         self.chatting = True
         
         if versusclient.local_player_is_in_match():
             players[versusclient.get_local_player_position()].handle_input_events = False
     
     if (pygame.K_RETURN in wotsuievents.keys_pressed or
     pygame.K_ESCAPE in wotsuievents.keys_pressed):
         self.chatting = False
         
         if versusclient.local_player_is_in_match():
             players[versusclient.get_local_player_position()].handle_input_events = True
 def build_player_command_types(self):
     keys_pressed = {
         PlayerPositions.PLAYER1 : InputCommandTypes(
             [],
             InputActionTypes.NO_MOVEMENT,
             [],
             [],
             []
         ),
         PlayerPositions.PLAYER2 : InputCommandTypes(
             [],
             InputActionTypes.NO_MOVEMENT,
             [],
             [],
             []
         )
     }
     
     if versusclient.local_player_is_in_match():
         player_position = versusclient.get_local_player_position()
         keys_pressed[player_position] = self.player_key_handlers[
             player_position
         ].get_command_data(wotsuievents.keys_pressed)
         
         if keys_pressed[player_position] == None:
             print(wotsuievents.keys_pressed)
     
     return keys_pressed
 def handle_simulation_messages(self, simulation_messages):
     
     for message in simulation_messages:
         action = message[SimulationDataKeys.ACTION]
         
         if action == SimulationActionTypes.STEP:
             self.update_simulation_rendering(
                 message[SimulationDataKeys.RENDERING_INFO]
             )
         else:
             if versusclient.local_player_is_in_match():
                 if gamestate.hosting:
                     if action == SimulationActionTypes.GET_STATE:
                         versusclient.listener.update_simulation_state(
                             message[SimulationDataKeys.SIMULATION_STATE]
                         )
                     
                 else:
                     if action == SimulationActionTypes.UPDATE_INPUT:
                         versusclient.listener.send_input_to_host(
                             message
                         )
             elif versusclient.dummies_only():
                 if gamestate.hosting:
                     if action == SimulationActionTypes.GET_STATE:
                         versusclient.listener.update_simulation_state(
                             message[SimulationDataKeys.SIMULATION_STATE]
                         )
             else:
                 pass #do nothing because this is a spectator
 def exit(self, quit=True):
     
     self.end_simulation()
     self.cleanup_rendering_objects()
     self.cleanup_match_state_variables()
     self.reset_GUI_variables()
     self.flush_recording()
     self.initialized = False
     self.exiting = True
     self.exit_indicator = True
     
     wotsrendering.flush()
     
     self.unregister_network_callbacks()
     
     if (versusclient.local_player_is_in_match() or 
     (versusclient.dummies_only() and gamestate.hosting)):
         versusclient.listener.end_match()
         
     else:
         if quit:
             #if you're a spectator go to the main menu
             versusclient.listener.close()
             versusclient.unload()
             gamestate.mode = gamestate.Modes.MAINMENU
     
     self.chatting = False
def load():
    global loading_match_label
    global load_match_progress_timer
    global player_data
    
    loading_match_label = button.Label((0, 0), LOADING_MATCH_TEXT, (255,255,255),40)
    loading_match_label.set_position(get_layout_label_pos())
    
    splash.draw_loading_splash()
    pygame.display.flip()
    
    load_match_progress_timer = 0
    
    versusmode_player_data = []
    
    #swap actual moveset with moveset name
    for player_data_object in player_data.values():
        versusmode_player_data.append(
            PlayerData(
                player_data_object.player_position,
                player_data_object.player_type,
                movesetdata.get_moveset(player_data_object.moveset),
                player_data_object.size,
                player_data_object.color,
                player_data_object.difficulty
            )
        )
    
    onlineversusmode.init(versusmode_player_data)
    
    if versusclient.local_player_is_in_match():
        
        versusclient.listener.send_all_movesets_loaded()
    
    elif versusclient.dummies_only():
        versusclient.listener.start_match()
def handle_events():
    global loaded
    global exit_button
    global start_match_label
    global player_status_ui_dictionary
    global join_match_button
    global local_player_container_created
    global local_player_position
    
    if loaded == False:
        load()
    
    if pygame.MOUSEBUTTONDOWN in wotsuievents.event_types:
        if exit_button.contains(wotsuievents.mouse_pos):
            exit_button.handle_selected()
        
        if start_match_label.active:
            if start_match_label.contains(wotsuievents.mouse_pos):
                start_match_label.handle_selected()
        
        if join_match_button.active:
            if join_match_button.contains(wotsuievents.mouse_pos):
                join_match_button.handle_selected()
        
        if spectate_button.active:
            if spectate_button.contains(wotsuievents.mouse_pos):
                spectate_button.handle_selected()
        
    if pygame.MOUSEBUTTONUP in wotsuievents.event_types:
        if exit_button.selected:
            exit_button.handle_deselected()
            
            if exit_button.contains(wotsuievents.mouse_pos):
                gamestate.mode = gamestate.Modes.ONLINEMENUPAGE
                unload()
        
        elif start_match_label.selected:
            if start_match_label.contains(wotsuievents.mouse_pos):
                start_match_label.handle_deselected()
                versusclient.listener.load_match_data()
        
        #TODO - inactivate join if selected and same for spectate
        elif join_match_button.selected:
            if join_match_button.contains(wotsuievents.mouse_pos):
                versusclient.listener.join_match()
                join_match_button.handle_deselected()
                join_match_button.inactivate()
                
                spectate_button.activate()
        
        elif spectate_button.selected:
            if spectate_button.contains(wotsuievents.mouse_pos):
                versusclient.listener.spectate_match()
                spectate_button.handle_deselected()
                spectate_button.inactivate()
                join_match_button.activate()
    
    if loaded:
        
        if versusclient.dummies_only() and start_match_label.active == False:
            start_match_label.activate()
            
        
        if local_player_container_created:
            players_ready = True
            
            local_player_position = versusclient.get_local_player_position()
            
            if player_status_ui_dictionary[local_player_position].player_ready() and \
            not versusclient.listener.player_positions_ready_dictionary[local_player_position]:
                
                versusclient.listener.player_ready()
            
            for player_status_ui in player_status_ui_dictionary.values():
                if hasattr(player_status_ui, "player_ready"):
                    players_ready = (getattr(player_status_ui, "player_ready")() and players_ready)
                else:
                    players_ready = False
            
            if players_ready:
                if start_match_label.active == False:
                    start_match_label.activate()
            else:
                if start_match_label.active:
                    start_match_label.inactivate()
        
        for player_status_ui in player_status_ui_dictionary.values():
            player_status_ui.handle_events()
            player_status_ui.draw(gamestate.screen)
        
        join_match_button.draw(gamestate.screen)
        exit_button.draw(gamestate.screen)
        start_match_label.draw(gamestate.screen)
        spectate_button.draw(gamestate.screen)
        
        #Network Dependent Event Handling
        if (versusclient.listener.connection_status == 
        versusclient.ConnectionStatus.DISCONNECTED):
            
            unload()
            gamestate.mode = gamestate.Modes.ONLINEMENUPAGE
        
        if versusclient.connected() or gamestate.hosting:
            if not versusclient.local_player_is_in_match():
                if not join_match_button.active:
                    join_match_button.activate()
                
                if spectate_button.active:
                    spectate_button.inactivate()
                
            else:
                
                if not spectate_button.active:
                    spectate_button.activate()
                
                if join_match_button.active:
                    join_match_button.inactivate()
            
            update_player_data()
            
            if (versusclient.listener.server_mode == 
            versusserver.ServerModes.LOADING_MATCH_DATA) or \
            (versusclient.listener.server_mode == versusserver.ServerModes.MATCH):
                gamestate.mode = gamestate.Modes.ONLINEMATCHLOADER
            
            versusclient.get_network_messages()
            versusclient.listener.Pump()