From 89b17177a179a00996becdc45f5e88d19584159f Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Mon, 18 Dec 2023 20:23:55 +0200 Subject: [PATCH] Show multiple save confirmation dialogs on quit for each project that has changes --- Translations/Translations.pot | 2 +- src/Autoload/Global.gd | 2 - src/Main.gd | 76 +++++++++++++++------ src/Main.tscn | 5 +- src/UI/Dialogs/SaveSprite.tscn | 1 + src/UI/Dialogs/SaveSpriteHTML5.tscn | 3 +- src/UI/TopMenuContainer/TopMenuContainer.gd | 19 +----- 7 files changed, 61 insertions(+), 47 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index 4af3770db..7ed68084c 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -1124,7 +1124,7 @@ msgstr "" msgid "Save before exiting?" msgstr "" -msgid "You have unsaved progress. How do you wish to proceed?" +msgid "Project %s has unsaved progress. How do you wish to proceed?" msgstr "" msgid "Save & Exit" diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index dec4674dc..093cf8a19 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -499,8 +499,6 @@ var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn") @onready var open_sprites_dialog: FileDialog = control.find_child("OpenSprite") ## Dialog used to save (.pxo) projects. @onready var save_sprites_dialog: FileDialog = control.find_child("SaveSprite") -## Html version of [member save_sprites_dialog] used to save (.pxo) projects. -@onready var save_sprites_html5_dialog: ConfirmationDialog = control.find_child("SaveSpriteHTML5") ## Dialog used to export images. It has the [param ExportDialog.gd] script attached. @onready var export_dialog: AcceptDialog = control.find_child("ExportDialog") ## The preferences dialog. It has the [param PreferencesDialog.gd] script attached. diff --git a/src/Main.gd b/src/Main.gd index 5e11cfa9b..59f6b13a3 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -3,10 +3,12 @@ extends Control var opensprite_file_selected := false var redone := false var is_quitting_on_save := false -var cursor_image: Texture2D = preload("res://assets/graphics/cursor.png") +var changed_projects_on_quit: Array[Project] +var cursor_image := preload("res://assets/graphics/cursor.png") @onready var ui := $MenuAndUI/UI/DockableContainer as DockableContainer @onready var backup_confirmation: ConfirmationDialog = $Dialogs/BackupConfirmation +@onready var save_sprite_html5: ConfirmationDialog = $Dialogs/SaveSpriteHTML5 @onready var quit_dialog: ConfirmationDialog = $Dialogs/QuitDialog @onready var quit_and_save_dialog: ConfirmationDialog = $Dialogs/QuitAndSaveDialog @onready var left_cursor: Sprite2D = $LeftCursor @@ -31,7 +33,6 @@ func _ready() -> void: Import.import_patterns(Global.path_join_array(Global.data_directories, "Patterns")) quit_and_save_dialog.add_button("Exit without saving", false, "ExitWithoutSaving") - quit_and_save_dialog.get_ok_button().text = "Save & Exit" Global.open_sprites_dialog.current_dir = Global.config_cache.get_value( "data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP) @@ -277,6 +278,17 @@ func _on_OpenSprite_files_selected(paths: PackedStringArray) -> void: Global.config_cache.set_value("data", "current_dir", paths[0].get_base_dir()) +func show_save_dialog(project := Global.current_project) -> void: + Global.dialog_open(true) + if OS.get_name() == "Web": + var save_filename := save_sprite_html5.get_node("FileNameContainer/FileNameLineEdit") + save_sprite_html5.popup_centered() + save_filename.text = project.name + else: + Global.save_sprites_dialog.popup_centered() + Global.save_sprites_dialog.get_line_edit().text = project.name + + func _on_SaveSprite_file_selected(path: String) -> void: save_project(path) @@ -285,22 +297,29 @@ func save_project(path: String) -> void: var include_blended: bool = ( Global.save_sprites_dialog.get_vbox().get_node("IncludeBlended").button_pressed ) - var success := OpenSave.save_pxo_file(path, false, include_blended) + var project_to_save := Global.current_project + if is_quitting_on_save: + project_to_save = changed_projects_on_quit[0] + var success := OpenSave.save_pxo_file(path, false, include_blended, project_to_save) if success: Global.open_sprites_dialog.current_dir = path.get_base_dir() Global.config_cache.set_value("data", "current_dir", path.get_base_dir()) - - if is_quitting_on_save: - _quit() + if is_quitting_on_save: + changed_projects_on_quit.pop_front() + _save_on_quit_confirmation() func _on_SaveSpriteHTML5_confirmed() -> void: - var file_name: String = ( - Global.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text - ) + var file_name: String = save_sprite_html5.get_node("FileNameContainer/FileNameLineEdit").text file_name += ".pxo" var path := "user://".path_join(file_name) - OpenSave.save_pxo_file(path, false) + var project_to_save := Global.current_project + if is_quitting_on_save: + project_to_save = changed_projects_on_quit[0] + OpenSave.save_pxo_file(path, false, false, project_to_save) + if is_quitting_on_save: + changed_projects_on_quit.pop_front() + _save_on_quit_confirmation() func _on_open_sprite_visibility_changed() -> void: @@ -313,39 +332,52 @@ func _can_draw_true() -> void: func show_quit_dialog() -> void: - var changed_project := false + changed_projects_on_quit = [] for project in Global.projects: if project.has_changed: - changed_project = true - break + changed_projects_on_quit.append(project) - if !quit_dialog.visible: - if !changed_project: + if not quit_dialog.visible: + if changed_projects_on_quit.size() == 0: if Global.quit_confirmation: - quit_dialog.call_deferred("popup_centered") + quit_dialog.popup_centered() else: _quit() else: - quit_and_save_dialog.call_deferred("popup_centered") + quit_and_save_dialog.dialog_text = ( + tr("Project %s has unsaved progress. How do you wish to proceed?") + % changed_projects_on_quit[0].name + ) + quit_and_save_dialog.popup_centered() Global.dialog_open(true) +func _save_on_quit_confirmation() -> void: + if changed_projects_on_quit.size() == 0: + _quit() + else: + quit_and_save_dialog.dialog_text = ( + tr("Project %s has unsaved progress. How do you wish to proceed?") + % changed_projects_on_quit[0].name + ) + quit_and_save_dialog.popup_centered() + Global.dialog_open(true) + + func _on_QuitDialog_confirmed() -> void: _quit() func _on_QuitAndSaveDialog_custom_action(action: String) -> void: if action == "ExitWithoutSaving": - _quit() + changed_projects_on_quit.pop_front() + _save_on_quit_confirmation() func _on_QuitAndSaveDialog_confirmed() -> void: is_quitting_on_save = true - Global.save_sprites_dialog.get_ok_button().text = "Save & Exit" - Global.save_sprites_dialog.popup_centered() - quit_dialog.hide() - Global.dialog_open(true) + show_save_dialog(changed_projects_on_quit[0]) func _quit() -> void: diff --git a/src/Main.tscn b/src/Main.tscn index ab7d865dc..791ed8a88 100644 --- a/src/Main.tscn +++ b/src/Main.tscn @@ -84,9 +84,8 @@ dialog_text = "Are you sure you want to exit Pixelorama?" [node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="Dialogs"] title = "Save before exiting?" -exclusive = false -popup_window = true -dialog_text = "You have unsaved progress. How do you wish to proceed?" +ok_button_text = "Save & Exit" +dialog_text = "Project %s has unsaved progress. How do you wish to proceed?" [node name="ErrorDialog" type="AcceptDialog" parent="Dialogs"] exclusive = false diff --git a/src/UI/Dialogs/SaveSprite.tscn b/src/UI/Dialogs/SaveSprite.tscn index bdacbe3c9..73a3288ae 100644 --- a/src/UI/Dialogs/SaveSprite.tscn +++ b/src/UI/Dialogs/SaveSprite.tscn @@ -4,5 +4,6 @@ size = Vector2i(675, 400) exclusive = false popup_window = true +ok_button_text = "Save" access = 2 filters = PackedStringArray("*.pxo ; Pixelorama Project") diff --git a/src/UI/Dialogs/SaveSpriteHTML5.tscn b/src/UI/Dialogs/SaveSpriteHTML5.tscn index 062ccff7d..1757158a4 100644 --- a/src/UI/Dialogs/SaveSpriteHTML5.tscn +++ b/src/UI/Dialogs/SaveSpriteHTML5.tscn @@ -1,8 +1,7 @@ [gd_scene format=3 uid="uid://cltlo2whtiejd"] [node name="SaveSpriteHTML5" type="ConfirmationDialog"] -exclusive = false -popup_window = true +ok_button_text = "Save" [node name="FileNameContainer" type="HBoxContainer" parent="."] anchors_preset = 10 diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index fa94aafb8..eae923bc1 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -381,7 +381,7 @@ func file_menu_id_pressed(id: int) -> void: Global.FileMenu.SAVE: _save_project_file() Global.FileMenu.SAVE_AS: - _save_project_file_as() + Global.control.show_save_dialog() Global.FileMenu.EXPORT: _export_file() Global.FileMenu.EXPORT_AS: @@ -416,26 +416,11 @@ func _on_open_last_project_file_menu_option_pressed() -> void: func _save_project_file() -> void: var path: String = OpenSave.current_save_paths[Global.current_project_index] if path == "": - _save_project_file_as() + Global.control.show_save_dialog() else: Global.control.save_project(path) -func _save_project_file_as() -> void: - Global.dialog_open(true) - if OS.get_name() == "Web": - var save_dialog: ConfirmationDialog = Global.save_sprites_html5_dialog - var save_filename = save_dialog.get_node("FileNameContainer/FileNameLineEdit") - save_dialog.popup_centered() - save_filename.text = Global.current_project.name - else: - Global.save_sprites_dialog.get_ok_button().text = "Save" - Global.save_sprites_dialog.popup_centered() - await get_tree().process_frame - await get_tree().process_frame - Global.save_sprites_dialog.get_line_edit().text = Global.current_project.name - - func _export_file() -> void: if Global.current_project.was_exported == false: _popup_dialog(Global.export_dialog)