mtd/Scripts/scoreboard.gd

47 lines
1.3 KiB
GDScript3
Raw Normal View History

2024-02-22 06:22:22 +11:00
class_name Scoreboard extends PanelContainer
2024-02-22 06:22:22 +11:00
signal all_players_ready()
var entry_scene: PackedScene = preload("res://Scenes/UI/scoreboard_entry.tscn")
var entries: Dictionary = {}
func _ready() -> void:
$VBoxContainer/DummyEntry1.queue_free()
$VBoxContainer/DummyEntry2.queue_free()
$VBoxContainer/DummyEntry3.queue_free()
2024-02-22 06:22:22 +11:00
func get_player_entry(peer_id: int) -> ScoreboardEntry:
return entries[peer_id]
2024-02-22 06:22:22 +11:00
func set_player_ready_state(peer_id: int, state: bool) -> void:
entries[peer_id].set_ready_state(state)
2024-02-22 06:22:22 +11:00
for id: int in entries:
if !entries[id].get_ready_state():
return
all_players_ready.emit()
unready_all_players()
2024-02-22 06:22:22 +11:00
func unready_all_players() -> void:
for peer_id: int in entries:
entries[peer_id].set_ready_state(false)
2024-02-22 06:22:22 +11:00
func add_player(peer_id: int, player_profile: PlayerProfile) -> void:
var entry: ScoreboardEntry = entry_scene.instantiate() as ScoreboardEntry
entry.name = str(peer_id)
entry.set_display_name("", player_profile.get_display_name())
entry.set_character(0, player_profile.get_preferred_class())
player_profile.display_name_changed.connect(entry.set_display_name)
player_profile.preferred_class_changed.connect(entry.set_character)
entries[peer_id] = entry
$VBoxContainer.add_child(entry)
2024-02-22 06:22:22 +11:00
func remove_player(peer_id: int) -> void:
entries[peer_id].queue_free()
entries.erase(peer_id)