diff --git a/scenes/maps/testmap.tscn b/scenes/maps/testmap.tscn new file mode 100644 index 0000000..94448c1 --- /dev/null +++ b/scenes/maps/testmap.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://cbyee7drds7qu"] + +[node name="Testmap" type="Node3D"] diff --git a/scenes/ui/lobby.tscn b/scenes/ui/lobby.tscn index fa09c10..91aac64 100644 --- a/scenes/ui/lobby.tscn +++ b/scenes/ui/lobby.tscn @@ -18,3 +18,18 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 + +[node name="StartButton" type="Button" parent="."] +visible = false +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -96.0 +offset_top = -31.0 +grow_horizontal = 0 +grow_vertical = 0 +disabled = true +text = "Start Game" diff --git a/scripts/ui/lobby.gd b/scripts/ui/lobby.gd index a801d88..2eaa977 100644 --- a/scripts/ui/lobby.gd +++ b/scripts/ui/lobby.gd @@ -5,12 +5,23 @@ var label: PackedScene = preload("res://scenes/ui/elements/name_label.tscn") func _ready() -> void: if Networking.playerlist_changed.connect(_on_playerlist_changed) != OK: Log.error("FAILED to connect the playerlist_changed signal to _on_playerlist_changed!", "Internal Error: Failed to connect signal.") + var start_button: Button = $StartButton + if start_button.pressed.connect(_on_start_button_pressed) != OK: + Log.error("FAILED to connect the pressed signal to _on_start_button_pressed!", "Internal Error: Failed to connect signal.") _on_playerlist_changed() func _on_playerlist_changed() -> void: + if Networking.isManager: + var start_button: Button = $StartButton + start_button.show() + start_button.disabled = false for child: Label in $NameContainer.get_children(): child.free() for peer: String in Networking.peers: var instance: Label = label.instantiate() instance.text = peer $NameContainer.add_child(instance) + + +func _on_start_button_pressed() -> void: + Networking.send_rpcs("start_game", ["hello", " world"]) diff --git a/scripts/utils/networking.gd b/scripts/utils/networking.gd index 2eaceda..7fd3553 100644 --- a/scripts/utils/networking.gd +++ b/scripts/utils/networking.gd @@ -236,3 +236,19 @@ func send_playerlist(status: int, newPeers: Dictionary) -> void: Log.warning("Name %s is already taken in the room!" % Game.username) 3: Log.warning("Sent a playerlist request to a regular peer, not the host!") + +## General Game RPCs + +# Does RPCs to all clients. +func send_rpcs(method: String, args: Array) -> void: + for peer: String in peers: + var id: int = peers[peer] + if rpc_id(id, method, args) != OK: + Log.warning("Failed to send the rpc %s to %d." % [method, id]) + +# Starts the game. +@rpc("any_peer", "call_remote", "reliable") +func start_game() -> void: + if multiplayer.get_remote_sender_id() == managerID: + if !get_tree().change_scene_to_file("res://scenes/maps/testmap.tscn"): + Log.warning("Couldn't load the map!")