Files
MusicPlayer/character_select_popup.gd
T
Sansan 390da577d7 Name popups *Popup and give scripts, scenes and classes matching names
Every popup is now called *Popup instead of *Window in its file, root node,
node name, class and variable, and PopupWindow becomes BasePopup. Player is
PlayerRow, SongListObject is SongRow and Character is CharacterCard. Script
files are snake_case and scene files PascalCase, each matching its class or
root node, and LightGrayTheme.tres is light_gray_theme.tres.
2026-10-06 11:22:39 +02:00

67 lines
2.0 KiB
GDScript

class_name CharacterSelectPopup
extends BasePopup
@onready
var character_panel: Panel = %CharacterPanel
@onready
var title_label: Label = %TitleLabel
@onready
var character_grid: GridContainer = %CharacterGridContainer
@onready
var close_timer: Timer = %CloseTimer
var can_select_character: bool = false
signal new_new_character_selected(file_name: String)
var character: PackedScene = preload("res://CharacterCard.tscn")
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) -> 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.connect("new_character_selected", _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
self.visible = false
if can_select_character:
new_new_character_selected.emit(texture)
close_timer.start()
can_select_character = false