Files
MusicPlayer/quiz/music_list_panel.gd
SansanandClaude Opus 5.5 0fc3be79e1
Build / test (push) Successful in 1m39s
Build / build (push) Successful in 1m14s
Add animations to popups, points, songs, the winner and the tabs (#48)
Popups fade in while growing and close the reverse way, with the backdrop
fading along. The winner gets confetti, bouncing pictures and a score graph
that draws itself from the left. Filtered statistics cards and search rows
fade in, the tabs slide in from their side, and every button bounces on hover
and click (ButtonBounce, now added to all buttons).

In the player list the score pops on every point, the first point flashes the
row, and a player on match point glows with a "Match point!" tag. A song
starting fades in the title, flashes its row (kept across list rebuilds) and
pops the play button.

Common/anim.gd holds the helpers. A saved "Reduce animations" switch in
Settings turns all movement off; the tests use it. The flash colours are
theme colours (Palette first_point, match_point, flash) in every theme.

Closes #48

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 21:49:01 +02:00

48 lines
1.9 KiB
GDScript

class_name MusicListPanel
extends PanelContainer
## The list of songs in the playlist, one row per song. A song's row flashes when the
## song starts playing and when it is answered.
## Emitted when the row of song number [param song_no] is clicked.
signal song_clicked(song_no: int)
var _song_list_object: PackedScene = preload("res://quiz/SongRow.tscn")
# Whether each song was playing and answered when the list was last shown, so a row
# can flash when its song starts or is answered
var _last_state: Dictionary = {}
# When each flash ends, in msec, so a flash goes on when the list is shown again
var _flash_ends: Dictionary = {}
@onready var _rows: VBoxContainer = %MusicList
## Shows the songs in the playlist again, so it shows their latest state.
func refresh() -> void:
Settings.delete_children(_rows)
var songs: Array[SongObject] = Playlist.get_playlist()
var state: Dictionary = {}
for i: int in songs.size():
var s: SongObject = songs[i]
var new_song_list_object: SongRow = _song_list_object.instantiate()
new_song_list_object.song_object = s
new_song_list_object.index = i
new_song_list_object.gui_input.connect(_on_row_input.bind(s.song_number))
_rows.add_child(new_song_list_object)
state[s] = [s.is_playing, s.is_answered]
# Only songs that were listed before flash, not a whole list loaded at once
if _last_state.has(s) && _last_state[s] != state[s] \
&& (s.is_playing || s.is_answered):
_flash_ends[s] = Time.get_ticks_msec() + int(Anim.SLOW * 1000)
var left: float = (_flash_ends.get(s, 0) - Time.get_ticks_msec()) / 1000.0
if left > 0:
Anim.flash(new_song_list_object, get_theme_color(&"flash", &"Palette"), left)
else:
_flash_ends.erase(s)
_last_state = state
func _on_row_input(event: InputEvent, song_no: int) -> void:
if event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT:
song_clicked.emit(song_no)