2019-08-18 09:28:38 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
var opensprite_file_selected := false
|
2019-11-13 13:45:55 +00:00
|
|
|
var redone := false
|
2020-02-22 22:52:51 +00:00
|
|
|
var is_quitting_on_save := false
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
2019-12-04 17:16:18 +00:00
|
|
|
get_tree().set_auto_accept_quit(false)
|
2020-05-23 21:22:06 +00:00
|
|
|
setup_application_window_size()
|
|
|
|
|
2020-06-05 17:15:40 +00:00
|
|
|
Global.window_title = tr("untitled") + " - Pixelorama " + Global.current_version
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.layers[0].name = tr("Layer") + " 0"
|
|
|
|
Global.layers_container.get_child(0).label.text = Global.current_project.layers[0].name
|
|
|
|
Global.layers_container.get_child(0).line_edit.text = Global.current_project.layers[0].name
|
2020-05-23 21:22:06 +00:00
|
|
|
|
|
|
|
Import.import_brushes(Global.directory_module.get_brushes_search_path_in_order())
|
|
|
|
Import.import_patterns(Global.directory_module.get_patterns_search_path_in_order())
|
|
|
|
|
2020-07-17 23:27:47 +00:00
|
|
|
Global.quit_and_save_dialog.add_button("Save & Exit", false, "Save")
|
|
|
|
Global.quit_and_save_dialog.get_ok().text = "Exit without saving"
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2020-10-25 01:26:31 +00:00
|
|
|
Global.open_sprites_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)
|
|
|
|
Global.save_sprites_dialog.current_dir = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)
|
|
|
|
|
2020-07-10 23:09:17 +00:00
|
|
|
var zstd_checkbox := CheckBox.new()
|
|
|
|
zstd_checkbox.name = "ZSTDCompression"
|
|
|
|
zstd_checkbox.pressed = true
|
|
|
|
zstd_checkbox.text = "Use ZSTD Compression"
|
|
|
|
zstd_checkbox.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND
|
2020-07-17 23:27:47 +00:00
|
|
|
Global.save_sprites_dialog.get_vbox().add_child(zstd_checkbox)
|
2020-07-10 23:09:17 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
if not Global.config_cache.has_section_key("preferences", "startup"):
|
|
|
|
Global.config_cache.set_value("preferences", "startup", true)
|
|
|
|
show_splash_screen()
|
|
|
|
|
|
|
|
handle_backup()
|
|
|
|
|
2020-05-29 21:28:17 +00:00
|
|
|
# If the user wants to run Pixelorama with arguments in terminal mode
|
|
|
|
# or open files with Pixelorama directly, then handle that
|
|
|
|
if OS.get_cmdline_args():
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.handle_loading_files(OS.get_cmdline_args())
|
2020-05-29 17:19:22 +00:00
|
|
|
get_tree().connect("files_dropped", self, "_on_files_dropped")
|
2020-05-23 21:22:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
Global.right_cursor.position = get_global_mouse_position() + Vector2(32, 32)
|
|
|
|
Global.right_cursor.texture = Global.right_cursor_tool_texture
|
|
|
|
|
|
|
|
if event is InputEventKey and (event.scancode == KEY_ENTER or event.scancode == KEY_KP_ENTER):
|
|
|
|
if get_focus_owner() is LineEdit:
|
|
|
|
get_focus_owner().release_focus()
|
|
|
|
|
|
|
|
if event.is_action_pressed("redo_secondary"): # Shift + Ctrl + Z
|
|
|
|
redone = true
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.redo()
|
2020-05-23 21:22:06 +00:00
|
|
|
redone = false
|
|
|
|
|
|
|
|
|
|
|
|
func setup_application_window_size() -> void:
|
2020-07-21 21:11:33 +00:00
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
return
|
2019-09-14 19:55:33 +00:00
|
|
|
# Set a minimum window size to prevent UI elements from collapsing on each other.
|
2020-05-30 21:20:41 +00:00
|
|
|
OS.min_window_size = Vector2(1024, 576)
|
2019-12-07 15:45:48 +00:00
|
|
|
|
|
|
|
# Restore the window position/size if values are present in the configuration cache
|
2019-12-18 16:12:44 +00:00
|
|
|
if Global.config_cache.has_section_key("window", "screen"):
|
|
|
|
OS.current_screen = Global.config_cache.get_value("window", "screen")
|
|
|
|
if Global.config_cache.has_section_key("window", "maximized"):
|
|
|
|
OS.window_maximized = Global.config_cache.get_value("window", "maximized")
|
2019-11-19 21:36:37 +00:00
|
|
|
|
|
|
|
if !OS.window_maximized:
|
2019-12-18 16:12:44 +00:00
|
|
|
if Global.config_cache.has_section_key("window", "position"):
|
|
|
|
OS.window_position = Global.config_cache.get_value("window", "position")
|
|
|
|
if Global.config_cache.has_section_key("window", "size"):
|
|
|
|
OS.window_size = Global.config_cache.get_value("window", "size")
|
2019-11-19 21:36:37 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
|
|
|
func show_splash_screen() -> void:
|
2020-05-02 15:10:01 +00:00
|
|
|
# Wait for the window to adjust itself, so the popup is correctly centered
|
2020-07-21 21:11:33 +00:00
|
|
|
yield(get_tree().create_timer(0.2), "timeout")
|
2020-02-18 23:13:29 +00:00
|
|
|
if Global.config_cache.get_value("preferences", "startup"):
|
2020-07-17 23:27:47 +00:00
|
|
|
$Dialogs/SplashDialog.popup_centered() # Splash screen
|
2020-05-08 00:10:23 +00:00
|
|
|
modulate = Color(0.5, 0.5, 0.5)
|
2020-02-18 23:13:29 +00:00
|
|
|
else:
|
|
|
|
Global.can_draw = true
|
2020-01-14 03:44:16 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
|
|
|
func handle_backup() -> void:
|
2020-04-30 17:33:24 +00:00
|
|
|
# If backup file exists then Pixelorama was not closed properly (probably crashed) - reopen backup
|
2020-07-17 23:27:47 +00:00
|
|
|
var backup_confirmation : ConfirmationDialog = $Dialogs/BackupConfirmation
|
|
|
|
backup_confirmation.get_cancel().text = tr("Delete")
|
2020-04-30 17:33:24 +00:00
|
|
|
if Global.config_cache.has_section("backups"):
|
|
|
|
var project_paths = Global.config_cache.get_section_keys("backups")
|
|
|
|
if project_paths.size() > 0:
|
2020-06-05 23:16:53 +00:00
|
|
|
# Get backup paths
|
|
|
|
var backup_paths := []
|
|
|
|
for p_path in project_paths:
|
|
|
|
backup_paths.append(Global.config_cache.get_value("backups", p_path))
|
2020-04-30 17:33:24 +00:00
|
|
|
# Temporatily stop autosave until user confirms backup
|
|
|
|
OpenSave.autosave_timer.stop()
|
2020-07-17 23:27:47 +00:00
|
|
|
backup_confirmation.dialog_text = tr(backup_confirmation.dialog_text) % project_paths
|
|
|
|
backup_confirmation.connect("confirmed", self, "_on_BackupConfirmation_confirmed", [project_paths, backup_paths])
|
|
|
|
backup_confirmation.get_cancel().connect("pressed", self, "_on_BackupConfirmation_delete", [project_paths, backup_paths])
|
|
|
|
backup_confirmation.popup_centered()
|
2020-05-08 00:10:23 +00:00
|
|
|
Global.can_draw = false
|
|
|
|
modulate = Color(0.5, 0.5, 0.5)
|
2020-04-30 17:33:24 +00:00
|
|
|
else:
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|
2020-04-30 17:33:24 +00:00
|
|
|
else:
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|
2020-04-21 17:45:02 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
2020-05-29 21:28:17 +00:00
|
|
|
func _notification(what : int) -> void:
|
|
|
|
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit
|
|
|
|
show_quit_dialog()
|
|
|
|
|
|
|
|
|
2020-05-30 21:42:35 +00:00
|
|
|
func _on_files_dropped(_files : PoolStringArray, _screen : int) -> void:
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.handle_loading_files(_files)
|
2020-05-29 21:28:17 +00:00
|
|
|
|
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
func load_last_project() -> void:
|
2020-07-28 22:54:15 +00:00
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
return
|
2020-04-30 21:02:52 +00:00
|
|
|
# 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
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.open_pxo_file(file_path)
|
2020-04-30 21:02:52 +00:00
|
|
|
else:
|
|
|
|
# If file doesn't exist on disk then warn user about this
|
2020-05-19 22:37:36 +00:00
|
|
|
Global.error_dialog.set_text("Cannot find last project file.")
|
|
|
|
Global.error_dialog.popup_centered()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-04-21 17:45:02 +00:00
|
|
|
|
2020-04-02 12:28:47 +00:00
|
|
|
|
2020-10-26 20:51:55 +00:00
|
|
|
func load_recent_project_file(path : String) -> void:
|
|
|
|
if OS.get_name() == "HTML5":
|
|
|
|
return
|
2020-10-27 21:03:43 +00:00
|
|
|
|
2020-10-26 20:51:55 +00:00
|
|
|
# Check if file still exists on disk
|
|
|
|
var file_check := File.new()
|
|
|
|
if file_check.file_exists(path): # If yes then load the file
|
|
|
|
OpenSave.handle_loading_files([path])
|
|
|
|
else:
|
|
|
|
# If file doesn't exist on disk then warn user about this
|
|
|
|
Global.error_dialog.set_text("Cannot find project file.")
|
|
|
|
Global.error_dialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
2019-11-21 19:13:15 +00:00
|
|
|
func _on_OpenSprite_file_selected(path : String) -> void:
|
2020-06-11 22:11:58 +00:00
|
|
|
OpenSave.handle_loading_files([path])
|
2020-02-22 15:14:32 +00:00
|
|
|
|
2019-11-21 19:13:15 +00:00
|
|
|
|
2020-01-10 14:21:46 +00:00
|
|
|
func _on_SaveSprite_file_selected(path : String) -> void:
|
2020-07-10 23:09:17 +00:00
|
|
|
var zstd = Global.save_sprites_dialog.get_vbox().get_node("ZSTDCompression").pressed
|
|
|
|
OpenSave.save_pxo_file(path, false, zstd)
|
2020-04-09 20:54:05 +00:00
|
|
|
|
2020-02-22 22:52:51 +00:00
|
|
|
if is_quitting_on_save:
|
|
|
|
_on_QuitDialog_confirmed()
|
2019-09-14 19:55:33 +00:00
|
|
|
|
|
|
|
|
2020-06-30 17:25:43 +00:00
|
|
|
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)
|
2020-07-10 23:09:17 +00:00
|
|
|
OpenSave.save_pxo_file(path, false, false)
|
2020-06-30 17:25:43 +00:00
|
|
|
|
|
|
|
|
2020-06-11 22:11:58 +00:00
|
|
|
func _on_OpenSprite_popup_hide() -> void:
|
2019-08-18 09:28:38 +00:00
|
|
|
if !opensprite_file_selected:
|
2020-05-08 15:37:45 +00:00
|
|
|
_can_draw_true()
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func _can_draw_true() -> void:
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(false)
|
2020-05-01 17:47:10 +00:00
|
|
|
|
|
|
|
|
2020-02-23 00:11:52 +00:00
|
|
|
func show_quit_dialog() -> void:
|
2020-06-13 14:59:57 +00:00
|
|
|
if !Global.quit_dialog.visible:
|
2020-06-04 18:05:36 +00:00
|
|
|
if !Global.current_project.has_changed:
|
2020-06-13 14:59:57 +00:00
|
|
|
Global.quit_dialog.call_deferred("popup_centered")
|
2020-02-23 00:11:52 +00:00
|
|
|
else:
|
2020-06-13 14:59:57 +00:00
|
|
|
Global.quit_and_save_dialog.call_deferred("popup_centered")
|
2020-04-13 02:07:52 +00:00
|
|
|
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-02-23 00:11:52 +00:00
|
|
|
|
2020-04-13 02:07:52 +00:00
|
|
|
|
2020-02-23 00:11:52 +00:00
|
|
|
func _on_QuitAndSaveDialog_custom_action(action : String) -> void:
|
2020-02-22 15:02:56 +00:00
|
|
|
if action == "Save":
|
2020-02-22 22:52:51 +00:00
|
|
|
is_quitting_on_save = true
|
2020-07-17 23:27:47 +00:00
|
|
|
Global.save_sprites_dialog.popup_centered()
|
|
|
|
Global.quit_dialog.hide()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-02-22 15:02:56 +00:00
|
|
|
|
2020-04-13 02:07:52 +00:00
|
|
|
|
2020-02-22 22:52:51 +00:00
|
|
|
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).
|
|
|
|
modulate = Color(0.5, 0.5, 0.5)
|
|
|
|
get_tree().quit()
|
2020-04-27 15:09:54 +00:00
|
|
|
|
|
|
|
|
2020-06-05 23:16:53 +00:00
|
|
|
func _on_BackupConfirmation_confirmed(project_paths : Array, backup_paths : Array) -> void:
|
|
|
|
OpenSave.reload_backup_file(project_paths, backup_paths)
|
2020-04-30 17:33:24 +00:00
|
|
|
OpenSave.autosave_timer.start()
|
2020-07-31 20:26:52 +00:00
|
|
|
Export.file_name = OpenSave.current_save_paths[0].get_file().trim_suffix(".pxo")
|
|
|
|
Export.directory_path = OpenSave.current_save_paths[0].get_base_dir()
|
|
|
|
Export.was_exported = false
|
2020-06-13 14:59:57 +00:00
|
|
|
Global.file_menu.get_popup().set_item_text(3, tr("Save") + " %s" % OpenSave.current_save_paths[0].get_file())
|
2020-06-25 02:07:07 +00:00
|
|
|
Global.file_menu.get_popup().set_item_text(5, tr("Export"))
|
2020-04-30 17:33:24 +00:00
|
|
|
|
|
|
|
|
2020-06-05 23:16:53 +00:00
|
|
|
func _on_BackupConfirmation_delete(project_paths : Array, backup_paths : Array) -> void:
|
|
|
|
for i in range(project_paths.size()):
|
|
|
|
OpenSave.remove_backup_by_path(project_paths[i], backup_paths[i])
|
2020-04-30 17:33:24 +00:00
|
|
|
OpenSave.autosave_timer.start()
|
|
|
|
# Reopen last project
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|