Files
MusicPlayer/quiz/music_list_panel.gd
T
Sansan 78e1facaf0 Lay out the song list's pictures and text to fit any number of players
The players' pictures sit on the right in even lines of at most four, each
ending at the row's right edge, so five pictures are 3 + 2 and seven 4 + 3.
The text takes the room they leave and wraps only when it does not fit, and
the row is as tall as the taller of the two, instead of a width fixed by
the number of pictures.

Rows are rounded and alternate like the other lists, are highlighted under
the mouse, and the playing song has an orange edge. Clicking a picture
clicks its song.
2026-10-09 17:25:38 +02:00

30 lines
1.0 KiB
GDScript

class_name MusicListPanel
extends PanelContainer
## The list of songs in the playlist, one row per song.
## 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")
@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()
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)
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)