diff --git a/assets/core/networking/network_test_ui.gd b/assets/core/networking/network_test_ui.gd index 79fc438..cb6325b 100644 --- a/assets/core/networking/network_test_ui.gd +++ b/assets/core/networking/network_test_ui.gd @@ -6,11 +6,9 @@ extends Control @export var join_button: Button @export var lobby_id: LineEdit @export var hosted_lobby_id: Label +@export var users_list: VBoxContainer -@export var user_box1: HBoxContainer -@export var user_box2: HBoxContainer -@export var user_box3: HBoxContainer -@export var user_box4: HBoxContainer +@export var user_box_prefab: PackedScene # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -19,6 +17,8 @@ func _ready() -> void: network_manager.user_joined_lobby.connect(_on_user_joined_lobby) + var user_box1: Node = user_box_prefab.instantiate() + users_list.add_child(user_box1) user_box1.get_node("Username").text = network_manager.username @@ -47,20 +47,12 @@ func _on_join_button_pressed() -> void: func _on_user_joined_lobby(user_id: int, username: String) -> void: - if network_manager.lobby_members.size() >= 2 and network_manager.lobby_members[1] == {"steam_id": user_id, "username": username}: - user_box2.get_node("Username").text = username - user_box2.get_node("PFP").texture = load_avatar(user_id) - user_box2.visible = true - elif network_manager.lobby_members.size() >= 3 and network_manager.lobby_members[2] == {"steam_id": user_id, "username": username}: - user_box3.get_node("Username").text = username - user_box3.get_node("PFP").texture = load_avatar(user_id) - user_box3.visible = true - elif network_manager.lobby_members.size() >= 4 and network_manager.lobby_members[3] == {"steam_id": user_id, "username": username}: - user_box4.get_node("Username").text = username - user_box4.get_node("PFP").texture = load_avatar(user_id) - user_box4.visible = true - else: - _on_user_joined_lobby(user_id, username) + var user_box: Node = user_box_prefab.instantiate() + user_box.name = "UserBox_" + str(user_id) + users_list.add_child(user_box) + + user_box.get_node("Username").text = username + user_box.get_node("PFP").texture = load_avatar(user_id) func load_avatar(user_id: int) -> ImageTexture: Steam.getPlayerAvatar(user_id) diff --git a/assets/core/networking/test-lobby.tscn b/assets/core/networking/test-lobby.tscn index 51e0fa4..9b4544f 100644 --- a/assets/core/networking/test-lobby.tscn +++ b/assets/core/networking/test-lobby.tscn @@ -2,13 +2,13 @@ [ext_resource type="PackedScene" uid="uid://bpmn7t87tfk7f" path="res://assets/core/networking/network_manager.tscn" id="1_i1w5w"] [ext_resource type="Script" path="res://assets/core/networking/network_test_ui.gd" id="2_rbs4r"] -[ext_resource type="Texture2D" uid="uid://fwub8fvl2u4i" path="res://addons/ingameconsole/ps1hagrid.png" id="3_co2ix"] +[ext_resource type="PackedScene" uid="uid://biryul3n6thlw" path="res://assets/core/networking/user_box_prefab.tscn" id="3_if51w"] [node name="Test-lobby" type="Node"] [node name="NetworkManager" parent="." instance=ExtResource("1_i1w5w")] -[node name="UiRoot" type="Control" parent="." node_paths=PackedStringArray("network_manager", "host_button", "join_button", "lobby_id", "hosted_lobby_id", "user_box1", "user_box2", "user_box3", "user_box4")] +[node name="UiRoot" type="Control" parent="." node_paths=PackedStringArray("network_manager", "host_button", "join_button", "lobby_id", "hosted_lobby_id", "users_list")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -21,10 +21,8 @@ host_button = NodePath("Panel/HBoxContainer/VBoxContainer/Host") join_button = NodePath("Panel/HBoxContainer/VBoxContainer/Join") lobby_id = NodePath("Panel/HBoxContainer/VBoxContainer/LobbyID") hosted_lobby_id = NodePath("Panel/HBoxContainer/VBoxContainer/HostedLobbyID") -user_box1 = NodePath("Panel/HBoxContainer/VBoxContainer2/UserBox1") -user_box2 = NodePath("Panel/HBoxContainer/VBoxContainer2/UserBox2") -user_box3 = NodePath("Panel/HBoxContainer/VBoxContainer2/UserBox3") -user_box4 = NodePath("Panel/HBoxContainer/VBoxContainer2/UserBox4") +users_list = NodePath("Panel/HBoxContainer/UsersList") +user_box_prefab = ExtResource("3_if51w") [node name="Panel" type="Panel" parent="UiRoot"] layout_mode = 1 @@ -63,66 +61,6 @@ visible = false layout_mode = 2 text = "Lobby hosted: " -[node name="VBoxContainer2" type="VBoxContainer" parent="UiRoot/Panel/HBoxContainer"] +[node name="UsersList" type="VBoxContainer" parent="UiRoot/Panel/HBoxContainer"] layout_mode = 2 size_flags_horizontal = 3 - -[node name="UserBox1" type="HBoxContainer" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2"] -layout_mode = 2 - -[node name="PFP" type="TextureRect" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox1"] -custom_minimum_size = Vector2(128, 128) -layout_mode = 2 -size_flags_horizontal = 4 -texture = ExtResource("3_co2ix") -expand_mode = 1 - -[node name="Username" type="Label" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox1"] -layout_mode = 2 -size_flags_horizontal = 8 -text = "Hagrid 1" - -[node name="UserBox2" type="HBoxContainer" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2"] -layout_mode = 2 - -[node name="PFP" type="TextureRect" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox2"] -custom_minimum_size = Vector2(128, 128) -layout_mode = 2 -size_flags_horizontal = 4 -texture = ExtResource("3_co2ix") -expand_mode = 1 - -[node name="Username" type="Label" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox2"] -layout_mode = 2 -size_flags_horizontal = 8 -text = "Hagrid 2" - -[node name="UserBox3" type="HBoxContainer" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2"] -layout_mode = 2 - -[node name="PFP" type="TextureRect" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox3"] -custom_minimum_size = Vector2(128, 128) -layout_mode = 2 -size_flags_horizontal = 4 -texture = ExtResource("3_co2ix") -expand_mode = 1 - -[node name="Username" type="Label" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox3"] -layout_mode = 2 -size_flags_horizontal = 8 -text = "Hagrid 3" - -[node name="UserBox4" type="HBoxContainer" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2"] -layout_mode = 2 - -[node name="PFP" type="TextureRect" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox4"] -custom_minimum_size = Vector2(128, 128) -layout_mode = 2 -size_flags_horizontal = 4 -texture = ExtResource("3_co2ix") -expand_mode = 1 - -[node name="Username" type="Label" parent="UiRoot/Panel/HBoxContainer/VBoxContainer2/UserBox4"] -layout_mode = 2 -size_flags_horizontal = 8 -text = "Hagrid 4" diff --git a/assets/core/networking/user_box_prefab.tscn b/assets/core/networking/user_box_prefab.tscn new file mode 100644 index 0000000..34a8fd3 --- /dev/null +++ b/assets/core/networking/user_box_prefab.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=2 format=3 uid="uid://biryul3n6thlw"] + +[ext_resource type="Texture2D" uid="uid://fwub8fvl2u4i" path="res://addons/ingameconsole/ps1hagrid.png" id="1_gtutw"] + +[node name="UserBox" type="HBoxContainer"] + +[node name="PFP" type="TextureRect" parent="."] +custom_minimum_size = Vector2(128, 128) +layout_mode = 2 +size_flags_horizontal = 4 +texture = ExtResource("1_gtutw") +expand_mode = 1 + +[node name="Username" type="Label" parent="."] +layout_mode = 2 +size_flags_horizontal = 8 +text = "Hagrid 1"