55 lines
1.4 KiB
GDScript3
55 lines
1.4 KiB
GDScript3
|
|
extends VBoxContainer
|
||
|
|
|
||
|
|
@onready var lobby_label = $VBoxContainer/HBoxContainer/LobbyLabel
|
||
|
|
@onready var session_info = $VBoxContainer/SessionInfo
|
||
|
|
@onready var start_game_button = $VBoxContainer/StartGameButton
|
||
|
|
|
||
|
|
|
||
|
|
func start_hosting() -> void:
|
||
|
|
Networking.start_webrtc_lobby()
|
||
|
|
|
||
|
|
func stop_hosting() -> void:
|
||
|
|
Networking.stop_webrtc()
|
||
|
|
|
||
|
|
lobby_label.text = ""
|
||
|
|
session_info.text = ""
|
||
|
|
|
||
|
|
func show_panel() -> void:
|
||
|
|
lobby_label.text = ""
|
||
|
|
start_hosting()
|
||
|
|
visible = true
|
||
|
|
|
||
|
|
func hide_panel() -> void:
|
||
|
|
stop_hosting()
|
||
|
|
start_game_button.disabled = true
|
||
|
|
visible = false
|
||
|
|
|
||
|
|
# Called when the node enters the scene tree for the first time.
|
||
|
|
func _ready():
|
||
|
|
Networking.ws_client.lobby_joined.connect(_on_lobby_joined)
|
||
|
|
lobby_label.text = ""
|
||
|
|
multiplayer.peer_connected.connect(_on_peer_connected)
|
||
|
|
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
|
||
|
|
|
||
|
|
func _on_peer_connected(id: int) -> void:
|
||
|
|
GameData.peer_id = id
|
||
|
|
session_info.text = "Opponent connected"
|
||
|
|
start_game_button.disabled = false
|
||
|
|
|
||
|
|
func _on_peer_disconnected(id: int) -> void:
|
||
|
|
GameData.peer_id = 1
|
||
|
|
session_info.text = "Opponent disconnected"
|
||
|
|
start_game_button.disabled = true
|
||
|
|
|
||
|
|
func _on_lobby_joined(lobby_id: String) -> void:
|
||
|
|
lobby_label.text = lobby_id
|
||
|
|
session_info.text = "Waiting for opponent..."
|
||
|
|
|
||
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||
|
|
func _process(delta):
|
||
|
|
pass
|
||
|
|
|
||
|
|
|
||
|
|
func _on_back_button_pressed():
|
||
|
|
pass # Replace with function body.
|