mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Show multiple save confirmation dialogs on quit for each project that has changes
This commit is contained in:
parent
7afc4d20bb
commit
2b2a65e791
|
@ -1098,7 +1098,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"
|
||||||
|
|
|
@ -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 tile_mode_offset_dialog: AcceptDialog = control.find_node("TileModeOffsetsDialog")
|
||||||
onready var open_sprites_dialog: FileDialog = control.find_node("OpenSprite")
|
onready var open_sprites_dialog: FileDialog = control.find_node("OpenSprite")
|
||||||
onready var save_sprites_dialog: FileDialog = control.find_node("SaveSprite")
|
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 export_dialog: AcceptDialog = control.find_node("ExportDialog")
|
||||||
onready var preferences_dialog: AcceptDialog = control.find_node("PreferencesDialog")
|
onready var preferences_dialog: AcceptDialog = control.find_node("PreferencesDialog")
|
||||||
onready var error_dialog: AcceptDialog = control.find_node("ErrorDialog")
|
onready var error_dialog: AcceptDialog = control.find_node("ErrorDialog")
|
||||||
|
|
78
src/Main.gd
78
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 changed_projects_on_quit := [] ## Array of Project(s)
|
||||||
var cursor_image: Texture = preload("res://assets/graphics/cursor.png")
|
var cursor_image: Texture = preload("res://assets/graphics/cursor.png")
|
||||||
|
|
||||||
onready var ui := $MenuAndUI/UI/DockableContainer
|
onready var ui := $MenuAndUI/UI/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: Sprite = $LeftCursor
|
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())
|
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:
|
func _on_SaveSprite_file_selected(path: String) -> void:
|
||||||
save_project(path)
|
save_project(path)
|
||||||
|
|
||||||
|
|
||||||
func save_project(path: String) -> void:
|
func save_project(path: String) -> void:
|
||||||
var zstd: bool = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed
|
var project_to_save := Global.current_project
|
||||||
var success = OpenSave.save_pxo_file(path, false, zstd)
|
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:
|
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:
|
||||||
_quit()
|
changed_projects_on_quit.pop_front()
|
||||||
|
_save_on_quit_confirmation()
|
||||||
|
is_quitting_on_save = false
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
func _on_OpenSprite_popup_hide() -> void:
|
func _on_OpenSprite_popup_hide() -> void:
|
||||||
|
@ -315,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().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:
|
||||||
|
|
|
@ -99,6 +99,7 @@ dialog_text = "Are you sure you want to exit Pixelorama?"
|
||||||
[node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="Dialogs"]
|
[node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="Dialogs"]
|
||||||
margin_right = 330.0
|
margin_right = 330.0
|
||||||
margin_bottom = 70.0
|
margin_bottom = 70.0
|
||||||
|
popup_exclusive = true
|
||||||
window_title = "Save before exiting?"
|
window_title = "Save before exiting?"
|
||||||
resizable = true
|
resizable = true
|
||||||
dialog_text = "You have unsaved progress. How do you wish to proceed?"
|
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="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="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="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/SaveSpriteHTML5" to="." method="_can_draw_true"]
|
||||||
[connection signal="popup_hide" from="Dialogs/ExportDialog" 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"]
|
[connection signal="popup_hide" from="Dialogs/PreferencesDialog" to="." method="_can_draw_true"]
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
[node name="SaveSpriteHTML5" type="ConfirmationDialog"]
|
[node name="SaveSpriteHTML5" type="ConfirmationDialog"]
|
||||||
margin_right = 200.0
|
margin_right = 200.0
|
||||||
margin_bottom = 70.0
|
margin_bottom = 70.0
|
||||||
|
popup_exclusive = true
|
||||||
|
|
||||||
[node name="FileNameContainer" type="HBoxContainer" parent="."]
|
[node name="FileNameContainer" type="HBoxContainer" parent="."]
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
|
|
|
@ -357,7 +357,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:
|
||||||
|
@ -392,26 +392,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() == "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:
|
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