Files
MusicPlayer/popups/character_select_popup.gd
T
Sansan d77b72159d Sort the scripts and scenes into folders
main/ holds the main window and top bar, quiz/ the quiz and its parts,
player/ the music player, popups/ every popup and what they share, data/ the
songs, players, playlist and settings, server/ the MusicServer client,
common/ the list row and GameLog, and themes/ the themes and style boxes.
2026-10-06 11:57:29 +02:00

66 lines
2.1 KiB
GDScript

class_name CharacterSelectPopup
extends BasePopup
## Emitted with the picture of the character that was picked.
signal character_selected(texture: ImageTexture)
var can_select_character: bool = false
var character: PackedScene = preload("res://popups/CharacterCard.tscn")
@onready var character_panel: Panel = %CharacterPanel
@onready var title_label: Label = %TitleLabel
@onready var character_grid: GridContainer = %CharacterGridContainer
@onready var close_timer: Timer = %CloseTimer
func _ready() -> void:
close_timer.timeout.connect(_on_close_timeout)
func _on_close_timeout() -> void:
GameLog.debug("_on_close_timeout!")
Settings.character_select_open = false
close_timer.stop()
func load_characters() -> void:
GameLog.debug("load_characters")
var fetch_character_list: Callable = func fetch_character_list(list: Variant) -> void:
GameLog.debug("fetch_character_list")
Settings.delete_children(character_grid)
if typeof(list) == TYPE_ARRAY:
for character_name: String in list:
GameLog.debug("character_name ", character_name)
var character_box: CharacterCard = character.instantiate()
character_grid.add_child(character_box)
character_box.custom_minimum_size = Vector2(235, 145)
character_box.size = Vector2(235, 145)
character_box.set_character_name(character_name)
character_box.new_character_selected.connect(_on_character_selected)
MusicServerClient.fetch_character_list(fetch_character_list)
func show_grid(player_name: String) -> void:
GameLog.debug("show_grid")
title_label.text = "Select character for " + player_name
close_timer.stop()
open()
can_select_character = true
Settings.character_select_open = true
func close() -> void:
super()
Settings.character_select_open = false
func _on_character_selected(texture: ImageTexture) -> void:
GameLog.debug("_on_character_selected")
# Not close(): character_select_open stays true until close_timer fires, so the click
# that picked the character does not also select a song behind it
visible = false
if can_select_character:
character_selected.emit(texture)
close_timer.start()
can_select_character = false