Files
MusicPlayer/popups/character_select_popup.gd
T
Sansan 8d21b0617d
Build / test (push) Successful in 41s
Build / build (push) Successful in 1m13s
Fix and tidy the Character select, Shortcuts, Log and QR popups
Character select
- A card only picks its character when it is clicked. Before, every card
  watched every click, so clicking below the panel could pick a card
  scrolled out of view there.
- Six columns of fixed-size cards that scroll for any number of
  characters, with a gap between the cards and the scrollbar.
- Pictures are read as PNG, JPG or WebP by their first bytes, so JPGs no
  longer print an error. Names are split into words ("Paper Mario") and
  the card under the mouse is highlighted.

Shortcuts
- Alt+Z restarts the song; it was listed as "Reset".
- Grouped by what the keys do, in sentence case, and the panel fits the
  list. A test checks that every button shortcut is listed.

Log
- Scrolls to the newest row, alternates row colours and says "Nothing
  has happened yet" when empty.

QR
- A title, and the code is set up in one place.
2026-10-07 15:24:43 +02:00

64 lines
2.0 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.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