Only list played songs in the statistics song list
Songs never played are left out of the song list, so the Show menu is hidden while it is shown.
This commit is contained in:
1 parent
a4e6da4c28
commit
84e137e16a
4 files changed
+464
-471
No files matched your search
@@ -1,8 +1,8 @@
|
||||
class_name StatisticsView
|
||||
extends Panel
|
||||
## Shows every soundtrack on the server as a card with its play statistics, or every
|
||||
## song in a list with its soundtrack. Either can be searched, filtered on whether it has
|
||||
## been played, and sorted.
|
||||
## played song in a list with its soundtrack. Both can be searched and sorted, and the
|
||||
## cards filtered on whether the soundtrack has been played.
|
||||
##
|
||||
## Shown instead of the quiz when the Statistics tab is chosen.
|
||||
|
||||
@@ -36,6 +36,7 @@ var _songs_ready: bool = false
|
||||
|
||||
@onready var search_field: LineEdit = %SearchField
|
||||
@onready var clear_button: Button = %ClearButton
|
||||
@onready var show_label: Label = $Toolbar/ShowLabel
|
||||
@onready var show_option: OptionButton = %ShowOption
|
||||
@onready var sort_option: OptionButton = %SortOption
|
||||
@onready var count_label: Label = %CountLabel
|
||||
@@ -81,6 +82,9 @@ func set_mode(new_mode: Mode) -> void:
|
||||
songs_mode_button.set_pressed_no_signal(mode == Mode.SONGS)
|
||||
card_scroll.visible = mode == Mode.SOUNDTRACKS
|
||||
song_list.visible = mode == Mode.SONGS
|
||||
# The song list only has played songs, so there is nothing to filter
|
||||
show_label.visible = mode == Mode.SOUNDTRACKS
|
||||
show_option.visible = mode == Mode.SOUNDTRACKS
|
||||
search_field.placeholder_text = "Search soundtracks" if mode == Mode.SOUNDTRACKS \
|
||||
else "Search songs and soundtracks"
|
||||
apply_sort()
|
||||
@@ -167,11 +171,10 @@ func _on_song_pressed(song: SongInfoForStats) -> void:
|
||||
soundtrack_selected.emit(_soundtracks[song.soundtrack_name])
|
||||
|
||||
|
||||
# Shows the songs matching the search text and the show menu, in the sort menu's order
|
||||
# Shows the songs matching the search text, in the sort menu's order
|
||||
func _show_songs() -> void:
|
||||
_prepare_songs()
|
||||
var search_text: String = search_field.text.strip_edges()
|
||||
var filter: ShowFilter = show_option.selected as ShowFilter
|
||||
var song_names: Dictionary = {}
|
||||
var soundtrack_names: Dictionary = {}
|
||||
if !search_text.is_empty():
|
||||
@@ -182,18 +185,18 @@ func _show_songs() -> void:
|
||||
var shown: Array[SongInfoForStats] = []
|
||||
for song: SongInfoForStats in songs_in_order(_songs_a_to_z,
|
||||
sort_option.selected as SortOrder):
|
||||
if (search_text.is_empty() || song_names.has(song.song_name)
|
||||
|| soundtrack_names.has(song.soundtrack_name)) \
|
||||
&& _song_passes_filter(song, filter):
|
||||
if search_text.is_empty() || song_names.has(song.song_name) \
|
||||
|| soundtrack_names.has(song.soundtrack_name):
|
||||
shown.append(song)
|
||||
song_list.show_songs(shown, search_text)
|
||||
if shown.size() == _songs_a_to_z.size():
|
||||
count_label.text = "%d songs" % shown.size()
|
||||
count_label.text = "%d played songs" % shown.size()
|
||||
else:
|
||||
count_label.text = "%d of %d songs" % [shown.size(), _songs_a_to_z.size()]
|
||||
count_label.text = "%d of %d played songs" % [shown.size(), _songs_a_to_z.size()]
|
||||
|
||||
|
||||
# Lists every song once after loading, sorted A to Z, which the other orders start from
|
||||
# Lists every played song once after loading, sorted A to Z, which the other orders
|
||||
# start from. Songs never played are left out: there are many and they say nothing.
|
||||
func _prepare_songs() -> void:
|
||||
if _songs_ready:
|
||||
return
|
||||
@@ -202,6 +205,8 @@ func _prepare_songs() -> void:
|
||||
var names: Dictionary = {}
|
||||
for soundtrack: SoundtrackWithSongs in _soundtracks.values():
|
||||
for song: SongInfoForStats in soundtrack.songs:
|
||||
if song.times_played == 0:
|
||||
continue
|
||||
# The song list finds a song's soundtrack by its name
|
||||
song.soundtrack_name = soundtrack.soundtrack_name
|
||||
_songs_a_to_z.append(song)
|
||||
@@ -243,15 +248,6 @@ static func songs_in_order(
|
||||
return a_to_z
|
||||
|
||||
|
||||
static func _song_passes_filter(song: SongInfoForStats, filter: ShowFilter) -> bool:
|
||||
match filter:
|
||||
ShowFilter.PLAYED:
|
||||
return song.times_played > 0
|
||||
ShowFilter.NEVER_PLAYED:
|
||||
return song.times_played == 0
|
||||
return true
|
||||
|
||||
|
||||
func _on_load_failed() -> void:
|
||||
_loading = false
|
||||
if cards.is_empty():
|
||||
|
||||
Reference in new issue
Block a user