1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Added a preview dialog that opens every time the user imports an image file

The dialog does not appear on .pxo files. Import options will be added on it soon.
This commit is contained in:
OverloadedOrama 2020-06-13 20:58:43 +03:00
parent 7219a5a274
commit 57d4156341
3 changed files with 72 additions and 10 deletions

View file

@ -21,7 +21,20 @@ func handle_loading_files(files : PoolStringArray) -> void:
if file.get_extension().to_lower() == "pxo":
open_pxo_file(file)
else:
open_image_file(file)
var image := Image.new()
var err := image.load(file)
if err != OK: # An error occured
var file_name : String = file.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)
continue
var preview_dialog : ConfirmationDialog = preload("res://src/UI/Dialogs/PreviewDialog.tscn").instance()
preview_dialog.path = file
preview_dialog.image = image
Global.control.add_child(preview_dialog)
preview_dialog.popup_centered()
func open_pxo_file(path : String, untitled_backup : bool = false) -> void:
@ -290,16 +303,8 @@ func save_pxo_file(path : String, autosave : bool, project : Project = Global.cu
file.close()
func open_image_file(path : String) -> void:
func open_image_file(path : String, image : Image) -> 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())

View file

@ -0,0 +1,19 @@
extends ConfirmationDialog
var path : String
var image : Image
func _on_PreviewDialog_about_to_show() -> void:
var img_texture := ImageTexture.new()
img_texture.create_from_image(image)
get_node("CenterContainer/TextureRect").texture = img_texture
func _on_PreviewDialog_popup_hide() -> void:
queue_free()
func _on_PreviewDialog_confirmed() -> void:
OpenSave.open_image_file(path, image)

View file

@ -0,0 +1,38 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/PreviewDialog.gd" type="Script" id=1]
[node name="PreviewDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
rect_min_size = Vector2( 400, 70 )
popup_exclusive = true
resizable = true
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="CenterContainer" type="CenterContainer" parent="."]
anchor_right = 1.0
margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = 308.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="CenterContainer"]
margin_left = 42.0
margin_right = 342.0
margin_bottom = 300.0
rect_min_size = Vector2( 300, 300 )
expand = true
stretch_mode = 6
__meta__ = {
"_edit_use_anchors_": false
}
[connection signal="about_to_show" from="." to="." method="_on_PreviewDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_PreviewDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_PreviewDialog_popup_hide"]