1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-20 12:33:14 +00:00

Removed Import option from the file menu

The "Open" option will handle importing of .pxo files and image files from now on. The "ImportSprites" file dialog node and script are scheduled to be deleted too. Importing spritesheets option will return soon. Next thing I'm going to work on is a preview window that will appear when importing image files.
This commit is contained in:
OverloadedOrama 2020-06-12 01:11:58 +03:00
parent e94e57ea09
commit 2371238ec0
6 changed files with 71 additions and 57 deletions

View file

@ -287,11 +287,6 @@ save_file_as={
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":true,"control":true,"meta":false,"command":true,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
]
}
import_file={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":73,"unicode":0,"echo":false,"script":null)
]
}
export_file={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":true,"meta":false,"command":true,"pressed":false,"scancode":69,"unicode":0,"echo":false,"script":null)

View file

@ -151,7 +151,6 @@ var zoom_level_label : Label
var open_sprites_dialog : FileDialog
var save_sprites_dialog : FileDialog
var import_sprites_dialog : FileDialog
var export_dialog : AcceptDialog
var preferences_dialog : AcceptDialog
var unsaved_changes_dialog : ConfirmationDialog
@ -270,7 +269,6 @@ func _ready() -> void:
open_sprites_dialog = find_node_by_name(root, "OpenSprite")
save_sprites_dialog = find_node_by_name(root, "SaveSprite")
import_sprites_dialog = find_node_by_name(root, "ImportSprites")
export_dialog = find_node_by_name(root, "ExportDialog")
preferences_dialog = find_node_by_name(root, "PreferencesDialog")
unsaved_changes_dialog = find_node_by_name(root, "UnsavedCanvasDialog")

View file

@ -16,6 +16,14 @@ func _ready() -> void:
update_autosave()
func handle_loading_files(files : PoolStringArray) -> void:
for file in files:
if file.get_extension().to_lower() == "pxo":
open_pxo_file(file)
else:
open_image_file(file)
func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
var file := File.new()
var err := file.open_compressed(path, File.READ, File.COMPRESSION_ZSTD)
@ -78,6 +86,15 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
# Untitled backup should not change window title and save path
current_save_paths[Global.current_project_index] = path
Global.window_title = path.get_file() + " - Pixelorama " + Global.current_version
Global.save_sprites_dialog.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")
Global.export_dialog.file_name = path.get_file().trim_suffix(".pxo")
Global.export_dialog.directory_path = path.get_base_dir()
Global.export_dialog.was_exported = false
Global.control.file_menu.set_item_text(3, tr("Save") + " %s" % path.get_file())
Global.control.file_menu.set_item_text(5, tr("Export"))
# For pxo files older than v0.8
@ -260,11 +277,53 @@ func save_pxo_file(path : String, autosave : bool, project : Project = Global.cu
Global.notification_label("File saved")
Global.window_title = path.get_file() + " - Pixelorama " + Global.current_version
# Set last opened project path and save
Global.config_cache.set_value("preferences", "last_project_path", path)
Global.config_cache.save("user://cache.ini")
Global.export_dialog.file_name = path.get_file().trim_suffix(".pxo")
Global.export_dialog.directory_path = path.get_base_dir()
Global.export_dialog.was_exported = false
Global.control.file_menu.set_item_text(3, tr("Save") + " %s" % path.get_file())
else:
Global.notification_label("File failed to save")
file.close()
func open_image_file(path : String) -> void:
var project := Global.current_project
var image := Image.new()
var err := image.load(path)
if err != OK: # An error occured
var file_name : String = path.get_file()
Global.error_dialog.set_text(tr("Can't load file '%s'.\nError code: %s") % [file_name, str(err)])
Global.error_dialog.popup_centered()
Global.dialog_open(true)
return
project = Project.new([], path.get_file())
project.layers.append(Layer.new())
Global.projects.append(project)
project.size = image.get_size()
var frame := Frame.new()
image.convert(Image.FORMAT_RGBA8)
image.lock()
frame.cels.append(Cel.new(image, 1))
project.frames.append(frame)
Global.tabs.current_tab = Global.tabs.get_tab_count() - 1
Global.canvas.camera_zoom()
Global.window_title = path.get_file() + " (" + tr("imported") + ") - Pixelorama " + Global.current_version
if project.has_changed:
Global.window_title = Global.window_title + "(*)"
var file_name := path.get_basename().get_file()
var directory_path := path.get_basename().replace(file_name, "")
Global.export_dialog.directory_path = directory_path
Global.export_dialog.file_name = file_name
func update_autosave() -> void:
autosave_timer.stop()
autosave_timer.wait_time = Global.autosave_interval * 60 # Interval parameter is in minutes, wait_time is seconds

View file

@ -43,7 +43,7 @@ func _ready() -> void:
# 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():
handle_loading_files(OS.get_cmdline_args())
OpenSave.handle_loading_files(OS.get_cmdline_args())
get_tree().connect("files_dropped", self, "_on_files_dropped")
@ -90,7 +90,6 @@ func setup_file_menu() -> void:
'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(),
"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(),
@ -223,21 +222,13 @@ func handle_backup() -> void:
load_last_project()
func handle_loading_files(files : PoolStringArray) -> void:
for file in files:
if file.get_extension().to_lower() == "pxo":
_on_OpenSprite_file_selected(file)
else:
$ImportSprites._on_ImportSprites_files_selected([file])
func _notification(what : int) -> void:
if what == MainLoop.NOTIFICATION_WM_QUIT_REQUEST: # Handle exit
show_quit_dialog()
func _on_files_dropped(_files : PoolStringArray, _screen : int) -> void:
handle_loading_files(_files)
OpenSave.handle_loading_files(_files)
func on_new_project_file_menu_option_pressed() -> void:
@ -276,12 +267,6 @@ func save_project_file_as() -> void:
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()
@ -302,14 +287,12 @@ func file_menu_id_pressed(id : int) -> void:
save_project_file()
4: # Save as
save_project_file_as()
5: # Import
import_file()
6: # Export
5: # Export
export_file()
7: # Export as
6: # Export as
$ExportDialog.popup_centered()
Global.dialog_open(true)
8: # Quit
7: # Quit
show_quit_dialog()
@ -550,7 +533,7 @@ func load_last_project() -> void:
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)
OpenSave.open_pxo_file(file_path)
else:
# If file doesn't exist on disk then warn user about this
Global.error_dialog.set_text("Cannot find last project file.")
@ -559,35 +542,17 @@ func load_last_project() -> void:
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(3, tr("Save") + " %s" % path.get_file())
file_menu.set_item_text(6, tr("Export"))
OpenSave.handle_loading_files([path])
func _on_SaveSprite_file_selected(path : String) -> void:
OpenSave.save_pxo_file(path, false)
# 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(3, tr("Save") + " %s" % path.get_file())
if is_quitting_on_save:
_on_QuitDialog_confirmed()
func _on_ImportSprites_popup_hide() -> void:
func _on_OpenSprite_popup_hide() -> void:
if !opensprite_file_selected:
_can_draw_true()
@ -639,3 +604,4 @@ func _on_BackupConfirmation_delete(project_paths : Array, backup_paths : Array)
# Reopen last project
if Global.open_last_project:
load_last_project()

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=18 format=2]
[ext_resource path="res://assets/themes/dark/theme.tres" type="Theme" id=1]
[ext_resource path="res://src/Main.gd" type="Script" id=2]
@ -10,7 +10,6 @@
[ext_resource path="res://src/UI/Dialogs/OpenSprite.tscn" type="PackedScene" id=12]
[ext_resource path="res://src/UI/Dialogs/SplashDialog.tscn" type="PackedScene" id=27]
[ext_resource path="res://src/UI/Dialogs/CreateNewImage.tscn" type="PackedScene" id=28]
[ext_resource path="res://src/UI/Dialogs/ImportSprites.tscn" type="PackedScene" id=29]
[ext_resource path="res://src/UI/Dialogs/ScaleImage.tscn" type="PackedScene" id=31]
[ext_resource path="res://src/Preferences/PreferencesDialog.tscn" type="PackedScene" id=32]
[ext_resource path="res://src/UI/Dialogs/OutlineDialog.tscn" type="PackedScene" id=33]
@ -54,8 +53,6 @@ __meta__ = {
[node name="SaveSprite" parent="." instance=ExtResource( 11 )]
[node name="ImportSprites" parent="." instance=ExtResource( 29 )]
[node name="ExportDialog" parent="." instance=ExtResource( 39 )]
[node name="ScaleImage" parent="." instance=ExtResource( 31 )]
@ -117,10 +114,9 @@ visible = false
[connection signal="popup_hide" from="SplashDialog" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="CreateNewImage" to="." method="_can_draw_true"]
[connection signal="file_selected" from="OpenSprite" to="." method="_on_OpenSprite_file_selected"]
[connection signal="popup_hide" from="OpenSprite" to="." method="_on_ImportSprites_popup_hide"]
[connection signal="popup_hide" from="OpenSprite" to="." method="_on_OpenSprite_popup_hide"]
[connection signal="file_selected" from="SaveSprite" to="." method="_on_SaveSprite_file_selected"]
[connection signal="popup_hide" from="SaveSprite" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="ImportSprites" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="ExportDialog" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="ScaleImage" to="." method="_can_draw_true"]
[connection signal="popup_hide" from="PreferencesDialog" to="." method="_can_draw_true"]

View file

@ -7,6 +7,6 @@ window_title = "Open a File"
resizable = true
mode = 0
access = 2
filters = PoolStringArray( "*.pxo ; Pixelorama Project" )
filters = PoolStringArray( "*.pxo ; Pixelorama Project", "*.png ; PNG Image", "*.bmp ; BMP Image", "*.hdr ; Radiance HDR Image", "*.jpg,*.jpeg ; JPEG Image", "*.svg ; SVG Image", "*.tga ; TGA Image", "*.webp ; WebP Image" )
current_dir = "C:/Users"
current_path = "C:/Users/"