Files
MusicPlayer/sync_window.gd
T
Sansan c7d49bc5cc Rework popups and fix blurry text and player list layout
Popups:
- All nine popups now extend a shared PopupWindow class with open(),
  close() and toggle(), instead of each copying its own close-on-click
  code. Popups that need cleanup override close().
- A click outside a popup closed it and also pressed whatever was
  underneath, e.g. Reset playlist. The closing click is now consumed.
- Popups used Godot's see-through default panel, so the song list and
  titles showed through. They now use an opaque popup theme, and a
  backdrop dims the window behind them.
- The main window root now fills the screen, so the backdrop covers it.

Text and images:
- Many labels and buttons forced nearest filtering, which made text and
  icons jagged when the window is not 1920x1080. They now use the
  default smooth filtering. Only the pixel-art "no character" picture
  keeps nearest filtering when the winner window enlarges it.

Player list:
- A long player name pushed that row's character and buttons to the
  right. Names now take the free space and shorten with an ellipsis, so
  all rows line up and use the full width of the panel.
2026-10-06 08:32:56 +02:00

254 lines
8.2 KiB
GDScript

extends PopupWindow
@onready
var sync_panel: Panel = %SyncPanel
@onready
var sync_title_label: Label = %SyncTitleLabel
@onready
var no_changes_label: Label = %NoChangesLabel
@onready
var progress_hbox: HBoxContainer = %ProgressHBoxContainer
@onready
var sync_hbox: HBoxContainer = %SyncHBoxContainer
@onready
var sync_progress_bar: ProgressBar = %SyncProgressBar
@onready
var soundtracks_added_vbox: VBoxContainer = %SoundtracksAddedVBox
@onready
var soundtracks_added_separator: VSeparator = %SoundtracksAddedSeparator
@onready
var soundtracks_readded_vbox: VBoxContainer = %SoundtracksReAddedVBox
@onready
var soundtracks_readded_separator: VSeparator = %SoundtracksReAddedSeparator
@onready
var soundtracks_changed_title_vbox: VBoxContainer = %SoundtracksChangedTitleVBox
@onready
var soundtracks_changed_title_separator: VSeparator = %SoundtracksChangedTitleSeparator
@onready
var soundtracks_changed_content_vbox: VBoxContainer = %SoundtracksChangedContentVBox
@onready
var soundtracks_changed_content_separator: VSeparator = %SoundtracksChangedContentSeparator
@onready
var soundtracks_removed_vbox: VBoxContainer = %SoundtracksRemovedVBox
@onready
var soundtracks_removed_separator: VSeparator = %SoundtracksRemovedSeparator
@onready
var catched_errors_vbox: VBoxContainer = %CatchedErrorsVBox
@onready
var sync_time: Label = %SyncTime
@onready
var sync_timer: Timer = %SyncTimer
@onready
var restart_sync_button: Button = %RestartSyncButton
@onready
var first_separator: VSeparator = %VSeparator6
var changes: bool = false
var has_synced: bool = false
signal sync_started
signal sync_finished
func _ready() -> void:
sync_timer.timeout.connect(_on_sync_timeout)
restart_sync_button.pressed.connect(start_sync)
restart_sync_button.visible = false
func show_section_if_has_data(data: Variant, vbox: VBoxContainer, separator: VSeparator, header_text: String) -> bool:
if data != null && data.size() > 0:
vbox.visible = true
make_list(data, vbox, header_text)
return true
else:
vbox.visible = false
separator.visible = false
return false
func start_sync() -> void:
print("start_sync")
self.visible = true
if has_synced:
# Already synced, just show the results
show_sync_result()
return
var sync_request_sent: Callable = func sync_request_sent() -> void:
sync_timer.start(0.75)
Settings.currently_syncing = true
sync_started.emit()
show_sync_progress()
if !Settings.currently_syncing:
MusicServerClient.start_sync(sync_request_sent)
func _on_sync_timeout() -> void:
print("_on_sync_timeout!")
var get_progress: Callable = func get_progress(data_received: Dictionary) -> void:
print("get_progress")
print("data_received: ", data_received)
if data_received != null:
if data_received.has("progress"):
sync_progress_bar.value = int(data_received.progress)
sync_time.text = data_received.time_spent if data_received.has("time_spent") else ""
else:
on_sync_finished(data_received)
MusicServerClient.fetch_sync_progress(get_progress)
func on_sync_finished(data_received: Dictionary) -> void:
has_synced = true
reset_sync_result()
if show_section_if_has_data(data_received.soundtracks_added, soundtracks_added_vbox, soundtracks_added_separator, "Added"):
changes = true
if show_section_if_has_data(data_received.soundtracks_re_added, soundtracks_readded_vbox, soundtracks_readded_separator, "ReAdded"):
changes = true
if data_received.soundtracks_changed_title != null && data_received.soundtracks_changed_title.size() > 0:
changes = true
Settings.delete_children(soundtracks_changed_title_vbox)
make_header_label(soundtracks_changed_title_vbox, "Changed Title")
var row: int = 0
for old_soundtrack_title: String in data_received.soundtracks_changed_title:
var label: Label = make_soundtrack_label(old_soundtrack_title + "\nchanged title to\n" + data_received.soundtracks_changed_title[old_soundtrack_title])
if row % 2 != 0:
label.add_theme_color_override("font_color", Color(1, 0.5, 0))
soundtracks_changed_title_vbox.add_child(label)
row += 1
soundtracks_changed_title_vbox.visible = true
if show_section_if_has_data(data_received.soundtracks_changed_content, soundtracks_changed_content_vbox, soundtracks_changed_content_separator, "Changed Content"):
changes = true
if show_section_if_has_data(data_received.soundtracks_removed, soundtracks_removed_vbox, soundtracks_removed_separator, "Removed"):
changes = true
if data_received.catched_errors != null && data_received.catched_errors.size() > 0:
catched_errors_vbox.visible = true
make_list(data_received.catched_errors, catched_errors_vbox, "CatchedErrors")
# Hide separators that don't have a visible section after them
# The structure is: RestartSyncButton -> VSeparator6 -> VBox -> Separator -> VBox -> Separator -> ...
# Hide VSeparator6 if there are no visible sections
var visible_sections: Array = []
if soundtracks_added_vbox.visible:
visible_sections.append("added")
if soundtracks_readded_vbox.visible:
visible_sections.append("readded")
if soundtracks_changed_title_vbox.visible:
visible_sections.append("changed_title")
if soundtracks_changed_content_vbox.visible:
visible_sections.append("changed_content")
if soundtracks_removed_vbox.visible:
visible_sections.append("removed")
first_separator.visible = visible_sections.size() > 1
# Show section separators only if there's a visible section after them
for i in range(visible_sections.size()):
var section = visible_sections[i]
var separator_map = {
"added": soundtracks_added_separator,
"readded": soundtracks_readded_separator,
"changed_title": soundtracks_changed_title_separator,
"changed_content": soundtracks_changed_content_separator,
"removed": soundtracks_removed_separator
}
# Show this section's separator only if there's a next section
if i < visible_sections.size() - 1:
separator_map[section].visible = true
else:
separator_map[section].visible = false
if !changes:
no_changes_label.visible = true
sync_time.text = "Total time: " + data_received.total_time if data_received.has("total_time") else ""
Settings.currently_syncing = false
sync_timer.stop()
print("sync finished")
show_sync_result()
restart_sync_button.visible = true
sync_finished.emit()
func list_visible(vbox: VBoxContainer, seperator: VSeparator) -> void:
vbox.visible = true
seperator.visible = true
func make_header_label(vbox: VBoxContainer, text: String) -> void:
var label: Label = Label.new()
label.add_theme_font_size_override("font_size", 20)
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.add_theme_color_override("font_color", Color(1, 0.5, 0))
label.text = text
vbox.add_child(label)
func make_soundtrack_label(text: String) -> Label:
var label: Label = Label.new()
label.add_theme_font_size_override("font_size", 18)
label.text = text
label.autowrap_mode = TextServer.AUTOWRAP_OFF
return label
func reset_sync_result() -> void:
sync_progress_bar.value = 0
sync_time.text = ""
changes = false
no_changes_label.visible = false
soundtracks_added_vbox.visible = false
soundtracks_added_separator.visible = false
soundtracks_readded_vbox.visible = false
soundtracks_readded_separator.visible = false
soundtracks_changed_title_vbox.visible = false
soundtracks_changed_title_separator.visible = false
soundtracks_changed_content_vbox.visible = false
soundtracks_changed_content_separator.visible = false
soundtracks_removed_vbox.visible = false
soundtracks_removed_separator.visible = false
catched_errors_vbox.visible = false
first_separator.visible = false
func make_list(list: Array, vbox: VBoxContainer, text: String) -> void:
Settings.delete_children(vbox)
make_header_label(vbox, text)
var row: int = 0
for soundtrack: String in list:
var label: Label = make_soundtrack_label(soundtrack)
if row % 2 != 0:
label.add_theme_color_override("font_color", Color(1, 0.5, 0))
vbox.add_child(label)
row += 1
func show_sync_result() -> void:
sync_title_label.text = "Sync Result"
progress_hbox.visible = false
sync_hbox.visible = true
restart_sync_button.visible = true
func show_sync_progress() -> void:
sync_title_label.text = "Sync in Progress"
progress_hbox.visible = true
no_changes_label.visible = false
sync_hbox.visible = false
catched_errors_vbox.visible = false
restart_sync_button.visible = false
first_separator.visible = false