diff --git a/Main.tscn b/Main.tscn index 35b319006..6e6b80a4f 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1459,6 +1459,13 @@ margin_bottom = 70.0 resizable = true dialog_text = "Are you sure you want to exit Pixelorama?" +[node name="QuitAndSaveDialog" type="ConfirmationDialog" parent="."] +margin_right = 200.0 +margin_bottom = 70.0 +window_title = "Save before exiting?" +resizable = true +dialog_text = "You have unsaved progress. How do you wish to proceed?" + [node name="ErrorDialog" type="AcceptDialog" parent="."] margin_right = 76.0 margin_bottom = 60.0 @@ -1546,9 +1553,10 @@ visible = false [connection signal="popup_hide" from="OutlineDialog" to="." method="_can_draw_true"] [connection signal="popup_hide" from="AboutDialog" to="." method="_can_draw_true"] [connection signal="confirmed" from="QuitDialog" to="." method="_on_QuitDialog_confirmed"] -[connection signal="custom_action" from="QuitDialog" to="." method="_on_QuitDialog_custom_action"] [connection signal="popup_hide" from="QuitDialog" to="." method="_can_draw_true"] -[connection signal="popup_hide" from="QuitDialog" to="." method="_on_QuitDialog_popup_hide"] +[connection signal="confirmed" from="QuitAndSaveDialog" to="." method="_on_QuitDialog_confirmed"] +[connection signal="custom_action" from="QuitAndSaveDialog" to="." method="_on_QuitAndSaveDialog_custom_action"] +[connection signal="popup_hide" from="QuitAndSaveDialog" to="." method="_can_draw_true"] [connection signal="confirmed" from="NewPaletteDialog" to="MenuAndUI/UI/LayerPanel/LayersAndMisc/VSplitContainer/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_new_palette_confirmed"] [connection signal="file_selected" from="PaletteImportFileDialog" to="MenuAndUI/UI/LayerPanel/LayersAndMisc/VSplitContainer/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_palette_import_file_selected"] diff --git a/Scripts/Main.gd b/Scripts/Main.gd index 9b7484315..f86b319c3 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -9,7 +9,6 @@ var redone := false var is_quitting_on_save := false var previous_left_color := Color.black var previous_right_color := Color.white -var SaveButton : Button # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -171,6 +170,9 @@ func _ready() -> void: $MenuAndUI/UI/ToolPanel/Tools/ColorAndToolOptions/ColorButtonsVertical/ColorPickersCenter/ColorPickersHorizontal/LeftColorPickerButton.get_picker().presets_visible = false $MenuAndUI/UI/ToolPanel/Tools/ColorAndToolOptions/ColorButtonsVertical/ColorPickersCenter/ColorPickersHorizontal/RightColorPickerButton.get_picker().presets_visible = false + $QuitAndSaveDialog.add_button("Save & Exit", false, "Save") + $QuitAndSaveDialog.get_ok().text = "Exit without saving" + if not Global.config_cache.has_section_key("preferences", "startup"): Global.config_cache.set_value("preferences", "startup", true) @@ -203,18 +205,7 @@ func _input(event : InputEvent) -> void: func _notification(what : int) -> void: if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit - if !$QuitDialog.visible: - if Global.saved: - $QuitDialog.window_title = "Please Confirm..." - $QuitDialog.dialog_text = "Are you sure you want to exit Pixelorama?" - $QuitDialog.get_ok().text = "OK" - else: - $QuitDialog.window_title = "Save before exiting?" - $QuitDialog.dialog_text = "You have unsaved progress. How do you wish to proceed?" - SaveButton = $QuitDialog.add_button("Save & Exit", false, "Save") - $QuitDialog.get_ok().text = "Exit without saving" - $QuitDialog.call_deferred("popup_centered") - Global.can_draw = false + show_quit_dialog() func file_menu_id_pressed(id : int) -> void: match id: @@ -250,10 +241,7 @@ func file_menu_id_pressed(id : int) -> void: $ExportSprites.popup_centered() Global.can_draw = false 7: # Quit - if !Global.saved && !$QuitDialog.visible: - SaveButton = $QuitDialog.add_button("Save", false, "Save") - $QuitDialog.popup_centered() - Global.can_draw = false + show_quit_dialog() func edit_menu_id_pressed(id : int) -> void: match id: @@ -870,17 +858,21 @@ func _on_OpacitySlider_value_changed(value) -> void: Global.layer_opacity_spinbox.value = value Global.canvas.update() -func _on_QuitDialog_custom_action(action : String) -> void: +func show_quit_dialog() -> void: + if !$QuitDialog.visible: + if Global.saved: + $QuitDialog.call_deferred("popup_centered") + else: + $QuitAndSaveDialog.call_deferred("popup_centered") + Global.can_draw = false + +func _on_QuitAndSaveDialog_custom_action(action : String) -> void: if action == "Save": is_quitting_on_save = true $SaveSprite.popup_centered() $QuitDialog.hide() Global.can_draw = false -func _on_QuitDialog_popup_hide() -> void: - if !Global.saved: - SaveButton.queue_free() - func _on_QuitDialog_confirmed() -> void: # Darken the UI to denote that the application is currently exiting # (it won't respond to user input in this state).