class_name Lobby extends LobbyBase func _ready() -> void: setup_signals() func _exit_tree() -> void: # TODO: Maybe no longer needed... if Globals.multiplayer_data.is_multiplayer_active: return client._do_wait_close_connection() func setup_signals() -> void: MessageBus.subscribe("lobby_wait_for_connection", client._do_wait_for_connection) MessageBus.subscribe("lobby_close_connection", client._do_wait_close_connection) MessageBus.subscribe("receive_match_list", _on_receive_match_list) MessageBus.subscribe("match_list_activate_entry", _on_match_list_entry_activated) MessageBus.subscribe("match_list_add_entry", _on_match_list_entry_added) MessageBus.subscribe("match_list_remove_entry", _on_match_list_entry_removed) MessageBus.subscribe("match_list_entry_load_match", _on_match_list_entry_load_match) func _server_host_started() -> void: host_connect_bttn.visible = false # NOTE: 'matches_list' can be empty; so long as we get the call from the # server we know we are connected and thus hide respective UI elements. func _on_receive_match_list(matches_list: Array) -> void: push_warning("Client Joined Host: Full Match List Recieved...\n", matches_list) match_create_vbox.visible = true search_vbox.visible = true host_disconnect_bttn.visible = true host_connect_bttn.visible = false for match_entry in matches_list: _create_match_entry(match_entry) client.lobby_fully_connected = true func _on_match_list_entry_activated(match_id: String) -> void: for match_entry in match_list.get_children(): match_entry.join_bttn.visible = false if not match_entry.match_id == match_id: continue active_match = match_entry match_entry.join_bttn.text = "Delete" match_entry.join_bttn.visible = true match_create_vbox.visible = false match_entry.join_bttn.pressed.disconnect(_join_match) match_entry.join_bttn.pressed.connect( _delete_match.bind(match_entry.match_id) ) func _on_match_list_entry_added(match_entry: Dictionary) -> void: push_warning("Client: Added Match List Entry...", match_entry) _create_match_entry(match_entry) func _on_match_list_entry_removed(match_id: String) -> void: push_warning("Client: Removed Match List Entry...", match_id) if active_match && (match_id == active_match.match_id): active_match = null match_create_vbox.visible = true for match_entry in match_list.get_children(): if not active_match: match_entry.join_bttn.visible = true if not match_id == match_entry.match_id: continue match_entry.queue_free() func _on_match_list_entry_load_match(match_entry: Dictionary, is_player_1: bool) -> void: push_warning( "Client: Loading Game Match...\nMatch Data: ", match_entry, "\nis_player_1: ", is_player_1 ) Globals.multiplayer_data.set_multiplayer_active() Globals.game_data.set_game_mode(match_entry.type) Globals.game_data.set_player_id(is_player_1) Globals.game_state.set_game_scene("res://scenes/game.tscn") func _create_match_entry(match_entry: Dictionary) -> void: var container = MATCH_ENTRY.instantiate() match_list.add_child(container) container.name_lbl.text = match_entry.name container.type_lbl.text = match_entry.type container.match_id = match_entry.match_id container.join_bttn.pressed.connect( _join_match.bind(match_entry.match_id) ) if active_match: container.join_bttn.visible = false func _join_match(match_id: String) -> void: MessageBus.emit_request.rpc_id(1, "match_list_join_entry", match_id) func _delete_match(match_id: String) -> void: MessageBus.emit_request.rpc_id(1, "match_list_remove_entry", match_id)