blob: 24df945c0e75951ecabef7e05569b2c91dec4ecb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
extends PanelContainer
@export var players: Array[Player]:
set(value):
players = value
update_players()
@onready var list: Control = %List
func _ready() -> void:
#players_list_container.visible = false
Network.players_changed.connect(update_players)
multiplayer.peer_disconnected.connect(remove_player)
func update_players():
for player in players:
var control: Control = list.get_node_or_null(str(player.id))
if not control:
control = preload("res://UI/PlayersListItem.tscn").instantiate()
control.name = str(player.id)
control.modulate = player.get_color()
control.get_node("%Indicator").visible = player.id == multiplayer.get_unique_id()
list.add_child(control)
control.get_node("%ID").text = str(player.username)
control.get_node("%ID").tooltip_text = str(player.id)
control.get_node("%Score").text = str(player.income)
list.move_child(control, Network.get_ordered_player_ids(players).find(player.id) + 1)
func remove_player(id):
# TODO: function is called twice for some reason?
var node = list.get_node_or_null(str(id))
if node:
list.remove_child(node)
for idx in players.size():
if players[idx].id == id:
players.remove_at(idx)
break
|