extends VBoxContainer @onready var connect_button = $VBoxContainer/ConnectButton @onready var lobby_code = $VBoxContainer/HBoxContainer/LobbyCode @onready var session_info = $VBoxContainer/SessionInfo @onready var disconnect_button = $VBoxContainer/DisconnectButton func show_panel() -> void: session_info.text = "" visible = true pass func hide_panel() -> void: visible = false disconnect_from_host() pass func connect_to_host() -> void: session_info.text = "Connecting..." lobby_code.editable = false connect_button.disabled = true Networking.join_webrtc_lobby(lobby_code.text) func disconnect_from_host() -> void: session_info.text = "Disconnected" lobby_code.editable = true connect_button.disabled = false Networking.stop_webrtc() disconnect_button.disabled = true # Called when the node enters the scene tree for the first time. func _ready(): multiplayer.connected_to_server.connect(_on_connected_to_server) multiplayer.server_disconnected.connect(_on_server_disconnected) multiplayer.connection_failed.connect(_on_connection_failed) func _on_connection_failed() -> void: session_info.text = "Connection failed" connect_button.disabled = false lobby_code.editable = true disconnect_from_host() func _on_connected_to_server() -> void: session_info.text = "Connected. Waiting for host to start" disconnect_button.disabled = false func _on_server_disconnected() -> void: session_info.text = "Server closed the connection" lobby_code.editable = true connect_button.disabled = false disconnect_from_host() func _update_button_states() -> void: connect_button.disabled = lobby_code.text.is_empty() func _on_lobby_code_text_changed(new_text): _update_button_states() func _on_connect_button_pressed(): connect_to_host() func _on_disconnect_button_pressed(): disconnect_from_host()