mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
Show multiple save confirmation dialogs on quit for each project that has changes
This commit is contained in:
parent
92f128af1e
commit
89b17177a1
|
@ -1124,7 +1124,7 @@ msgstr ""
|
||||||
msgid "Save before exiting?"
|
msgid "Save before exiting?"
|
||||||
msgstr ""
|
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 ""
|
msgstr ""
|
||||||
|
|
||||||
msgid "Save & Exit"
|
msgid "Save & Exit"
|
||||||
|
|
|
@ -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")
|
@onready var open_sprites_dialog: FileDialog = control.find_child("OpenSprite")
|
||||||
## Dialog used to save (.pxo) projects.
|
## Dialog used to save (.pxo) projects.
|
||||||
@onready var save_sprites_dialog: FileDialog = control.find_child("SaveSprite")
|
@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.
|
## Dialog used to export images. It has the [param ExportDialog.gd] script attached.
|
||||||
@onready var export_dialog: AcceptDialog = control.find_child("ExportDialog")
|
@onready var export_dialog: AcceptDialog = control.find_child("ExportDialog")
|
||||||
## The preferences dialog. It has the [param PreferencesDialog.gd] script attached.
|
## The preferences dialog. It has the [param PreferencesDialog.gd] script attached.
|
||||||
|
|
76
src/Main.gd
76
src/Main.gd
|
@ -3,10 +3,12 @@ extends Control
|
||||||
var opensprite_file_selected := false
|
var opensprite_file_selected := false
|
||||||
var redone := false
|
var redone := false
|
||||||
var is_quitting_on_save := 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 ui := $MenuAndUI/UI/DockableContainer as DockableContainer
|
||||||
@onready var backup_confirmation: ConfirmationDialog = $Dialogs/BackupConfirmation
|
@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_dialog: ConfirmationDialog = $Dialogs/QuitDialog
|
||||||
@onready var quit_and_save_dialog: ConfirmationDialog = $Dialogs/QuitAndSaveDialog
|
@onready var quit_and_save_dialog: ConfirmationDialog = $Dialogs/QuitAndSaveDialog
|
||||||
@onready var left_cursor: Sprite2D = $LeftCursor
|
@onready var left_cursor: Sprite2D = $LeftCursor
|
||||||
|
@ -31,7 +33,6 @@ func _ready() -> void:
|
||||||
Import.import_patterns(Global.path_join_array(Global.data_directories, "Patterns"))
|
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.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(
|
Global.open_sprites_dialog.current_dir = Global.config_cache.get_value(
|
||||||
"data", "current_dir", OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)
|
"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())
|
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:
|
func _on_SaveSprite_file_selected(path: String) -> void:
|
||||||
save_project(path)
|
save_project(path)
|
||||||
|
|
||||||
|
@ -285,22 +297,29 @@ func save_project(path: String) -> void:
|
||||||
var include_blended: bool = (
|
var include_blended: bool = (
|
||||||
Global.save_sprites_dialog.get_vbox().get_node("IncludeBlended").button_pressed
|
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:
|
if success:
|
||||||
Global.open_sprites_dialog.current_dir = path.get_base_dir()
|
Global.open_sprites_dialog.current_dir = path.get_base_dir()
|
||||||
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
|
Global.config_cache.set_value("data", "current_dir", path.get_base_dir())
|
||||||
|
if is_quitting_on_save:
|
||||||
if is_quitting_on_save:
|
changed_projects_on_quit.pop_front()
|
||||||
_quit()
|
_save_on_quit_confirmation()
|
||||||
|
|
||||||
|
|
||||||
func _on_SaveSpriteHTML5_confirmed() -> void:
|
func _on_SaveSpriteHTML5_confirmed() -> void:
|
||||||
var file_name: String = (
|
var file_name: String = save_sprite_html5.get_node("FileNameContainer/FileNameLineEdit").text
|
||||||
Global.save_sprites_html5_dialog.get_node("FileNameContainer/FileNameLineEdit").text
|
|
||||||
)
|
|
||||||
file_name += ".pxo"
|
file_name += ".pxo"
|
||||||
var path := "user://".path_join(file_name)
|
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:
|
func _on_open_sprite_visibility_changed() -> void:
|
||||||
|
@ -313,39 +332,52 @@ func _can_draw_true() -> void:
|
||||||
|
|
||||||
|
|
||||||
func show_quit_dialog() -> void:
|
func show_quit_dialog() -> void:
|
||||||
var changed_project := false
|
changed_projects_on_quit = []
|
||||||
for project in Global.projects:
|
for project in Global.projects:
|
||||||
if project.has_changed:
|
if project.has_changed:
|
||||||
changed_project = true
|
changed_projects_on_quit.append(project)
|
||||||
break
|
|
||||||
|
|
||||||
if !quit_dialog.visible:
|
if not quit_dialog.visible:
|
||||||
if !changed_project:
|
if changed_projects_on_quit.size() == 0:
|
||||||
if Global.quit_confirmation:
|
if Global.quit_confirmation:
|
||||||
quit_dialog.call_deferred("popup_centered")
|
quit_dialog.popup_centered()
|
||||||
else:
|
else:
|
||||||
_quit()
|
_quit()
|
||||||
else:
|
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)
|
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:
|
func _on_QuitDialog_confirmed() -> void:
|
||||||
_quit()
|
_quit()
|
||||||
|
|
||||||
|
|
||||||
func _on_QuitAndSaveDialog_custom_action(action: String) -> void:
|
func _on_QuitAndSaveDialog_custom_action(action: String) -> void:
|
||||||
if action == "ExitWithoutSaving":
|
if action == "ExitWithoutSaving":
|
||||||
_quit()
|
changed_projects_on_quit.pop_front()
|
||||||
|
_save_on_quit_confirmation()
|
||||||
|
|
||||||
|
|
||||||
func _on_QuitAndSaveDialog_confirmed() -> void:
|
func _on_QuitAndSaveDialog_confirmed() -> void:
|
||||||
is_quitting_on_save = true
|
is_quitting_on_save = true
|
||||||
Global.save_sprites_dialog.get_ok_button().text = "Save & Exit"
|
show_save_dialog(changed_projects_on_quit[0])
|
||||||
Global.save_sprites_dialog.popup_centered()
|
|
||||||
quit_dialog.hide()
|
|
||||||
Global.dialog_open(true)
|
|
||||||
|
|
||||||
|
|
||||||
func _quit() -> void:
|
func _quit() -> void:
|
||||||
|
|
|
@ -84,9 +84,8 @@ dialog_text = "Are you sure you want to exit Pixelorama?"
|
||||||
|
|
||||||
[node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="Dialogs"]
|
[node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="Dialogs"]
|
||||||
title = "Save before exiting?"
|
title = "Save before exiting?"
|
||||||
exclusive = false
|
ok_button_text = "Save & Exit"
|
||||||
popup_window = true
|
dialog_text = "Project %s has unsaved progress. How do you wish to proceed?"
|
||||||
dialog_text = "You have unsaved progress. How do you wish to proceed?"
|
|
||||||
|
|
||||||
[node name="ErrorDialog" type="AcceptDialog" parent="Dialogs"]
|
[node name="ErrorDialog" type="AcceptDialog" parent="Dialogs"]
|
||||||
exclusive = false
|
exclusive = false
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
size = Vector2i(675, 400)
|
size = Vector2i(675, 400)
|
||||||
exclusive = false
|
exclusive = false
|
||||||
popup_window = true
|
popup_window = true
|
||||||
|
ok_button_text = "Save"
|
||||||
access = 2
|
access = 2
|
||||||
filters = PackedStringArray("*.pxo ; Pixelorama Project")
|
filters = PackedStringArray("*.pxo ; Pixelorama Project")
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
[gd_scene format=3 uid="uid://cltlo2whtiejd"]
|
[gd_scene format=3 uid="uid://cltlo2whtiejd"]
|
||||||
|
|
||||||
[node name="SaveSpriteHTML5" type="ConfirmationDialog"]
|
[node name="SaveSpriteHTML5" type="ConfirmationDialog"]
|
||||||
exclusive = false
|
ok_button_text = "Save"
|
||||||
popup_window = true
|
|
||||||
|
|
||||||
[node name="FileNameContainer" type="HBoxContainer" parent="."]
|
[node name="FileNameContainer" type="HBoxContainer" parent="."]
|
||||||
anchors_preset = 10
|
anchors_preset = 10
|
||||||
|
|
|
@ -381,7 +381,7 @@ func file_menu_id_pressed(id: int) -> void:
|
||||||
Global.FileMenu.SAVE:
|
Global.FileMenu.SAVE:
|
||||||
_save_project_file()
|
_save_project_file()
|
||||||
Global.FileMenu.SAVE_AS:
|
Global.FileMenu.SAVE_AS:
|
||||||
_save_project_file_as()
|
Global.control.show_save_dialog()
|
||||||
Global.FileMenu.EXPORT:
|
Global.FileMenu.EXPORT:
|
||||||
_export_file()
|
_export_file()
|
||||||
Global.FileMenu.EXPORT_AS:
|
Global.FileMenu.EXPORT_AS:
|
||||||
|
@ -416,26 +416,11 @@ func _on_open_last_project_file_menu_option_pressed() -> void:
|
||||||
func _save_project_file() -> void:
|
func _save_project_file() -> void:
|
||||||
var path: String = OpenSave.current_save_paths[Global.current_project_index]
|
var path: String = OpenSave.current_save_paths[Global.current_project_index]
|
||||||
if path == "":
|
if path == "":
|
||||||
_save_project_file_as()
|
Global.control.show_save_dialog()
|
||||||
else:
|
else:
|
||||||
Global.control.save_project(path)
|
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:
|
func _export_file() -> void:
|
||||||
if Global.current_project.was_exported == false:
|
if Global.current_project.was_exported == false:
|
||||||
_popup_dialog(Global.export_dialog)
|
_popup_dialog(Global.export_dialog)
|
||||||
|
|
Loading…
Reference in a new issue