summaryrefslogtreecommitdiff
path: root/UI/lobby.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-19 15:24:50 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-19 15:24:50 +0100
commit72863ffa31e27f4c6be862d80472cfb897fccaea (patch)
treece04be8d77b10c797c8ff854c8ff1a219eb1af46 /UI/lobby.gd
parent63d2a59042fb9d90a586ad85d8364de7c38aea8e (diff)
next commitHEADmain
Diffstat (limited to 'UI/lobby.gd')
-rw-r--r--UI/lobby.gd44
1 files changed, 42 insertions, 2 deletions
diff --git a/UI/lobby.gd b/UI/lobby.gd
index 26a7b97..f7d8405 100644
--- a/UI/lobby.gd
+++ b/UI/lobby.gd
@@ -5,6 +5,8 @@ signal joined
var current_map_idx := 0
+var settings := {}
+
@onready var list: VBoxContainer = %PlayersList
@@ -34,6 +36,8 @@ func _ready() -> void:
update_players()
multiplayer.peer_disconnected.connect(remove_player)
+ multiplayer.peer_connected.connect(_on_peer_connected)
+ multiplayer.peer_disconnected.connect(_on_peer_disconnected)
# reset map texture for clean load
%Thumbnail.texture = null
@@ -66,6 +70,12 @@ func remove_player(id):
list.remove_child(list.get_node(str(id)))
+func _on_peer_connected(id):
+ Network._on_peer_connected(id)
+func _on_peer_disconnected(id):
+ Network._on_peer_disconnected(id)
+
+
func _on_start_button_pressed() -> void:
start.rpc()
@@ -77,8 +87,13 @@ func _on_cancel_button_pressed() -> void:
@rpc("authority", "call_local")
func start():
- var scene = %Maps.get_child(current_map_idx).get_meta("map_scene")
- get_tree().change_scene_to_packed(scene)
+ var packed_scene = %Maps.get_child(current_map_idx).get_meta("map_scene")
+ var scene = packed_scene.instantiate()
+
+ for setting in settings:
+ scene[setting] = settings[setting]
+
+ Client.change_scene_to_instance(scene)
@rpc("authority", "call_local")
@@ -91,5 +106,30 @@ func set_map(index: int):
var node = %Maps.get_child(index)
var thumbnail = node.get_meta("thumbnail")
+ # settings
+ for child in %Settings.get_children():
+ child.queue_free()
+ if node.get_meta("settings"):
+ var scene = node.get_meta("map_scene").instantiate()
+ for setting in node.get_meta("settings", []):
+ settings[setting] = scene[setting]
+ var control = preload("res://UI/lobby_setting.tscn").instantiate()
+ control.label = setting
+ control.value = settings[setting]
+ control.disabled = !multiplayer.is_server()
+ if multiplayer.is_server():
+ control.value_changed.connect(func(value):
+ set_setting.rpc(setting, value)
+ )
+ %Settings.add_child(control)
+
node.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 1.0))
%Thumbnail.texture = thumbnail
+
+
+@rpc("authority", "call_local")
+func set_setting(key: String, value: Variant):
+ settings[key] = value
+
+ if not multiplayer.is_server():
+ %Settings.get_node(key).value = value