2025-06-28 15:19:04 +02:00
|
|
|
class_name ClientInterface
|
|
|
|
|
extends Control
|
2025-06-29 20:34:46 +02:00
|
|
|
|
2025-07-20 15:02:05 +02:00
|
|
|
@export var client: WebClient
|
2025-06-29 20:34:46 +02:00
|
|
|
|
|
|
|
|
@export var create_lobby_button: Button
|
|
|
|
|
@export var join_lobby_button: Button
|
|
|
|
|
@export var leave_lobby_button: Button
|
|
|
|
|
|
2025-07-07 22:11:02 +02:00
|
|
|
@export var connected_players_label: Label
|
|
|
|
|
|
2025-06-29 20:34:46 +02:00
|
|
|
@export var name_input: LineEdit
|
|
|
|
|
@export var lobby_code_input: LineEdit
|
|
|
|
|
|
|
|
|
|
func _on_create_lobby_button_pressed() -> void:
|
|
|
|
|
client.create_lobby(name_input.text.strip_edges())
|
|
|
|
|
|
|
|
|
|
func _on_join_lobby_button_pressed() -> void:
|
|
|
|
|
client.join_lobby(lobby_code_input.text.strip_edges(), name_input.text.strip_edges())
|
|
|
|
|
|
|
|
|
|
func _on_disconnect_lobby_button_pressed() -> void:
|
|
|
|
|
leave_lobby_button.disabled = true
|
|
|
|
|
client.leave_lobby()
|
|
|
|
|
|
2025-07-20 15:02:05 +02:00
|
|
|
func _on_web_client_tcp_connection_status_changed(new_status: WebClient.ConnectionStatus) -> void:
|
2025-07-02 21:58:19 +02:00
|
|
|
match new_status:
|
2025-07-20 15:02:05 +02:00
|
|
|
WebClient.ConnectionStatus.DISCONNECTED:
|
2025-07-02 21:58:19 +02:00
|
|
|
create_lobby_button.disabled = true
|
|
|
|
|
join_lobby_button.disabled = true
|
|
|
|
|
leave_lobby_button.disabled = true
|
|
|
|
|
name_input.editable = true
|
|
|
|
|
lobby_code_input.editable = false
|
|
|
|
|
lobby_code_input.text = ""
|
|
|
|
|
|
2025-07-20 15:02:05 +02:00
|
|
|
WebClient.ConnectionStatus.ATTEMPTING_CONNECTION:
|
2025-07-02 21:58:19 +02:00
|
|
|
create_lobby_button.disabled = true
|
|
|
|
|
join_lobby_button.disabled = true
|
|
|
|
|
leave_lobby_button.disabled = true
|
|
|
|
|
name_input.editable = true
|
|
|
|
|
lobby_code_input.editable = false
|
|
|
|
|
lobby_code_input.text = ""
|
|
|
|
|
|
2025-07-20 15:02:05 +02:00
|
|
|
WebClient.ConnectionStatus.LOBBYLESS:
|
2025-07-02 21:58:19 +02:00
|
|
|
create_lobby_button.disabled = false
|
|
|
|
|
join_lobby_button.disabled = false
|
|
|
|
|
leave_lobby_button.disabled = true
|
|
|
|
|
name_input.editable = true
|
|
|
|
|
lobby_code_input.editable = true
|
|
|
|
|
lobby_code_input.text = ""
|
|
|
|
|
|
2025-07-20 15:02:05 +02:00
|
|
|
WebClient.ConnectionStatus.ATTEMPTING_JOIN:
|
2025-07-02 21:58:19 +02:00
|
|
|
create_lobby_button.disabled = true
|
|
|
|
|
join_lobby_button.disabled = true
|
|
|
|
|
leave_lobby_button.disabled = true
|
|
|
|
|
name_input.editable = false
|
|
|
|
|
lobby_code_input.editable = false
|
|
|
|
|
|
2025-07-20 15:02:05 +02:00
|
|
|
WebClient.ConnectionStatus.JOINED:
|
2025-07-02 21:58:19 +02:00
|
|
|
create_lobby_button.disabled = true
|
|
|
|
|
join_lobby_button.disabled = true
|
|
|
|
|
leave_lobby_button.disabled = false
|
|
|
|
|
name_input.editable = false
|
|
|
|
|
lobby_code_input.editable = false
|
2025-07-07 10:57:39 +02:00
|
|
|
|
2025-07-20 19:26:50 +02:00
|
|
|
func _update_connected_players(connected_clients: Array[ClientData]) -> void:
|
|
|
|
|
connected_players_label.text = "Connected Players:"
|
|
|
|
|
for client in connected_clients:
|
|
|
|
|
connected_players_label.text += "\n" + client.client_name
|
2025-07-20 17:37:10 +02:00
|
|
|
|
|
|
|
|
func _on_web_client_connected_to_lobby(lobby_id: String, client_id: String) -> void:
|
|
|
|
|
lobby_code_input.text = lobby_id
|
|
|
|
|
|
2025-07-20 19:26:50 +02:00
|
|
|
func _on_web_client_connected_clients_changed(connected_clients: Array[ClientData]) -> void:
|
|
|
|
|
_update_connected_players(connected_clients)
|