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

Added options for when importing an image as a new frame or layer

The user can now choose which layer they want the new frame to be, and, similarly, which frame they want the new layer to be when importing an image.
This commit is contained in:
OverloadedOrama 2020-06-22 15:57:42 +03:00
parent 76b7014d84
commit 047561b95a
4 changed files with 90 additions and 32 deletions

View file

@ -373,53 +373,57 @@ func open_image_as_new_frame(image : Image, layer_index := 0) -> void:
new_frames.append(frame)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Frame")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.add_undo_method(Global, "undo")
project.undos += 1
project.undo_redo.create_action("Add Frame")
project.undo_redo.add_do_method(Global, "redo")
project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_property(project, "frames", new_frames)
Global.current_project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1)
Global.current_project.undo_redo.add_do_property(project, "current_layer", layer_index)
project.undo_redo.add_do_property(project, "frames", new_frames)
project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1)
project.undo_redo.add_do_property(project, "current_layer", layer_index)
Global.current_project.undo_redo.add_undo_property(project, "frames", project.frames)
Global.current_project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
Global.current_project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
Global.current_project.undo_redo.commit_action()
project.undo_redo.add_undo_property(project, "frames", project.frames)
project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
project.undo_redo.commit_action()
func open_image_as_new_layer(image : Image, file_name : String, frame_index := 0) -> void:
var project = Global.current_project
image.crop(project.size.x, project.size.y)
var new_layers : Array = Global.current_project.layers.duplicate()
var layer := Layer.new(file_name)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Layer")
for i in project.frames.size():
var new_cels : Array = project.frames[i].cels.duplicate(true)
if i == frame_index:
image.convert(Image.FORMAT_RGBA8)
image.lock()
project.frames[i].cels.append(Cel.new(image, 1))
new_cels.append(Cel.new(image, 1))
else:
var empty_image := Image.new()
empty_image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
empty_image.lock()
project.frames[i].cels.append(Cel.new(empty_image, 1))
new_cels.append(Cel.new(empty_image, 1))
project.undo_redo.add_do_property(project.frames[i], "cels", new_cels)
project.undo_redo.add_undo_property(project.frames[i], "cels", project.frames[i].cels)
new_layers.append(layer)
Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Layer")
Global.current_project.undo_redo.add_do_property(project, "current_layer", new_layers.size() - 1)
Global.current_project.undo_redo.add_do_property(project, "layers", new_layers)
Global.current_project.undo_redo.add_do_property(project, "current_frame", frame_index)
project.undo_redo.add_do_property(project, "current_layer", new_layers.size() - 1)
project.undo_redo.add_do_property(project, "layers", new_layers)
project.undo_redo.add_do_property(project, "current_frame", frame_index)
Global.current_project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
Global.current_project.undo_redo.add_undo_property(project, "layers", project.layers)
Global.current_project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
project.undo_redo.add_undo_property(project, "layers", project.layers)
project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
Global.current_project.undo_redo.add_undo_method(Global, "undo")
Global.current_project.undo_redo.add_do_method(Global, "redo")
Global.current_project.undo_redo.commit_action()
project.undo_redo.add_undo_method(Global, "undo")
project.undo_redo.add_do_method(Global, "redo")
project.undo_redo.commit_action()
func set_new_tab(project : Project, path : String) -> void:

View file

@ -9,5 +9,5 @@ func _draw() -> void:
# Draw current frame layers
for i in range(current_cels.size()):
var modulate_color := Color(1, 1, 1, current_cels[i].opacity)
if i < current_project.layers.size() and current_project.layers[i].visible: # if it's visible
if i < current_project.layers.size() and current_project.layers[i].visible:
draw_texture(current_cels[i].image_texture, Vector2.ZERO, modulate_color)

View file

@ -11,6 +11,8 @@ var spritesheet_vertical := 1
onready var texture_rect : TextureRect = $VBoxContainer/CenterContainer/TextureRect
onready var spritesheet_options = $VBoxContainer/HBoxContainer/SpritesheetOptions
onready var new_frame_options = $VBoxContainer/HBoxContainer/NewFrameOptions
onready var new_layer_options = $VBoxContainer/HBoxContainer/NewLayerOptions
func _on_PreviewDialog_about_to_show() -> void:
@ -36,23 +38,35 @@ func _on_PreviewDialog_confirmed() -> void:
elif current_import_option == ImageImportOptions.SPRITESHEET:
OpenSave.open_image_as_spritesheet(path, image, spritesheet_horizontal, spritesheet_vertical)
elif current_import_option == ImageImportOptions.NEW_FRAME:
OpenSave.open_image_as_new_frame(image)
var layer_index : int = new_frame_options.get_node("AtLayerSpinbox").value
OpenSave.open_image_as_new_frame(image, layer_index)
elif current_import_option == ImageImportOptions.NEW_LAYER:
OpenSave.open_image_as_new_layer(image, path.get_file())
var frame_index : int = new_layer_options.get_node("AtFrameSpinbox").value - 1
OpenSave.open_image_as_new_layer(image, path.get_file(), frame_index)
elif current_import_option == ImageImportOptions.PALETTE:
Global.palette_container.on_palette_import_file_selected(path)
func _on_ImportOption_item_selected(id : int) -> void:
current_import_option = id
spritesheet_options.visible = false
new_frame_options.visible = false
new_layer_options.visible = false
texture_rect.get_child(0).visible = false
texture_rect.get_child(1).visible = false
if id == ImageImportOptions.SPRITESHEET:
spritesheet_options.visible = true
texture_rect.get_child(0).visible = true
texture_rect.get_child(1).visible = true
else:
spritesheet_options.visible = false
texture_rect.get_child(0).visible = false
texture_rect.get_child(1).visible = false
elif id == ImageImportOptions.NEW_FRAME:
new_frame_options.visible = true
new_frame_options.get_node("AtLayerSpinbox").max_value = Global.current_project.layers.size() - 1
elif id == ImageImportOptions.NEW_LAYER:
new_layer_options.visible = true
new_layer_options.get_node("AtFrameSpinbox").max_value = Global.current_project.frames.size()
func _on_HorizontalFrames_value_changed(value) -> void:

View file

@ -101,6 +101,46 @@ margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
value = 1.0
[node name="NewFrameOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]
visible = false
margin_left = 155.0
margin_right = 286.0
margin_bottom = 24.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewFrameOptions"]
margin_top = 5.0
margin_right = 53.0
margin_bottom = 19.0
text = "At layer:"
[node name="AtLayerSpinbox" type="SpinBox" parent="VBoxContainer/HBoxContainer/NewFrameOptions"]
margin_left = 57.0
margin_right = 131.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
max_value = 0.0
[node name="NewLayerOptions" type="HBoxContainer" parent="VBoxContainer/HBoxContainer"]
visible = false
margin_left = 155.0
margin_right = 286.0
margin_bottom = 24.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer/NewLayerOptions"]
margin_top = 5.0
margin_right = 53.0
margin_bottom = 19.0
text = "At frame:"
[node name="AtFrameSpinbox" type="SpinBox" parent="VBoxContainer/HBoxContainer/NewLayerOptions"]
margin_left = 57.0
margin_right = 131.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 1.0
value = 1.0
[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"]