73 lines
2.4 KiB
GDScript
73 lines
2.4 KiB
GDScript
class_name ClientInterface
|
|
extends Control
|
|
|
|
@export var client: WebClient
|
|
|
|
@export var create_lobby_button: Button
|
|
@export var join_lobby_button: Button
|
|
@export var leave_lobby_button: Button
|
|
|
|
@export var connected_players_label: Label
|
|
|
|
@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()
|
|
|
|
func _on_web_client_tcp_connection_status_changed(new_status: WebClient.ConnectionStatus) -> void:
|
|
match new_status:
|
|
WebClient.ConnectionStatus.DISCONNECTED:
|
|
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 = ""
|
|
|
|
WebClient.ConnectionStatus.ATTEMPTING_CONNECTION:
|
|
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 = ""
|
|
|
|
WebClient.ConnectionStatus.LOBBYLESS:
|
|
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 = ""
|
|
|
|
WebClient.ConnectionStatus.ATTEMPTING_JOIN:
|
|
create_lobby_button.disabled = true
|
|
join_lobby_button.disabled = true
|
|
leave_lobby_button.disabled = true
|
|
name_input.editable = false
|
|
lobby_code_input.editable = false
|
|
|
|
WebClient.ConnectionStatus.JOINED:
|
|
create_lobby_button.disabled = true
|
|
join_lobby_button.disabled = true
|
|
leave_lobby_button.disabled = false
|
|
name_input.editable = false
|
|
lobby_code_input.editable = false
|
|
|
|
func _update_connected_players(new_client_names: Array[String]) -> void:
|
|
connected_players_label.text = "Connected Players:\n" + "\n".join(new_client_names)
|
|
|
|
func _on_web_client_connected_to_lobby(lobby_id: String, client_id: String) -> void:
|
|
lobby_code_input.text = lobby_id
|
|
|
|
func _on_web_client_connected_clients_changed(connected_client_names: Array[String]) -> void:
|
|
_update_connected_players(connected_client_names)
|