2024-02-22 06:22:22 +11:00
|
|
|
class_name Scoreboard extends PanelContainer
|
2023-11-08 14:28:55 +11:00
|
|
|
|
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 = {}
|
2023-11-08 14:28:55 +11:00
|
|
|
|
|
|
|
|
|
|
|
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:
|
2023-11-08 14:28:55 +11:00
|
|
|
return entries[peer_id]
|
|
|
|
|
|
|
|
|
2024-02-22 06:22:22 +11:00
|
|
|
func set_player_ready_state(peer_id: int, state: bool) -> void:
|
2023-11-08 14:28:55 +11:00
|
|
|
entries[peer_id].set_ready_state(state)
|
2024-02-22 06:22:22 +11:00
|
|
|
for id: int in entries:
|
2023-11-08 14:28:55 +11:00
|
|
|
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:
|
2023-11-08 14:28:55 +11:00
|
|
|
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
|
2023-11-08 14:28:55 +11:00
|
|
|
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:
|
2023-11-08 14:28:55 +11:00
|
|
|
entries[peer_id].queue_free()
|
|
|
|
entries.erase(peer_id)
|