summaryrefslogtreecommitdiff
path: root/UI/lobby.gd
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-11-26 17:13:40 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-11-26 17:13:40 +0100
commitcb9bb9d1c757b53707c741a3c8c218b513ffb5ec (patch)
tree1e3741a70672504d71685db98b22f7fe61e0e6cb /UI/lobby.gd
parent72863ffa31e27f4c6be862d80472cfb897fccaea (diff)
next commit
Diffstat (limited to 'UI/lobby.gd')
-rw-r--r--UI/lobby.gd135
1 files changed, 0 insertions, 135 deletions
diff --git a/UI/lobby.gd b/UI/lobby.gd
deleted file mode 100644
index f7d8405..0000000
--- a/UI/lobby.gd
+++ /dev/null
@@ -1,135 +0,0 @@
-extends Control
-
-
-signal joined
-
-var current_map_idx := 0
-
-var settings := {}
-
-@onready var list: VBoxContainer = %PlayersList
-
-
-func _ready() -> void:
- if not multiplayer.is_server():
- %StartButton.disabled = true
- #%StartButton.queue_free()
-
- %PlayersList.remove_child(%PlayersList.get_child(0))
- %PlayersList.remove_child(%PlayersList.get_child(0))
-
- if multiplayer.is_server():
- set_map.rpc(current_map_idx)
- joined.connect(func():
- set_map.rpc(current_map_idx)
- )
- for idx in %Maps.get_child_count():
- %Maps.get_child(idx).pressed.connect(func():
- set_map.rpc(idx)
- )
- if not multiplayer.is_server():
- set_map(0)
- for node: Control in %Maps.get_children():
- node.mouse_filter = Control.MOUSE_FILTER_IGNORE
-
- Network.players_changed.connect(update_players)
- 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
- set_map(current_map_idx)
-
-
-func update_players():
- for id in Network.get_ordered_player_ids():
- var player: Player = Network.get_player(id)
-
- var control: Control = list.get_node_or_null(str(id))
- if not control:
- control = MarginContainer.new()
- control.name = str(id)
- var label = Label.new()
- label.add_theme_color_override("font_color", player.get_color())
- if id == multiplayer.get_unique_id():
- label.add_theme_color_override("font_outline_color", Color(0.75, 0.75, 0.75, 0.75))
- label.add_theme_constant_override("outline_size", 10)
- control.add_child(label)
- list.add_child(control)
- joined.emit()
-
- control.get_child(0).text = str(player.username)
- control.get_child(0).tooltip_text = str(id)
- list.move_child(control, Network.get_ordered_player_ids().find(id) + 1)
-
-
-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()
-
-
-func _on_cancel_button_pressed() -> void:
- multiplayer.multiplayer_peer.close()
- get_tree().change_scene_to_file("res://UI/Start.tscn")
-
-
-@rpc("authority", "call_local")
-func start():
- 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")
-func set_map(index: int):
- current_map_idx = index
-
- for node: Button in %Maps.get_children():
- node.add_theme_color_override("font_color", Color(1.0, 1.0, 1.0, 0.5))
-
- 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