Fixed player list

This commit is contained in:
Jan Heemstra 2021-04-04 22:49:52 +02:00
parent 9391eabbc5
commit cbe6acbe8a
3 changed files with 26 additions and 17 deletions

View file

@ -36,12 +36,12 @@ func set_local_player(player):
var nickname = $MenuContainer/MainMenu/Name.text
set_nickname(nickname)
player.set_nickname(nickname)
on_player_added(player)
var player_data = get_player_data()
print(player_data)
rpc("set_player_data", player_data)
$PlayerListContainer.update_player_list()
player.hide()
@ -282,10 +282,8 @@ remote func check_players(player_data):
player.translation += Vector3(0.0, 3.0, 0.0)
player.set_nickname(data["nickname"])
on_player_added(player)
print(player.player_class)
$PlayerListContainer.update_player_list()
func join_game():
var player = player_scene.instance()
@ -303,19 +301,13 @@ sync func spawn(player_id):
spawning_player.show()
close_menus()
func on_player_added(player):
var player_list_item = preload("res://Classes/UI/PlayerListItem.tscn").instance()
$PlayerListContainer/Panel/PlayerList.add_child(player_list_item)
player_list_item.player = player
sync func remove_player(id):
for player_list_item in $PlayerListContainer/Panel/PlayerList.get_children():
if player_list_item.network_id == str(id):
player_list_item.queue_free()
for player in $Players.get_children():
if player.name == str(id):
player.queue_free()
player.free()
$PlayerListContainer.update_player_list()
func get_spawn_point():
return $Level/SpawnPoints.get_spawn_point()

View file

@ -1,9 +1,10 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Classes/UI/theme.tres" type="Theme" id=1]
[ext_resource path="res://Game.gd" type="Script" id=2]
[ext_resource path="res://Assets/Maps/DM1/DM1.tscn" type="PackedScene" id=3]
[ext_resource path="res://Classes/UI/CharacterSelect.tscn" type="PackedScene" id=4]
[ext_resource path="res://PlayerListContainer.gd" type="Script" id=5]
[node name="Game" type="Node"]
script = ExtResource( 2 )
@ -300,6 +301,7 @@ visible = false
anchor_right = 1.0
anchor_bottom = 1.0
theme = ExtResource( 1 )
script = ExtResource( 5 )
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -0,0 +1,15 @@
extends CenterContainer
var tracked_players = []
func update_player_list():
var players = get_parent().get_node("Players").get_children()
for child in $Panel/PlayerList.get_children():
$Panel/PlayerList.remove_child(child)
for player in players:
var player_list_item = preload("res://Classes/UI/PlayerListItem.tscn").instance()
$Panel/PlayerList.add_child(player_list_item)
player_list_item.player = player