mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-19 01:29:49 +00:00
Spritesheet layer improvements (#623)
* Drastically changed an old func() "open_image_as_spritesheet_layer" (Hope i didn't break anything...) * removed whitespace * some minor changes spritesheet "Start frame" no longer restricted to existing frames number and a minor UI change * solved some format errors
This commit is contained in:
parent
311f4dd70b
commit
bbc56e253e
|
@ -414,11 +414,34 @@ func open_image_as_spritesheet_layer(
|
|||
var frame_height := image.get_size().y / vertical
|
||||
|
||||
# resize canvas to if "frame_width" or "frame_height" is too large
|
||||
var project_width: int = max(frame_width, Global.current_project.size.x)
|
||||
var project_height: int = max(frame_height, Global.current_project.size.y)
|
||||
DrawingAlgos.resize_canvas(project_width, project_height, 0, 0)
|
||||
var project: Project = Global.current_project
|
||||
var project_width: int = max(frame_width, project.size.x)
|
||||
var project_height: int = max(frame_height, project.size.y)
|
||||
if project.size < Vector2(project_width, project_height):
|
||||
DrawingAlgos.resize_canvas(project_width, project_height, 0, 0)
|
||||
|
||||
# slice images
|
||||
#initialize undo mechanism
|
||||
project.undos += 1
|
||||
project.undo_redo.create_action("Add Spritesheet Layer")
|
||||
var new_layers: Array = project.layers.duplicate()
|
||||
var new_frames: Array = project.frames.duplicate()
|
||||
|
||||
#Create new frames (if needed)
|
||||
var new_frames_size = start_frame + (vertical * horizontal)
|
||||
if new_frames_size > project.frames.size():
|
||||
var required_frames = new_frames_size - project.frames.size()
|
||||
for i in required_frames:
|
||||
var frame: Frame = project.new_empty_frame()
|
||||
new_frames.insert(project.current_frame + 1, frame)
|
||||
#Create new layer for spritesheet
|
||||
var layer := Layer.new(file_name)
|
||||
new_layers.append(layer)
|
||||
for f in new_frames:
|
||||
var new_layer := Image.new()
|
||||
new_layer.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)
|
||||
f.cels.append(Cel.new(new_layer, 1))
|
||||
|
||||
# slice spritesheet
|
||||
var image_no: int = 0
|
||||
for yy in range(vertical):
|
||||
for xx in range(horizontal):
|
||||
|
@ -426,21 +449,28 @@ func open_image_as_spritesheet_layer(
|
|||
cropped_image = image.get_rect(
|
||||
Rect2(frame_width * xx, frame_height * yy, frame_width, frame_height)
|
||||
)
|
||||
if (start_frame + (image_no)) < Global.current_project.frames.size():
|
||||
# if frames are already present then fill those first
|
||||
if image_no == 0:
|
||||
open_image_as_new_layer(cropped_image, file_name, start_frame + image_no)
|
||||
else:
|
||||
open_image_at_frame(
|
||||
cropped_image,
|
||||
Global.current_project.layers.size() - 1,
|
||||
start_frame + image_no
|
||||
)
|
||||
else:
|
||||
# if no more frames are present then start making new frames
|
||||
open_image_as_new_frame(cropped_image, Global.current_project.layers.size() - 1)
|
||||
cropped_image.crop(project.size.x, project.size.y)
|
||||
var layer_index = new_layers.size() - 1
|
||||
var frame_index = start_frame + image_no
|
||||
|
||||
for i in new_frames.size():
|
||||
if i == frame_index:
|
||||
cropped_image.convert(Image.FORMAT_RGBA8)
|
||||
new_frames[i].cels[layer_index] = (Cel.new(cropped_image, 1))
|
||||
image_no += 1
|
||||
|
||||
project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1)
|
||||
project.undo_redo.add_do_property(project, "current_layer", project.layers.size())
|
||||
project.undo_redo.add_do_property(project, "layers", new_layers)
|
||||
project.undo_redo.add_do_property(project, "frames", new_frames)
|
||||
project.undo_redo.add_undo_property(project, "current_layer", project.current_layer)
|
||||
project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
|
||||
project.undo_redo.add_undo_property(project, "layers", project.layers)
|
||||
project.undo_redo.add_undo_property(project, "frames", project.frames)
|
||||
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
||||
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
||||
project.undo_redo.commit_action()
|
||||
|
||||
|
||||
func open_image_at_frame(image: Image, layer_index := 0, frame_index := 0) -> void:
|
||||
var project = Global.current_project
|
||||
|
|
|
@ -156,8 +156,6 @@ func _on_ImportOption_item_selected(id: int) -> void:
|
|||
frame_size_label.visible = true
|
||||
spritesheet_tab_options.visible = true
|
||||
spritesheet_layer_options.visible = true
|
||||
var n_of_frames: int = Global.current_project.frames.size()
|
||||
spritesheet_layer_options.get_node("AtFrameSpinbox").max_value = n_of_frames
|
||||
texture_rect.get_child(0).visible = true
|
||||
texture_rect.get_child(1).visible = true
|
||||
rect_size.x = spritesheet_layer_options.rect_size.x
|
||||
|
|
|
@ -28,6 +28,7 @@ __meta__ = {
|
|||
[node name="CenterContainer" type="CenterContainer" parent="VBoxContainer"]
|
||||
margin_right = 534.0
|
||||
margin_bottom = 300.0
|
||||
size_flags_vertical = 3
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
@ -44,6 +45,9 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="HorizLines" type="Control" parent="VBoxContainer/CenterContainer/TextureRect"]
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="VerticalLines" type="Control" parent="VBoxContainer/CenterContainer/TextureRect"]
|
||||
|
||||
|
@ -249,6 +253,7 @@ text = "Brush name:"
|
|||
margin_left = 85.0
|
||||
margin_right = 143.0
|
||||
margin_bottom = 24.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"]
|
||||
|
|
Loading…
Reference in a new issue