diff --git a/Translations/Translations.pot b/Translations/Translations.pot index ec9d38b1f..796f03971 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -1098,7 +1098,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 b949bdbb3..96eb54ce6 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -221,7 +221,6 @@ onready var layer_opacity_slider: ValueSlider = animation_timeline.find_node("Op onready var tile_mode_offset_dialog: AcceptDialog = control.find_node("TileModeOffsetsDialog") onready var open_sprites_dialog: FileDialog = control.find_node("OpenSprite") onready var save_sprites_dialog: FileDialog = control.find_node("SaveSprite") -onready var save_sprites_html5_dialog: ConfirmationDialog = control.find_node("SaveSpriteHTML5") onready var export_dialog: AcceptDialog = control.find_node("ExportDialog") onready var preferences_dialog: AcceptDialog = control.find_node("PreferencesDialog") onready var error_dialog: AcceptDialog = control.find_node("ErrorDialog") diff --git a/src/Main.gd b/src/Main.gd index af012eeef..f84bedded 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 changed_projects_on_quit := [] ## Array of Project(s) var cursor_image: Texture = preload("res://assets/graphics/cursor.png") onready var ui := $MenuAndUI/UI/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: Sprite = $LeftCursor @@ -281,28 +283,43 @@ func _on_OpenSprite_files_selected(paths: PoolStringArray) -> 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() == "HTML5": + 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() + yield(get_tree(), "idle_frame") + yield(get_tree(), "idle_frame") + Global.save_sprites_dialog.get_line_edit().text = project.name + + func _on_SaveSprite_file_selected(path: String) -> void: save_project(path) func save_project(path: String) -> void: - var zstd: bool = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed - var success = OpenSave.save_pxo_file(path, false, zstd) + var project_to_save := Global.current_project + if is_quitting_on_save: + project_to_save = changed_projects_on_quit[0] + var zstd := false + if OS.get_name() == "HTML5": + var file_name = save_sprite_html5.get_node("FileNameContainer/FileNameLineEdit").text + file_name += ".pxo" + path = "user://".plus_file(file_name) + else: + zstd = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed + var success := OpenSave.save_pxo_file(path, false, zstd, 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() - - -func _on_SaveSpriteHTML5_confirmed() -> void: - var file_name = Global.save_sprites_html5_dialog.get_node( - "FileNameContainer/FileNameLineEdit" - ).text - file_name += ".pxo" - var path = "user://".plus_file(file_name) - OpenSave.save_pxo_file(path, false, false) + if is_quitting_on_save: + changed_projects_on_quit.pop_front() + _save_on_quit_confirmation() + is_quitting_on_save = false func _on_OpenSprite_popup_hide() -> void: @@ -315,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().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 a65a16884..9b15c8c66 100644 --- a/src/Main.tscn +++ b/src/Main.tscn @@ -99,6 +99,7 @@ dialog_text = "Are you sure you want to exit Pixelorama?" [node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="Dialogs"] margin_right = 330.0 margin_bottom = 70.0 +popup_exclusive = true window_title = "Save before exiting?" resizable = true dialog_text = "You have unsaved progress. How do you wish to proceed?" @@ -144,7 +145,7 @@ visible = false [connection signal="popup_hide" from="Dialogs/OpenSprite" to="." method="_on_OpenSprite_popup_hide"] [connection signal="file_selected" from="Dialogs/SaveSprite" to="." method="_on_SaveSprite_file_selected"] [connection signal="popup_hide" from="Dialogs/SaveSprite" to="." method="_can_draw_true"] -[connection signal="confirmed" from="Dialogs/SaveSpriteHTML5" to="." method="_on_SaveSpriteHTML5_confirmed"] +[connection signal="confirmed" from="Dialogs/SaveSpriteHTML5" to="." method="save_project" binds= [ "" ]] [connection signal="popup_hide" from="Dialogs/SaveSpriteHTML5" to="." method="_can_draw_true"] [connection signal="popup_hide" from="Dialogs/ExportDialog" to="." method="_can_draw_true"] [connection signal="popup_hide" from="Dialogs/PreferencesDialog" to="." method="_can_draw_true"] diff --git a/src/UI/Dialogs/SaveSpriteHTML5.tscn b/src/UI/Dialogs/SaveSpriteHTML5.tscn index fd97340c4..ee9c24a97 100644 --- a/src/UI/Dialogs/SaveSpriteHTML5.tscn +++ b/src/UI/Dialogs/SaveSpriteHTML5.tscn @@ -3,6 +3,7 @@ [node name="SaveSpriteHTML5" type="ConfirmationDialog"] margin_right = 200.0 margin_bottom = 70.0 +popup_exclusive = true [node name="FileNameContainer" type="HBoxContainer" parent="."] anchor_right = 1.0 diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index d088da784..bca24f91c 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -357,7 +357,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: @@ -392,26 +392,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() == "HTML5": - 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().text = "Save" - Global.save_sprites_dialog.popup_centered() - yield(get_tree(), "idle_frame") - yield(get_tree(), "idle_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)