2019-08-18 09:28:38 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
var opensprite_file_selected := false
|
2019-12-28 01:07:48 +00:00
|
|
|
var file_menu : PopupMenu
|
2019-09-18 21:10:23 +00:00
|
|
|
var view_menu : PopupMenu
|
2019-11-13 13:45:55 +00:00
|
|
|
var redone := false
|
2020-05-01 16:40:36 +00:00
|
|
|
var unsaved_canvas_state := 0
|
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()
|
|
|
|
|
|
|
|
setup_file_menu()
|
|
|
|
setup_edit_menu()
|
|
|
|
setup_view_menu()
|
|
|
|
setup_image_menu()
|
|
|
|
setup_help_menu()
|
|
|
|
|
|
|
|
Global.window_title = "(" + tr("untitled") + ") - Pixelorama " + Global.current_version
|
|
|
|
|
|
|
|
Global.layers[0][0] = tr("Layer") + " 0"
|
|
|
|
Global.layers_container.get_child(0).label.text = Global.layers[0][0]
|
|
|
|
Global.layers_container.get_child(0).line_edit.text = Global.layers[0][0]
|
|
|
|
|
|
|
|
Import.import_brushes(Global.directory_module.get_brushes_search_path_in_order())
|
|
|
|
Import.import_patterns(Global.directory_module.get_patterns_search_path_in_order())
|
|
|
|
|
|
|
|
Global.left_color_picker.get_picker().presets_visible = false
|
|
|
|
Global.right_color_picker.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)
|
|
|
|
show_splash_screen()
|
|
|
|
|
|
|
|
handle_backup()
|
|
|
|
|
|
|
|
handle_running_pixelorama_with_arguments()
|
|
|
|
|
|
|
|
|
|
|
|
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("toggle_fullscreen"):
|
|
|
|
OS.window_fullscreen = !OS.window_fullscreen
|
|
|
|
|
|
|
|
if event.is_action_pressed("redo_secondary"): # Shift + Ctrl + Z
|
|
|
|
redone = true
|
|
|
|
Global.undo_redo.redo()
|
|
|
|
redone = false
|
|
|
|
|
|
|
|
|
|
|
|
func setup_application_window_size() -> void:
|
2019-09-14 19:55:33 +00:00
|
|
|
# Set a minimum window size to prevent UI elements from collapsing on each other.
|
|
|
|
# This property is only available in 3.2alpha or later, so use `set()` to fail gracefully if it doesn't exist.
|
2020-04-04 21:45:19 +00:00
|
|
|
OS.set("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 setup_file_menu() -> void:
|
2019-08-18 09:28:38 +00:00
|
|
|
var file_menu_items := {
|
2020-04-07 22:56:05 +00:00
|
|
|
"New..." : InputMap.get_action_list("new_file")[0].get_scancode_with_modifiers(),
|
|
|
|
"Open..." : InputMap.get_action_list("open_file")[0].get_scancode_with_modifiers(),
|
2020-04-21 17:45:02 +00:00
|
|
|
'Open last project...' : 0,
|
2020-04-07 22:56:05 +00:00
|
|
|
"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(),
|
|
|
|
"Export..." : InputMap.get_action_list("export_file")[0].get_scancode_with_modifiers(),
|
|
|
|
"Export as..." : InputMap.get_action_list("export_file_as")[0].get_scancode_with_modifiers(),
|
|
|
|
"Quit" : InputMap.get_action_list("quit")[0].get_scancode_with_modifiers(),
|
2019-08-18 09:28:38 +00:00
|
|
|
}
|
2020-05-23 21:22:06 +00:00
|
|
|
file_menu = Global.file_menu.get_popup()
|
|
|
|
var i := 0
|
|
|
|
|
|
|
|
for item in file_menu_items.keys():
|
|
|
|
file_menu.add_item(item, i, file_menu_items[item])
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
file_menu.connect("id_pressed", self, "file_menu_id_pressed")
|
|
|
|
|
|
|
|
|
|
|
|
func setup_edit_menu() -> void:
|
2019-09-03 19:51:14 +00:00
|
|
|
var edit_menu_items := {
|
2020-04-07 22:56:05 +00:00
|
|
|
"Undo" : InputMap.get_action_list("undo")[0].get_scancode_with_modifiers(),
|
|
|
|
"Redo" : InputMap.get_action_list("redo")[0].get_scancode_with_modifiers(),
|
2019-12-10 23:00:26 +00:00
|
|
|
"Clear Selection" : 0,
|
|
|
|
"Preferences" : 0
|
2019-09-03 19:51:14 +00:00
|
|
|
}
|
2020-05-23 21:22:06 +00:00
|
|
|
var edit_menu : PopupMenu = Global.edit_menu.get_popup()
|
|
|
|
var i := 0
|
|
|
|
|
|
|
|
for item in edit_menu_items.keys():
|
|
|
|
edit_menu.add_item(item, i, edit_menu_items[item])
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
edit_menu.connect("id_pressed", self, "edit_menu_id_pressed")
|
|
|
|
|
|
|
|
|
|
|
|
func setup_view_menu() -> void:
|
2019-09-18 21:10:23 +00:00
|
|
|
var view_menu_items := {
|
2020-04-07 22:56:05 +00:00
|
|
|
"Tile Mode" : InputMap.get_action_list("tile_mode")[0].get_scancode_with_modifiers(),
|
|
|
|
"Show Grid" : InputMap.get_action_list("show_grid")[0].get_scancode_with_modifiers(),
|
|
|
|
"Show Rulers" : InputMap.get_action_list("show_rulers")[0].get_scancode_with_modifiers(),
|
|
|
|
"Show Guides" : InputMap.get_action_list("show_guides")[0].get_scancode_with_modifiers(),
|
2020-02-15 01:30:40 +00:00
|
|
|
"Show Animation Timeline" : 0
|
2019-09-25 19:59:48 +00:00
|
|
|
}
|
2020-05-23 21:22:06 +00:00
|
|
|
view_menu = Global.view_menu.get_popup()
|
|
|
|
|
|
|
|
var i := 0
|
|
|
|
for item in view_menu_items.keys():
|
|
|
|
view_menu.add_check_item(item, i, view_menu_items[item])
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
view_menu.set_item_checked(2, true) # Show Rulers
|
|
|
|
view_menu.set_item_checked(3, true) # Show Guides
|
|
|
|
view_menu.set_item_checked(4, true) # Show Animation Timeline
|
|
|
|
view_menu.hide_on_checkable_item_selection = false
|
|
|
|
view_menu.connect("id_pressed", self, "view_menu_id_pressed")
|
|
|
|
|
|
|
|
|
|
|
|
func setup_image_menu() -> void:
|
2019-12-24 14:48:07 +00:00
|
|
|
var image_menu_items := {
|
2019-12-24 23:43:21 +00:00
|
|
|
"Scale Image" : 0,
|
|
|
|
"Crop Image" : 0,
|
2020-04-07 22:56:05 +00:00
|
|
|
"Flip Horizontal" : InputMap.get_action_list("image_flip_horizontal")[0].get_scancode_with_modifiers(),
|
|
|
|
"Flip Vertical" : InputMap.get_action_list("image_flip_vertical")[0].get_scancode_with_modifiers(),
|
2020-02-04 16:29:34 +00:00
|
|
|
"Rotate Image" : 0,
|
2019-12-31 18:10:10 +00:00
|
|
|
"Invert colors" : 0,
|
2019-12-27 22:57:28 +00:00
|
|
|
"Desaturation" : 0,
|
2020-04-13 14:10:17 +00:00
|
|
|
"Outline" : 0,
|
2020-04-15 16:54:59 +00:00
|
|
|
"Adjust Hue/Saturation/Value" : 0
|
2019-12-24 14:48:07 +00:00
|
|
|
}
|
2020-05-23 21:22:06 +00:00
|
|
|
var image_menu : PopupMenu = Global.image_menu.get_popup()
|
|
|
|
|
|
|
|
var i := 0
|
|
|
|
for item in image_menu_items.keys():
|
|
|
|
image_menu.add_item(item, i, image_menu_items[item])
|
|
|
|
if i == 4:
|
|
|
|
image_menu.add_separator()
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
image_menu.connect("id_pressed", self, "image_menu_id_pressed")
|
|
|
|
|
|
|
|
|
|
|
|
func setup_help_menu() -> void:
|
2019-09-25 19:59:48 +00:00
|
|
|
var help_menu_items := {
|
2019-12-31 16:36:57 +00:00
|
|
|
"View Splash Screen" : 0,
|
2020-05-09 23:00:24 +00:00
|
|
|
"Online Docs" : 0,
|
2019-12-31 12:40:44 +00:00
|
|
|
"Issue Tracker" : 0,
|
2019-12-31 16:36:57 +00:00
|
|
|
"Changelog" : 0,
|
2019-12-10 23:00:26 +00:00
|
|
|
"About Pixelorama" : 0
|
2019-09-18 21:10:23 +00:00
|
|
|
}
|
2019-09-25 19:59:48 +00:00
|
|
|
var help_menu : PopupMenu = Global.help_menu.get_popup()
|
2019-10-29 21:22:38 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
var i := 0
|
2019-09-25 19:59:48 +00:00
|
|
|
for item in help_menu_items.keys():
|
|
|
|
help_menu.add_item(item, i, help_menu_items[item])
|
|
|
|
i += 1
|
2019-10-29 21:22:38 +00:00
|
|
|
|
2019-09-25 19:59:48 +00:00
|
|
|
help_menu.connect("id_pressed", self, "help_menu_id_pressed")
|
2019-10-29 21:22:38 +00:00
|
|
|
|
2020-05-02 15:10:01 +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
|
|
|
|
yield(get_tree().create_timer(0.01), "timeout")
|
2020-02-18 23:13:29 +00:00
|
|
|
if Global.config_cache.get_value("preferences", "startup"):
|
|
|
|
$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
|
|
|
|
$BackupConfirmation.get_cancel().text = tr("Delete")
|
|
|
|
if Global.config_cache.has_section("backups"):
|
|
|
|
var project_paths = Global.config_cache.get_section_keys("backups")
|
|
|
|
if project_paths.size() > 0:
|
|
|
|
# Get backup path
|
|
|
|
var backup_path = Global.config_cache.get_value("backups", project_paths[0])
|
|
|
|
# Temporatily stop autosave until user confirms backup
|
|
|
|
OpenSave.autosave_timer.stop()
|
|
|
|
# For it's only possible to reload the first found backup
|
2020-05-05 11:45:16 +00:00
|
|
|
$BackupConfirmation.dialog_text = tr($BackupConfirmation.dialog_text) % project_paths[0]
|
2020-04-30 17:33:24 +00:00
|
|
|
$BackupConfirmation.connect("confirmed", self, "_on_BackupConfirmation_confirmed", [project_paths[0], backup_path])
|
|
|
|
$BackupConfirmation.get_cancel().connect("pressed", self, "_on_BackupConfirmation_delete", [project_paths[0], backup_path])
|
|
|
|
$BackupConfirmation.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
|
|
|
|
|
|
|
func handle_running_pixelorama_with_arguments() -> void:
|
|
|
|
# If user want to run Pixelorama with arguments in terminal mode then handle that
|
2020-05-03 18:45:05 +00:00
|
|
|
if OS.get_cmdline_args():
|
|
|
|
for arg in OS.get_cmdline_args():
|
|
|
|
if arg.get_extension().to_lower() == "pxo":
|
|
|
|
_on_OpenSprite_file_selected(arg)
|
|
|
|
else:
|
|
|
|
if arg == OS.get_cmdline_args()[0]:
|
|
|
|
$ImportSprites.new_frame = false
|
|
|
|
$ImportSprites._on_ImportSprites_files_selected([arg])
|
|
|
|
$ImportSprites.new_frame = true
|
|
|
|
|
2020-04-30 17:33:24 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
func _notification(what : int) -> void:
|
|
|
|
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit
|
|
|
|
show_quit_dialog()
|
2020-03-14 19:40:10 +00:00
|
|
|
|
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
func on_new_project_file_menu_option_pressed(id : int) -> void:
|
|
|
|
if Global.project_has_changed:
|
|
|
|
unsaved_canvas_state = id
|
|
|
|
$UnsavedCanvasDialog.popup_centered()
|
|
|
|
else:
|
|
|
|
$CreateNewImage.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
2019-11-19 21:33:37 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
|
|
|
|
func open_project_file() -> void:
|
|
|
|
$OpenSprite.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
opensprite_file_selected = false
|
2019-12-19 15:07:26 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
func on_open_last_project_file_menu_option_pressed(id : int) -> void:
|
|
|
|
# Check if last project path is set and if yes then open
|
|
|
|
if Global.config_cache.has_section_key("preferences", "last_project_path"):
|
|
|
|
if Global.project_has_changed:
|
|
|
|
unsaved_canvas_state = id
|
|
|
|
$UnsavedCanvasDialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
else:
|
|
|
|
load_last_project()
|
|
|
|
else: # if not then warn user that he didn't edit any project yet
|
|
|
|
Global.error_dialog.set_text("You haven't saved or opened any project in Pixelorama yet!")
|
|
|
|
Global.error_dialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
|
|
|
func save_project_file() -> void:
|
|
|
|
is_quitting_on_save = false
|
|
|
|
if OpenSave.current_save_path == "":
|
|
|
|
$SaveSprite.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
else:
|
|
|
|
_on_SaveSprite_file_selected(OpenSave.current_save_path)
|
|
|
|
|
|
|
|
|
|
|
|
func save_project_file_as() -> void:
|
|
|
|
is_quitting_on_save = false
|
|
|
|
$SaveSprite.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
|
|
|
func import_file() -> void:
|
|
|
|
$ImportSprites.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
opensprite_file_selected = false
|
|
|
|
|
|
|
|
|
|
|
|
func export_file() -> void:
|
|
|
|
if $ExportDialog.was_exported == false:
|
|
|
|
$ExportDialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
else:
|
|
|
|
$ExportDialog.external_export()
|
2019-12-04 17:16:18 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-08-18 09:28:38 +00:00
|
|
|
func file_menu_id_pressed(id : int) -> void:
|
|
|
|
match id:
|
2019-12-24 14:48:07 +00:00
|
|
|
0: # New
|
2020-05-23 21:22:06 +00:00
|
|
|
on_new_project_file_menu_option_pressed(id)
|
2019-12-24 14:48:07 +00:00
|
|
|
1: # Open
|
2020-05-23 21:22:06 +00:00
|
|
|
open_project_file()
|
2020-04-21 17:45:02 +00:00
|
|
|
2: # Open last project
|
2020-05-23 21:22:06 +00:00
|
|
|
on_open_last_project_file_menu_option_pressed(id)
|
2020-04-21 17:45:02 +00:00
|
|
|
3: # Save
|
2020-05-23 21:22:06 +00:00
|
|
|
save_project_file()
|
2020-04-21 17:45:02 +00:00
|
|
|
4: # Save as
|
2020-05-23 21:22:06 +00:00
|
|
|
save_project_file_as()
|
2020-04-21 17:45:02 +00:00
|
|
|
5: # Import
|
2020-05-23 21:22:06 +00:00
|
|
|
import_file()
|
2020-04-21 17:45:02 +00:00
|
|
|
6: # Export
|
2020-05-23 21:22:06 +00:00
|
|
|
export_file()
|
2020-04-21 17:45:02 +00:00
|
|
|
7: # Export as
|
2020-03-23 22:09:37 +00:00
|
|
|
$ExportDialog.popup_centered()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-04-21 17:45:02 +00:00
|
|
|
8: # Quit
|
2020-02-23 00:11:52 +00:00
|
|
|
show_quit_dialog()
|
2019-08-18 09:28:38 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-09-03 19:51:14 +00:00
|
|
|
func edit_menu_id_pressed(id : int) -> void:
|
|
|
|
match id:
|
2019-12-24 14:48:07 +00:00
|
|
|
0: # Undo
|
2019-11-04 17:12:35 +00:00
|
|
|
Global.undo_redo.undo()
|
2019-12-24 14:48:07 +00:00
|
|
|
1: # Redo
|
2019-11-13 13:45:55 +00:00
|
|
|
redone = true
|
2019-11-04 17:12:35 +00:00
|
|
|
Global.undo_redo.redo()
|
2019-11-13 13:45:55 +00:00
|
|
|
redone = false
|
2019-12-24 23:43:21 +00:00
|
|
|
2: # Clear selection
|
|
|
|
Global.canvas.handle_undo("Rectangle Select")
|
|
|
|
Global.selection_rectangle.polygon[0] = Vector2.ZERO
|
|
|
|
Global.selection_rectangle.polygon[1] = Vector2.ZERO
|
|
|
|
Global.selection_rectangle.polygon[2] = Vector2.ZERO
|
|
|
|
Global.selection_rectangle.polygon[3] = Vector2.ZERO
|
|
|
|
Global.selected_pixels.clear()
|
|
|
|
Global.canvas.handle_redo("Rectangle Select")
|
|
|
|
3: # Preferences
|
2020-02-07 22:10:33 +00:00
|
|
|
$PreferencesDialog.popup_centered(Vector2(400, 280))
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2019-12-24 23:43:21 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-05-23 21:22:06 +00:00
|
|
|
func toggle_tile_mode() -> void:
|
|
|
|
Global.tile_mode = !Global.tile_mode
|
|
|
|
view_menu.set_item_checked(0, Global.tile_mode)
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_show_grid() -> void:
|
|
|
|
Global.draw_grid = !Global.draw_grid
|
|
|
|
view_menu.set_item_checked(1, Global.draw_grid)
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_show_rulers() -> void:
|
|
|
|
Global.show_rulers = !Global.show_rulers
|
|
|
|
view_menu.set_item_checked(2, Global.show_rulers)
|
|
|
|
Global.horizontal_ruler.visible = Global.show_rulers
|
|
|
|
Global.vertical_ruler.visible = Global.show_rulers
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_show_guides() -> void:
|
|
|
|
Global.show_guides = !Global.show_guides
|
|
|
|
view_menu.set_item_checked(3, Global.show_guides)
|
|
|
|
for canvas in Global.canvases:
|
|
|
|
for guide in canvas.get_children():
|
|
|
|
if guide is Guide:
|
|
|
|
guide.visible = Global.show_guides
|
|
|
|
|
|
|
|
|
|
|
|
func toggle_show_anim_timeline() -> void:
|
|
|
|
Global.show_animation_timeline = !Global.show_animation_timeline
|
|
|
|
view_menu.set_item_checked(4, Global.show_animation_timeline)
|
|
|
|
Global.animation_timeline.visible = Global.show_animation_timeline
|
|
|
|
|
|
|
|
|
2019-12-24 23:43:21 +00:00
|
|
|
func view_menu_id_pressed(id : int) -> void:
|
|
|
|
match id:
|
|
|
|
0: # Tile mode
|
2020-05-23 21:22:06 +00:00
|
|
|
toggle_tile_mode()
|
2019-12-24 23:43:21 +00:00
|
|
|
1: # Show grid
|
2020-05-23 21:22:06 +00:00
|
|
|
toggle_show_grid()
|
2019-12-24 23:43:21 +00:00
|
|
|
2: # Show rulers
|
2020-05-23 21:22:06 +00:00
|
|
|
toggle_show_rulers()
|
2019-12-24 23:43:21 +00:00
|
|
|
3: # Show guides
|
2020-05-23 21:22:06 +00:00
|
|
|
toggle_show_guides()
|
2020-02-15 01:30:40 +00:00
|
|
|
4: # Show animation timeline
|
2020-05-23 21:22:06 +00:00
|
|
|
toggle_show_anim_timeline()
|
2019-12-24 23:43:21 +00:00
|
|
|
|
2019-12-27 22:57:28 +00:00
|
|
|
Global.canvas.update()
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-05-22 12:05:55 +00:00
|
|
|
func show_scale_image_popup() -> void:
|
|
|
|
$ScaleImage.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
|
|
|
func crop_image() -> void:
|
|
|
|
# Use first cel as a starting rectangle
|
|
|
|
var used_rect : Rect2 = Global.canvases[0].layers[0][0].get_used_rect()
|
|
|
|
|
|
|
|
for c in Global.canvases:
|
|
|
|
# However, if first cel is empty, loop through all cels until we find one that isn't
|
|
|
|
for layer in c.layers:
|
|
|
|
if used_rect != Rect2(0, 0, 0, 0):
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
if layer[0].get_used_rect() != Rect2(0, 0, 0, 0):
|
|
|
|
used_rect = layer[0].get_used_rect()
|
|
|
|
|
|
|
|
# Merge all layers with content
|
|
|
|
for layer in c.layers:
|
|
|
|
if layer[0].get_used_rect() != Rect2(0, 0, 0, 0):
|
|
|
|
used_rect = used_rect.merge(layer[0].get_used_rect())
|
|
|
|
|
|
|
|
# If no layer has any content, just return
|
|
|
|
if used_rect == Rect2(0, 0, 0, 0):
|
|
|
|
return
|
|
|
|
|
|
|
|
var width := used_rect.size.x
|
|
|
|
var height := used_rect.size.y
|
|
|
|
Global.undos += 1
|
|
|
|
Global.undo_redo.create_action("Scale")
|
|
|
|
for c in Global.canvases:
|
|
|
|
Global.undo_redo.add_do_property(c, "size", Vector2(width, height).floor())
|
|
|
|
# Loop through all the layers to crop them
|
|
|
|
for j in range(Global.canvas.layers.size() - 1, -1, -1):
|
|
|
|
var sprite : Image = c.layers[j][0].get_rect(used_rect)
|
|
|
|
Global.undo_redo.add_do_property(c.layers[j][0], "data", sprite.data)
|
|
|
|
Global.undo_redo.add_undo_property(c.layers[j][0], "data", c.layers[j][0].data)
|
|
|
|
|
|
|
|
Global.undo_redo.add_undo_property(c, "size", c.size)
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo", Global.canvases)
|
|
|
|
Global.undo_redo.add_do_method(Global, "redo", Global.canvases)
|
|
|
|
Global.undo_redo.commit_action()
|
|
|
|
|
|
|
|
|
|
|
|
func flip_image_horizontal() -> void:
|
|
|
|
var canvas : Canvas = Global.canvas
|
|
|
|
canvas.handle_undo("Draw")
|
|
|
|
canvas.layers[Global.current_layer][0].unlock()
|
|
|
|
canvas.layers[Global.current_layer][0].flip_x()
|
|
|
|
canvas.layers[Global.current_layer][0].lock()
|
|
|
|
canvas.handle_redo("Draw")
|
|
|
|
|
|
|
|
|
|
|
|
func flip_image_vertical() -> void:
|
|
|
|
var canvas : Canvas = Global.canvas
|
|
|
|
canvas.handle_undo("Draw")
|
|
|
|
canvas.layers[Global.current_layer][0].unlock()
|
|
|
|
canvas.layers[Global.current_layer][0].flip_y()
|
|
|
|
canvas.layers[Global.current_layer][0].lock()
|
|
|
|
canvas.handle_redo("Draw")
|
|
|
|
|
|
|
|
|
|
|
|
func show_rotate_image_popup() -> void:
|
|
|
|
var image : Image = Global.canvas.layers[Global.current_layer][0]
|
|
|
|
$RotateImage.set_sprite(image)
|
|
|
|
$RotateImage.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
|
|
|
func invert_image_colors() -> void:
|
|
|
|
var image : Image = Global.canvas.layers[Global.current_layer][0]
|
|
|
|
Global.canvas.handle_undo("Draw")
|
|
|
|
for xx in image.get_size().x:
|
|
|
|
for yy in image.get_size().y:
|
|
|
|
var px_color = image.get_pixel(xx, yy).inverted()
|
|
|
|
if px_color.a == 0:
|
|
|
|
continue
|
|
|
|
image.set_pixel(xx, yy, px_color)
|
|
|
|
Global.canvas.handle_redo("Draw")
|
|
|
|
|
|
|
|
|
|
|
|
func desaturate_image() -> void:
|
|
|
|
var image : Image = Global.canvas.layers[Global.current_layer][0]
|
|
|
|
Global.canvas.handle_undo("Draw")
|
|
|
|
for xx in image.get_size().x:
|
|
|
|
for yy in image.get_size().y:
|
|
|
|
var px_color = image.get_pixel(xx, yy)
|
|
|
|
if px_color.a == 0:
|
|
|
|
continue
|
|
|
|
var gray = image.get_pixel(xx, yy).v
|
|
|
|
px_color = Color(gray, gray, gray, px_color.a)
|
|
|
|
image.set_pixel(xx, yy, px_color)
|
|
|
|
Global.canvas.handle_redo("Draw")
|
|
|
|
|
|
|
|
|
|
|
|
func show_add_outline_popup() -> void:
|
|
|
|
$OutlineDialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
|
|
|
func show_hsv_configuration_popup() -> void:
|
|
|
|
$HSVDialog.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
|
|
|
|
|
2019-12-24 23:43:21 +00:00
|
|
|
func image_menu_id_pressed(id : int) -> void:
|
2020-03-09 23:42:50 +00:00
|
|
|
if Global.layers[Global.current_layer][2]: # No changes if the layer is locked
|
|
|
|
return
|
2019-12-24 23:43:21 +00:00
|
|
|
match id:
|
|
|
|
0: # Scale Image
|
2020-05-22 12:05:55 +00:00
|
|
|
show_scale_image_popup()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2019-12-24 23:43:21 +00:00
|
|
|
1: # Crop Image
|
2020-05-22 12:05:55 +00:00
|
|
|
crop_image()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2019-12-24 23:43:21 +00:00
|
|
|
2: # Flip Horizontal
|
2020-05-22 12:05:55 +00:00
|
|
|
flip_image_horizontal()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2019-12-24 23:43:21 +00:00
|
|
|
3: # Flip Vertical
|
2020-05-22 12:05:55 +00:00
|
|
|
flip_image_vertical()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2020-02-04 16:29:34 +00:00
|
|
|
4: # Rotate
|
2020-05-22 12:05:55 +00:00
|
|
|
show_rotate_image_popup()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2020-02-04 16:29:34 +00:00
|
|
|
5: # Invert Colors
|
2020-05-22 12:05:55 +00:00
|
|
|
invert_image_colors()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2020-02-04 16:29:34 +00:00
|
|
|
6: # Desaturation
|
2020-05-22 12:05:55 +00:00
|
|
|
desaturate_image()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2020-02-04 16:29:34 +00:00
|
|
|
7: # Outline
|
2020-05-22 12:05:55 +00:00
|
|
|
show_add_outline_popup()
|
2020-05-11 15:41:41 +00:00
|
|
|
|
2020-04-13 14:10:17 +00:00
|
|
|
8: # HSV
|
2020-05-22 12:05:55 +00:00
|
|
|
show_hsv_configuration_popup()
|
2019-12-24 14:48:07 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2019-09-25 19:59:48 +00:00
|
|
|
func help_menu_id_pressed(id : int) -> void:
|
|
|
|
match id:
|
2019-12-31 16:36:57 +00:00
|
|
|
0: # Splash Screen
|
2020-03-09 00:17:49 +00:00
|
|
|
$SplashDialog.popup_centered()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-05-09 23:00:24 +00:00
|
|
|
1: # Online Docs
|
|
|
|
OS.shell_open("https://orama-interactive.github.io/Pixelorama-Docs/")
|
|
|
|
2: # Issue Tracker
|
2019-12-31 12:40:44 +00:00
|
|
|
OS.shell_open("https://github.com/Orama-Interactive/Pixelorama/issues")
|
2020-05-09 23:00:24 +00:00
|
|
|
3: # Changelog
|
2020-05-15 17:49:48 +00:00
|
|
|
OS.shell_open("https://github.com/Orama-Interactive/Pixelorama/blob/master/CHANGELOG.md#v07---2020-05-16")
|
2020-05-09 23:00:24 +00:00
|
|
|
4: # About Pixelorama
|
2019-09-25 19:59:48 +00:00
|
|
|
$AboutDialog.popup_centered()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2019-09-25 19:59:48 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-04-30 21:02:52 +00:00
|
|
|
func load_last_project() -> void:
|
|
|
|
# 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
|
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
|
|
|
|
|
|
|
func _on_UnsavedCanvasDialog_confirmed() -> void:
|
2020-05-01 16:40:36 +00:00
|
|
|
if unsaved_canvas_state == 0: # New image
|
|
|
|
$CreateNewImage.popup_centered()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-05-01 16:40:36 +00:00
|
|
|
elif unsaved_canvas_state == 2: # Open last project
|
|
|
|
load_last_project()
|
2020-04-02 12:28:47 +00:00
|
|
|
|
|
|
|
|
2019-11-21 19:13:15 +00:00
|
|
|
func _on_OpenSprite_file_selected(path : String) -> void:
|
2020-04-09 20:54:05 +00:00
|
|
|
OpenSave.open_pxo_file(path)
|
2019-11-10 01:25:25 +00:00
|
|
|
|
2020-02-16 16:18:12 +00:00
|
|
|
$SaveSprite.current_path = path
|
2020-04-21 17:45:02 +00:00
|
|
|
# Set last opened project path and save
|
|
|
|
Global.config_cache.set_value("preferences", "last_project_path", path)
|
|
|
|
Global.config_cache.save("user://cache.ini")
|
2020-03-23 22:09:37 +00:00
|
|
|
$ExportDialog.file_name = path.get_file().trim_suffix(".pxo")
|
|
|
|
$ExportDialog.directory_path = path.get_base_dir()
|
|
|
|
$ExportDialog.was_exported = false
|
2020-04-21 17:45:02 +00:00
|
|
|
file_menu.set_item_text(3, tr("Save") + " %s" % path.get_file())
|
|
|
|
file_menu.set_item_text(6, tr("Export"))
|
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-04-30 17:33:24 +00:00
|
|
|
OpenSave.save_pxo_file(path, false)
|
2020-04-09 20:54:05 +00:00
|
|
|
|
2020-04-21 17:45:02 +00:00
|
|
|
# Set last opened project path and save
|
|
|
|
Global.config_cache.set_value("preferences", "last_project_path", path)
|
|
|
|
Global.config_cache.save("user://cache.ini")
|
2020-03-23 22:09:37 +00:00
|
|
|
$ExportDialog.file_name = path.get_file().trim_suffix(".pxo")
|
|
|
|
$ExportDialog.directory_path = path.get_base_dir()
|
|
|
|
$ExportDialog.was_exported = false
|
2020-04-21 17:45:02 +00:00
|
|
|
file_menu.set_item_text(3, tr("Save") + " %s" % path.get_file())
|
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
|
|
|
|
|
|
|
|
|
|
|
func _on_ImportSprites_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:
|
|
|
|
if !$QuitDialog.visible:
|
2020-05-01 16:40:36 +00:00
|
|
|
if !Global.project_has_changed:
|
2020-02-23 00:11:52 +00:00
|
|
|
$QuitDialog.call_deferred("popup_centered")
|
|
|
|
else:
|
|
|
|
$QuitAndSaveDialog.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-02-22 15:02:56 +00:00
|
|
|
$SaveSprite.popup_centered()
|
2020-02-22 15:14:32 +00:00
|
|
|
$QuitDialog.hide()
|
2020-05-08 15:37:45 +00:00
|
|
|
Global.dialog_open(true)
|
2020-04-30 17:33:24 +00:00
|
|
|
OpenSave.remove_backup()
|
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)
|
2020-04-30 17:33:24 +00:00
|
|
|
OpenSave.remove_backup()
|
2020-02-22 22:52:51 +00:00
|
|
|
get_tree().quit()
|
2020-04-27 15:09:54 +00:00
|
|
|
|
|
|
|
|
2020-04-30 17:33:24 +00:00
|
|
|
func _on_BackupConfirmation_confirmed(project_path : String, backup_path : String) -> void:
|
|
|
|
OpenSave.reload_backup_file(project_path, backup_path)
|
|
|
|
OpenSave.autosave_timer.start()
|
|
|
|
$ExportDialog.file_name = OpenSave.current_save_path.get_file().trim_suffix(".pxo")
|
|
|
|
$ExportDialog.directory_path = OpenSave.current_save_path.get_base_dir()
|
|
|
|
$ExportDialog.was_exported = false
|
|
|
|
file_menu.set_item_text(3, tr("Save") + " %s" % OpenSave.current_save_path.get_file())
|
|
|
|
file_menu.set_item_text(6, tr("Export"))
|
|
|
|
|
|
|
|
|
|
|
|
func _on_BackupConfirmation_delete(project_path : String, backup_path : String) -> void:
|
|
|
|
OpenSave.remove_backup_by_path(project_path, backup_path)
|
|
|
|
OpenSave.autosave_timer.start()
|
|
|
|
# Reopen last project
|
2020-04-30 21:02:52 +00:00
|
|
|
if Global.open_last_project:
|
|
|
|
load_last_project()
|