The popups, the volume slider, the player name field and the main window get a class_name, so the main window and the quiz hold them by their real type instead of Control. The classes already use the names the files will get.
67 lines
2.0 KiB
GDScript
67 lines
2.0 KiB
GDScript
class_name CharacterSelectPopup
|
|
extends PopupWindow
|
|
|
|
@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://character.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: Character = 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
|