From 086679f1f0a3a708c73a6f524c67f3bfae601ba7 Mon Sep 17 00:00:00 2001 From: Igor Santarek Date: Tue, 21 Apr 2020 19:45:02 +0200 Subject: [PATCH] Open last edited project at startup or at will feature (#215) * Created feature that will alllow user to open last edited project on Pixelorama startup or open last edited project at will. Co-authored-by: Manolis Papadeas <35376950+OverloadedOrama@users.noreply.github.com> --- Main.tscn | 17 ++++++- .../NoProjectEditedOrCreatedAlertDialog.tscn | 7 +++ .../Dialogs/OpenLastProjectAlertDialog.tscn | 7 +++ Prefabs/Dialogs/PreferencesDialog.tscn | 44 ++++++++++------- Scripts/Dialogs/ExportDialog.gd | 2 +- Scripts/Dialogs/PreferencesDialog.gd | 9 ++++ Scripts/Global.gd | 1 + Scripts/Main.gd | 49 +++++++++++++++---- Translations/Translations.pot | 9 ++++ 9 files changed, 116 insertions(+), 29 deletions(-) create mode 100644 Prefabs/Dialogs/NoProjectEditedOrCreatedAlertDialog.tscn create mode 100644 Prefabs/Dialogs/OpenLastProjectAlertDialog.tscn diff --git a/Main.tscn b/Main.tscn index f7d4783da..570539c50 100644 --- a/Main.tscn +++ b/Main.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=57 format=2] +[gd_scene load_steps=59 format=2] [ext_resource path="res://Themes & Styles/Dark Theme/Dark Theme.tres" type="Theme" id=1] [ext_resource path="res://Scripts/Main.gd" type="Script" id=2] @@ -45,6 +45,8 @@ [ext_resource path="res://Assets/Graphics/Dark Themes/Tools/Zoom.png" type="Texture" id=43] [ext_resource path="res://Prefabs/Dialogs/HSVDialog.tscn" type="PackedScene" id=44] [ext_resource path="res://Scripts/TransparentChecker.gd" type="Script" id=45] +[ext_resource path="res://Prefabs/Dialogs/OpenLastProjectAlertDialog.tscn" type="PackedScene" id=46] +[ext_resource path="res://Prefabs/Dialogs/NoProjectEditedOrCreatedAlertDialog.tscn" type="PackedScene" id=47] [sub_resource type="Shader" id=1] code = "shader_type canvas_item; @@ -1350,7 +1352,7 @@ columns = 5 [node name="OpenSprite" type="FileDialog" parent="."] margin_right = 515.0 margin_bottom = 348.0 -window_title = "Open a File" +window_title = "Otwórz plik" resizable = true mode = 0 access = 2 @@ -1422,10 +1424,21 @@ dialog_text = "This is an error message!" [node name="NewPaletteDialog" parent="." instance=ExtResource( 36 )] [node name="PaletteImportFileDialog" parent="." instance=ExtResource( 37 )] +window_title = "Otwórz plik" filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library", "*.png; Portable Network Graphics" ) +current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama" +current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama" [node name="HSVDialog" parent="." instance=ExtResource( 44 )] +[node name="OpenLastProjectAlertDialog" parent="." instance=ExtResource( 46 )] +margin_right = 179.0 +margin_bottom = 62.0 + +[node name="NoProjectEditedOrCreatedAlertDialog" parent="." instance=ExtResource( 47 )] +margin_bottom = 62.0 +window_title = "Alarm!" + [node name="LeftCursor" type="Sprite" parent="."] visible = false diff --git a/Prefabs/Dialogs/NoProjectEditedOrCreatedAlertDialog.tscn b/Prefabs/Dialogs/NoProjectEditedOrCreatedAlertDialog.tscn new file mode 100644 index 000000000..81fe43227 --- /dev/null +++ b/Prefabs/Dialogs/NoProjectEditedOrCreatedAlertDialog.tscn @@ -0,0 +1,7 @@ +[gd_scene format=2] + +[node name="NoProjectEditedOrCreatedAlertDialog" type="AcceptDialog"] +dialog_text = "You haven't saved or opened any project in Pixelorama yet!" +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/Prefabs/Dialogs/OpenLastProjectAlertDialog.tscn b/Prefabs/Dialogs/OpenLastProjectAlertDialog.tscn new file mode 100644 index 000000000..d06c75e81 --- /dev/null +++ b/Prefabs/Dialogs/OpenLastProjectAlertDialog.tscn @@ -0,0 +1,7 @@ +[gd_scene format=2] + +[node name="OpenLastProjectAlertDialog" type="AcceptDialog"] +margin_right = 209.0 +margin_bottom = 58.0 +window_title = "Alarm!" +dialog_text = "Cannot find last project file." diff --git a/Prefabs/Dialogs/PreferencesDialog.tscn b/Prefabs/Dialogs/PreferencesDialog.tscn index c92c96038..0dcdc85be 100644 --- a/Prefabs/Dialogs/PreferencesDialog.tscn +++ b/Prefabs/Dialogs/PreferencesDialog.tscn @@ -49,30 +49,39 @@ size_flags_horizontal = 3 [node name="VBoxContainer" type="VBoxContainer" parent="HSplitContainer/ScrollContainer"] margin_right = 308.0 -margin_bottom = 1158.0 +margin_bottom = 1186.0 size_flags_horizontal = 3 [node name="General" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] margin_right = 306.0 -margin_bottom = 88.0 +margin_bottom = 116.0 -[node name="SmoothZoom" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/General"] +[node name="OpenLastProject" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/General"] margin_right = 306.0 margin_bottom = 24.0 +hint_tooltip = "Opens last opened project on startup" +mouse_default_cursor_shape = 2 +pressed = true +text = "Open last project on startup" + +[node name="SmoothZoom" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/General"] +margin_top = 28.0 +margin_right = 306.0 +margin_bottom = 52.0 hint_tooltip = "Adds a smoother transition when zooming in or out" mouse_default_cursor_shape = 2 pressed = true text = "Smooth Zoom" [node name="HSeparator2" type="HSeparator" parent="HSplitContainer/ScrollContainer/VBoxContainer/General"] -margin_top = 28.0 +margin_top = 56.0 margin_right = 306.0 -margin_bottom = 32.0 +margin_bottom = 60.0 [node name="GridContainer" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/General"] -margin_top = 36.0 +margin_top = 64.0 margin_right = 306.0 -margin_bottom = 88.0 +margin_bottom = 116.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 columns = 2 @@ -137,9 +146,9 @@ items = [ "None", null, false, 0, null, "Affect Brush's Alpha", null, false, 1, selected = 1 [node name="Languages" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] -margin_top = 92.0 +margin_top = 120.0 margin_right = 306.0 -margin_bottom = 484.0 +margin_bottom = 512.0 [node name="System Language" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Languages"] margin_right = 306.0 @@ -243,9 +252,9 @@ custom_fonts/font = ExtResource( 3 ) text = "繁體中文 [zh_TW]" [node name="Themes" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] -margin_top = 488.0 +margin_top = 516.0 margin_right = 306.0 -margin_bottom = 624.0 +margin_bottom = 652.0 [node name="Dark Theme" type="CheckBox" parent="HSplitContainer/ScrollContainer/VBoxContainer/Themes"] margin_right = 306.0 @@ -282,9 +291,9 @@ mouse_default_cursor_shape = 2 text = "Light" [node name="Canvas" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] -margin_top = 628.0 +margin_top = 656.0 margin_right = 306.0 -margin_bottom = 820.0 +margin_bottom = 848.0 [node name="GuideOptions" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Canvas"] margin_right = 306.0 @@ -456,9 +465,9 @@ mouse_default_cursor_shape = 2 color = Color( 1, 1, 1, 1 ) [node name="Image" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] -margin_top = 824.0 +margin_top = 852.0 margin_right = 306.0 -margin_bottom = 900.0 +margin_bottom = 928.0 [node name="ImageOptions" type="GridContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Image"] margin_right = 306.0 @@ -529,9 +538,9 @@ mouse_default_cursor_shape = 2 color = Color( 0, 0, 0, 0 ) [node name="Shortcuts" type="VBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer"] -margin_top = 904.0 +margin_top = 932.0 margin_right = 306.0 -margin_bottom = 1158.0 +margin_bottom = 1186.0 [node name="HBoxContainer" type="HBoxContainer" parent="HSplitContainer/ScrollContainer/VBoxContainer/Shortcuts"] margin_right = 306.0 @@ -796,6 +805,7 @@ __meta__ = { [connection signal="about_to_show" from="." to="." method="_on_PreferencesDialog_about_to_show"] [connection signal="popup_hide" from="." to="." method="_on_PreferencesDialog_popup_hide"] [connection signal="item_selected" from="HSplitContainer/Tree" to="." method="_on_Tree_item_selected"] +[connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/General/OpenLastProject" to="." method="_on_OpenLastProject_pressed"] [connection signal="pressed" from="HSplitContainer/ScrollContainer/VBoxContainer/General/SmoothZoom" to="." method="_on_SmoothZoom_pressed"] [connection signal="toggled" from="HSplitContainer/ScrollContainer/VBoxContainer/General/GridContainer/LeftIndicatorCheckbox" to="." method="_on_LeftIndicatorCheckbox_toggled"] [connection signal="toggled" from="HSplitContainer/ScrollContainer/VBoxContainer/General/GridContainer/RightIndicatorCheckbox" to="." method="_on_RightIndicatorCheckbox_toggled"] diff --git a/Scripts/Dialogs/ExportDialog.gd b/Scripts/Dialogs/ExportDialog.gd index 7c692eb08..edb717ca0 100644 --- a/Scripts/Dialogs/ExportDialog.gd +++ b/Scripts/Dialogs/ExportDialog.gd @@ -314,7 +314,7 @@ func export_processed_images(ignore_overwrites : bool) -> void: # Store settings for quick export and when the dialog is opened again was_exported = true store_export_settings() - Global.file_menu.get_popup().set_item_text(5, tr("Export") + " %s" % (file_name + file_format_string(file_format))) + Global.file_menu.get_popup().set_item_text(6, tr("Export") + " %s" % (file_name + file_format_string(file_format))) Global.notification_label("File(s) exported") hide() diff --git a/Scripts/Dialogs/PreferencesDialog.gd b/Scripts/Dialogs/PreferencesDialog.gd index bed83076b..a5a3b229a 100644 --- a/Scripts/Dialogs/PreferencesDialog.gd +++ b/Scripts/Dialogs/PreferencesDialog.gd @@ -9,6 +9,7 @@ onready var canvas = $HSplitContainer/ScrollContainer/VBoxContainer/Canvas onready var image = $HSplitContainer/ScrollContainer/VBoxContainer/Image onready var shortcuts = $HSplitContainer/ScrollContainer/VBoxContainer/Shortcuts +onready var open_last_project_button = $HSplitContainer/ScrollContainer/VBoxContainer/General/OpenLastProject onready var smooth_zoom_button = $HSplitContainer/ScrollContainer/VBoxContainer/General/SmoothZoom onready var sensitivity_option = $HSplitContainer/ScrollContainer/VBoxContainer/General/PressureSentivity/PressureSensitivityOptionButton onready var left_tool_icon = $HSplitContainer/ScrollContainer/VBoxContainer/General/GridContainer/LeftToolIconCheckbox @@ -58,6 +59,9 @@ func _ready() -> void: themes.get_child(0).pressed = true # Set default values for General options + if Global.config_cache.has_section_key("preferences", "open_last_project"): + Global.open_last_project = Global.config_cache.get_value("preferences", "open_last_project") + open_last_project_button.pressed = Global.open_last_project if Global.config_cache.has_section_key("preferences", "smooth_zoom"): Global.smooth_zoom = Global.config_cache.get_value("preferences", "smooth_zoom") smooth_zoom_button.pressed = Global.smooth_zoom @@ -508,3 +512,8 @@ func _on_ShortcutSelector_confirmed() -> void: shortcuts.get_node("Shortcuts/" + action_being_edited).text = OS.get_scancode_string(new_input_event.get_scancode_with_modifiers()) $Popups/ShortcutSelector.hide() + +func _on_OpenLastProject_pressed(): + Global.open_last_project = !Global.open_last_project + Global.config_cache.set_value("preferences", "open_last_project", Global.open_last_project) + Global.config_cache.save("user://cache.ini") diff --git a/Scripts/Global.gd b/Scripts/Global.gd index cf2767d32..6e85ad907 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -45,6 +45,7 @@ var can_draw := false # warning-ignore:unused_class_variable var has_focus := false var pressure_sensitivity_mode = Pressure_Sensitivity.NONE +var open_last_project := true var smooth_zoom := true var cursor_image = preload("res://Assets/Graphics/Cursor.png") var left_cursor_tool_texture : ImageTexture diff --git a/Scripts/Main.gd b/Scripts/Main.gd index 3dffe4e5f..3fa654dc8 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -42,6 +42,7 @@ func _ready() -> void: var file_menu_items := { "New..." : InputMap.get_action_list("new_file")[0].get_scancode_with_modifiers(), "Open..." : InputMap.get_action_list("open_file")[0].get_scancode_with_modifiers(), + 'Open last project...' : 0, "Save..." : InputMap.get_action_list("save_file")[0].get_scancode_with_modifiers(), "Save as..." : InputMap.get_action_list("save_file_as")[0].get_scancode_with_modifiers(), "Import..." : InputMap.get_action_list("import_file")[0].get_scancode_with_modifiers(), @@ -187,6 +188,12 @@ func _ready() -> void: else: Global.can_draw = true + if not Global.config_cache.has_section_key("preferences", "open_last_project"): + Global.config_cache.set_value("preferences", "open_last_project", true) + if Global.config_cache.get_value("preferences", "open_last_project"): + Global.open_last_project = Global.config_cache.get_value("preferences", "open_last_project") + load_last_project() + func _input(event : InputEvent) -> void: Global.left_cursor.position = get_global_mouse_position() + Vector2(-32, 32) Global.left_cursor.texture = Global.left_cursor_tool_texture @@ -230,31 +237,37 @@ func file_menu_id_pressed(id : int) -> void: $OpenSprite.popup_centered() Global.can_draw = false opensprite_file_selected = false - 2: # Save + 2: # Open last project + # Check if last project path is set and if yes then open + if Global.config_cache.has_section_key("preferences", "last_project_path"): + load_last_project() + else: # if not then warn user that he didn't edit any project yet + $NoProjectEditedOrCreatedAlertDialog.popup_centered() + 3: # Save is_quitting_on_save = false if OpenSave.current_save_path == "": $SaveSprite.popup_centered() Global.can_draw = false else: _on_SaveSprite_file_selected(OpenSave.current_save_path) - 3: # Save as + 4: # Save as is_quitting_on_save = false $SaveSprite.popup_centered() Global.can_draw = false - 4: # Import + 5: # Import $ImportSprites.popup_centered() Global.can_draw = false opensprite_file_selected = false - 5: # Export + 6: # Export if $ExportDialog.was_exported == false: $ExportDialog.popup_centered() Global.can_draw = false else: $ExportDialog.external_export() - 6: # Export as + 7: # Export as $ExportDialog.popup_centered() Global.can_draw = false - 7: # Quit + 8: # Quit show_quit_dialog() func edit_menu_id_pressed(id : int) -> void: @@ -405,6 +418,18 @@ func help_menu_id_pressed(id : int) -> void: $AboutDialog.popup_centered() Global.can_draw = false +func load_last_project(): + # Check if any project was saved or opened last time + if Global.config_cache.has_section_key("preferences", "last_project_path"): + # Check if file still exists on disk + var file_path = Global.config_cache.get_value("preferences", "last_project_path") + var file_check := File.new() + if file_check.file_exists(file_path): # If yes then load the file + _on_OpenSprite_file_selected(file_path) + else: + # If file doesn't exist on disk then warn user about this + $OpenLastProjectAlertDialog.popup_centered() + func _on_UnsavedCanvasDialog_confirmed() -> void: $CreateNewImage.popup_centered() @@ -414,20 +439,26 @@ func _on_OpenSprite_file_selected(path : String) -> void: OpenSave.open_pxo_file(path) $SaveSprite.current_path = path + # Set last opened project path and save + Global.config_cache.set_value("preferences", "last_project_path", path) + Global.config_cache.save("user://cache.ini") $ExportDialog.file_name = path.get_file().trim_suffix(".pxo") $ExportDialog.directory_path = path.get_base_dir() $ExportDialog.was_exported = false - file_menu.set_item_text(2, tr("Save") + " %s" % path.get_file()) - file_menu.set_item_text(5, tr("Export")) + file_menu.set_item_text(3, tr("Save") + " %s" % path.get_file()) + file_menu.set_item_text(6, tr("Export")) func _on_SaveSprite_file_selected(path : String) -> void: OpenSave.save_pxo_file(path) + # Set last opened project path and save + Global.config_cache.set_value("preferences", "last_project_path", path) + Global.config_cache.save("user://cache.ini") $ExportDialog.file_name = path.get_file().trim_suffix(".pxo") $ExportDialog.directory_path = path.get_base_dir() $ExportDialog.was_exported = false - file_menu.set_item_text(2, tr("Save") + " %s" % path.get_file()) + file_menu.set_item_text(3, tr("Save") + " %s" % path.get_file()) if is_quitting_on_save: _on_QuitDialog_confirmed() diff --git a/Translations/Translations.pot b/Translations/Translations.pot index e53ff6bcc..7702cc5bd 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -1037,3 +1037,12 @@ msgstr "" msgid "A tool assigned to the right mouse button" msgstr "" + +msgid "Cannot find last project file." +msgstr "" + +msgid "You haven't saved or opened any project in Pixelorama yet!" +msgstr "" + +msgid "Open last project..." +msgstr ""