2020-01-15 20:01:43 +00:00
|
|
|
extends Panel
|
|
|
|
|
2020-03-31 15:53:26 +00:00
|
|
|
var animation_loop := 1 # 0 is no loop, 1 is cycle loop, 2 is ping-pong loop
|
2020-01-15 20:01:43 +00:00
|
|
|
var animation_forward := true
|
2020-04-19 17:39:08 +00:00
|
|
|
var first_frame := 0
|
2020-06-04 18:05:36 +00:00
|
|
|
var last_frame := 0
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-05-05 21:55:17 +00:00
|
|
|
var timeline_scroll : ScrollContainer
|
|
|
|
var tag_scroll_container : ScrollContainer
|
2020-12-17 00:20:47 +00:00
|
|
|
var fps_spinbox : SpinBox
|
2020-04-02 00:29:14 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-04-02 00:29:14 +00:00
|
|
|
func _ready() -> void:
|
2020-05-05 21:55:17 +00:00
|
|
|
timeline_scroll = Global.find_node_by_name(self, "TimelineScroll")
|
|
|
|
tag_scroll_container = Global.find_node_by_name(self, "TagScroll")
|
2020-12-17 00:20:47 +00:00
|
|
|
fps_spinbox = find_node("FPSValue")
|
2020-04-02 00:29:14 +00:00
|
|
|
timeline_scroll.get_h_scrollbar().connect("value_changed", self, "_h_scroll_changed")
|
2020-12-17 00:20:47 +00:00
|
|
|
Global.animation_timer.wait_time = 1 / Global.current_project.fps
|
2020-04-02 00:29:14 +00:00
|
|
|
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2020-04-02 00:29:14 +00:00
|
|
|
func _h_scroll_changed(value : float) -> void:
|
|
|
|
# Let the main timeline ScrollContainer affect the tag ScrollContainer too
|
|
|
|
tag_scroll_container.get_child(0).rect_min_size.x = timeline_scroll.get_child(0).rect_size.x - 212
|
|
|
|
tag_scroll_container.scroll_horizontal = value
|
|
|
|
|
2020-03-31 16:14:13 +00:00
|
|
|
|
2020-01-15 20:01:43 +00:00
|
|
|
func add_frame() -> void:
|
2020-06-02 23:14:24 +00:00
|
|
|
var frame : Frame = Global.canvas.new_empty_frame()
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_frames : Array = Global.current_project.frames.duplicate()
|
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
2020-10-19 14:57:40 +00:00
|
|
|
new_frames.insert(Global.current_project.current_frame + 1, frame)
|
2020-06-02 23:14:24 +00:00
|
|
|
# Loop through the array to create new classes for each element, so that they
|
|
|
|
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
|
|
|
for i in new_layers.size():
|
|
|
|
var new_linked_cels = new_layers[i].linked_cels.duplicate()
|
|
|
|
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
for l_i in range(new_layers.size()):
|
|
|
|
if new_layers[l_i].new_cels_linked: # If the link button is pressed
|
|
|
|
new_layers[l_i].linked_cels.append(frame)
|
|
|
|
frame.cels[l_i].image = new_layers[l_i].linked_cels[0].cels[l_i].image
|
|
|
|
frame.cels[l_i].image_texture = new_layers[l_i].linked_cels[0].cels[l_i].image_texture
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
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")
|
2020-03-04 23:53:48 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
2020-10-19 14:57:40 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", Global.current_project.current_frame + 1)
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2020-03-18 00:56:29 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
2020-10-19 14:57:40 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame )
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2020-04-17 21:35:42 +00:00
|
|
|
func _on_DeleteFrame_pressed(frame := -1) -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.frames.size() == 1:
|
2020-04-15 17:59:49 +00:00
|
|
|
return
|
2020-04-17 21:35:42 +00:00
|
|
|
if frame == -1:
|
2020-06-04 18:05:36 +00:00
|
|
|
frame = Global.current_project.current_frame
|
2020-10-20 00:27:38 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
var frame_to_delete : Frame = Global.current_project.frames[frame]
|
|
|
|
var new_frames : Array = Global.current_project.frames.duplicate()
|
2020-06-02 23:14:24 +00:00
|
|
|
new_frames.erase(frame_to_delete)
|
2020-06-04 18:05:36 +00:00
|
|
|
var current_frame := Global.current_project.current_frame
|
2020-06-02 23:14:24 +00:00
|
|
|
if current_frame > 0 && current_frame == new_frames.size(): # If it's the last frame
|
2020-04-15 17:59:49 +00:00
|
|
|
current_frame -= 1
|
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_animation_tags := Global.current_project.animation_tags.duplicate()
|
2020-06-02 02:14:05 +00:00
|
|
|
# Loop through the tags to create new classes for them, so that they won't be the same
|
2020-06-04 18:05:36 +00:00
|
|
|
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
|
2020-06-02 02:14:05 +00:00
|
|
|
for i in new_animation_tags.size():
|
|
|
|
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
|
|
|
|
|
2020-04-19 18:00:36 +00:00
|
|
|
# Loop through the tags to see if the frame is in one
|
2020-04-19 21:09:48 +00:00
|
|
|
for tag in new_animation_tags:
|
2020-06-02 02:14:05 +00:00
|
|
|
if frame + 1 >= tag.from && frame + 1 <= tag.to:
|
|
|
|
if tag.from == tag.to: # If we're deleting the only frame in the tag
|
2020-04-19 21:09:48 +00:00
|
|
|
new_animation_tags.erase(tag)
|
2020-04-19 18:00:36 +00:00
|
|
|
else:
|
2020-06-02 02:14:05 +00:00
|
|
|
tag.to -= 1
|
|
|
|
elif frame + 1 < tag.from:
|
|
|
|
tag.from -= 1
|
|
|
|
tag.to -= 1
|
2020-04-19 18:00:36 +00:00
|
|
|
|
2020-04-22 22:46:16 +00:00
|
|
|
# Check if one of the cels of the frame is linked
|
|
|
|
# if they are, unlink them too
|
|
|
|
# this prevents removed cels being kept in linked memory
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
2020-06-02 02:14:05 +00:00
|
|
|
# Loop through the array to create new classes for each element, so that they
|
|
|
|
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
|
|
|
for i in new_layers.size():
|
|
|
|
var new_linked_cels = new_layers[i].linked_cels.duplicate()
|
|
|
|
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
|
|
|
|
|
2020-04-22 22:46:16 +00:00
|
|
|
for layer in new_layers:
|
2020-06-01 13:42:53 +00:00
|
|
|
for linked in layer.linked_cels:
|
2020-06-04 18:05:36 +00:00
|
|
|
if linked == Global.current_project.frames[frame]:
|
2020-06-01 13:42:53 +00:00
|
|
|
layer.linked_cels.erase(linked)
|
2020-04-19 18:00:36 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undos += 1
|
|
|
|
Global.current_project.undo_redo.create_action("Remove Frame")
|
2020-04-15 17:59:49 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", current_frame)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2020-04-15 17:59:49 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
2020-04-15 17:59:49 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-04-15 17:59:49 +00:00
|
|
|
|
2020-04-17 01:25:08 +00:00
|
|
|
|
|
|
|
func _on_CopyFrame_pressed(frame := -1) -> void:
|
|
|
|
if frame == -1:
|
2020-06-04 18:05:36 +00:00
|
|
|
frame = Global.current_project.current_frame
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
var new_frame := Frame.new()
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_frames := Global.current_project.frames.duplicate()
|
2020-06-02 23:14:24 +00:00
|
|
|
new_frames.insert(frame + 1, new_frame)
|
2020-04-16 00:00:40 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
for cel in Global.current_project.frames[frame].cels: # Copy every cel
|
2020-04-15 17:59:49 +00:00
|
|
|
var sprite := Image.new()
|
2020-06-02 23:14:24 +00:00
|
|
|
sprite.copy_from(cel.image)
|
2020-04-15 17:59:49 +00:00
|
|
|
sprite.lock()
|
2020-06-02 23:14:24 +00:00
|
|
|
new_frame.cels.append(Cel.new(sprite, cel.opacity))
|
2020-04-15 17:59:49 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_animation_tags := Global.current_project.animation_tags.duplicate()
|
2020-06-02 02:14:05 +00:00
|
|
|
# Loop through the tags to create new classes for them, so that they won't be the same
|
2020-06-04 18:05:36 +00:00
|
|
|
# as Global.current_project.animation_tags's classes. Needed for undo/redo to work properly.
|
2020-06-02 02:14:05 +00:00
|
|
|
for i in new_animation_tags.size():
|
|
|
|
new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to)
|
|
|
|
|
2020-04-17 01:59:23 +00:00
|
|
|
# Loop through the tags to see if the frame is in one
|
2020-04-19 21:09:48 +00:00
|
|
|
for tag in new_animation_tags:
|
2020-06-02 02:14:05 +00:00
|
|
|
if frame + 1 >= tag.from && frame + 1 <= tag.to:
|
|
|
|
tag.to += 1
|
2020-04-17 01:59:23 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
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")
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", frame + 1)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "animation_tags", new_animation_tags)
|
|
|
|
for i in range(Global.current_project.layers.size()):
|
|
|
|
for child in Global.current_project.layers[i].frame_container.get_children():
|
|
|
|
Global.current_project.undo_redo.add_do_property(child, "pressed", false)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(child, "pressed", child.pressed)
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", frame)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "animation_tags", Global.current_project.animation_tags)
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2020-03-26 18:56:30 +00:00
|
|
|
|
2020-04-04 21:35:11 +00:00
|
|
|
func _on_FrameTagButton_pressed() -> void:
|
|
|
|
Global.tag_dialog.popup_centered()
|
|
|
|
|
2020-10-03 19:46:24 +00:00
|
|
|
func _on_MoveLeft_pressed() -> void:
|
|
|
|
var frame : int = Global.current_project.current_frame
|
|
|
|
if frame == 0:
|
|
|
|
return
|
|
|
|
Global.current_project.layers[Global.current_project.current_layer].frame_container.get_child(frame).change_frame_order(-1)
|
|
|
|
|
|
|
|
func _on_MoveRight_pressed() -> void:
|
|
|
|
var frame : int = Global.current_project.current_frame
|
|
|
|
if frame == last_frame:
|
|
|
|
return
|
|
|
|
Global.current_project.layers[Global.current_project.current_layer].frame_container.get_child(frame).change_frame_order(1)
|
2020-04-04 21:35:11 +00:00
|
|
|
|
2020-03-26 18:56:30 +00:00
|
|
|
func _on_OnionSkinning_pressed() -> void:
|
|
|
|
Global.onion_skinning = !Global.onion_skinning
|
|
|
|
Global.canvas.update()
|
2020-04-30 14:14:31 +00:00
|
|
|
var texture_button : TextureRect = Global.onion_skinning_button.get_child(0)
|
2020-04-03 12:34:16 +00:00
|
|
|
if Global.onion_skinning:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(texture_button, "onion_skinning.png")
|
2020-04-03 12:34:16 +00:00
|
|
|
else:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(texture_button, "onion_skinning_off.png")
|
2020-03-26 18:56:30 +00:00
|
|
|
|
2020-03-31 16:14:13 +00:00
|
|
|
func _on_OnionSkinningSettings_pressed() -> void:
|
2020-04-23 20:25:12 +00:00
|
|
|
$OnionSkinningSettings.popup(Rect2(Global.onion_skinning_button.rect_global_position.x - $OnionSkinningSettings.rect_size.x - 16, Global.onion_skinning_button.rect_global_position.y - 106, 136, 126))
|
2020-03-31 16:14:13 +00:00
|
|
|
|
|
|
|
|
2020-01-15 20:01:43 +00:00
|
|
|
func _on_LoopAnim_pressed() -> void:
|
2020-04-30 14:14:31 +00:00
|
|
|
var texture_button : TextureRect = Global.loop_animation_button.get_child(0)
|
2020-01-15 20:01:43 +00:00
|
|
|
match animation_loop:
|
2020-01-18 19:06:47 +00:00
|
|
|
0: # Make it loop
|
2020-01-15 20:01:43 +00:00
|
|
|
animation_loop = 1
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(texture_button, "loop.png")
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.loop_animation_button.hint_tooltip = "Cycle loop"
|
2020-01-18 19:06:47 +00:00
|
|
|
1: # Make it ping-pong
|
2020-01-15 20:01:43 +00:00
|
|
|
animation_loop = 2
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(texture_button, "loop_pingpong.png")
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.loop_animation_button.hint_tooltip = "Ping-pong loop"
|
2020-01-18 19:06:47 +00:00
|
|
|
2: # Make it stop
|
2020-01-15 20:01:43 +00:00
|
|
|
animation_loop = 0
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(texture_button, "loop_none.png")
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.loop_animation_button.hint_tooltip = "No loop"
|
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
|
2020-01-15 20:01:43 +00:00
|
|
|
func _on_PlayForward_toggled(button_pressed : bool) -> void:
|
2020-04-30 14:14:31 +00:00
|
|
|
if button_pressed:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(Global.play_forward.get_child(0), "pause.png")
|
2020-04-30 14:14:31 +00:00
|
|
|
else:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(Global.play_forward.get_child(0), "play.png")
|
2020-04-30 14:14:31 +00:00
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
play_animation(button_pressed, true)
|
2020-01-15 20:01:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_PlayBackwards_toggled(button_pressed : bool) -> void:
|
2020-04-30 14:14:31 +00:00
|
|
|
if button_pressed:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(Global.play_backwards.get_child(0), "pause.png")
|
2020-04-30 14:14:31 +00:00
|
|
|
else:
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(Global.play_backwards.get_child(0), "play_backwards.png")
|
2020-04-30 14:14:31 +00:00
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
play_animation(button_pressed, false)
|
2020-01-15 20:01:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_AnimationTimer_timeout() -> void:
|
2020-05-09 18:38:28 +00:00
|
|
|
if first_frame == last_frame:
|
|
|
|
$AnimationTimer.stop()
|
|
|
|
return
|
|
|
|
|
2020-12-17 00:20:47 +00:00
|
|
|
var fps = Global.current_project.fps
|
2020-01-15 20:01:43 +00:00
|
|
|
if animation_forward:
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.current_frame < last_frame:
|
|
|
|
Global.current_project.current_frame += 1
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.animation_timer.wait_time = Global.current_project.frames[Global.current_project.current_frame].duration * (1/fps)
|
|
|
|
Global.animation_timer.start() # Change the frame, change the wait time and start a cycle, this is the best way to do it
|
2020-01-15 20:01:43 +00:00
|
|
|
else:
|
|
|
|
match animation_loop:
|
2020-01-18 19:06:47 +00:00
|
|
|
0: # No loop
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.play_forward.pressed = false
|
|
|
|
Global.play_backwards.pressed = false
|
|
|
|
Global.animation_timer.stop()
|
2020-01-18 19:06:47 +00:00
|
|
|
1: # Cycle loop
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = first_frame
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.animation_timer.wait_time = Global.current_project.frames[Global.current_project.current_frame].duration * (1/fps)
|
2020-10-19 14:57:40 +00:00
|
|
|
Global.animation_timer.start()
|
2020-01-18 19:06:47 +00:00
|
|
|
2: # Ping pong loop
|
2020-01-15 20:01:43 +00:00
|
|
|
animation_forward = false
|
|
|
|
_on_AnimationTimer_timeout()
|
|
|
|
|
|
|
|
else:
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.current_frame > first_frame:
|
|
|
|
Global.current_project.current_frame -= 1
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.animation_timer.wait_time = Global.current_project.frames[Global.current_project.current_frame].duration * (1/fps)
|
2020-10-19 14:57:40 +00:00
|
|
|
Global.animation_timer.start()
|
2020-01-15 20:01:43 +00:00
|
|
|
else:
|
|
|
|
match animation_loop:
|
2020-01-18 19:06:47 +00:00
|
|
|
0: # No loop
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.play_backwards.pressed = false
|
|
|
|
Global.play_forward.pressed = false
|
|
|
|
Global.animation_timer.stop()
|
2020-01-18 19:06:47 +00:00
|
|
|
1: # Cycle loop
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = last_frame
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.animation_timer.wait_time = Global.current_project.frames[Global.current_project.current_frame].duration * (1/fps)
|
2020-10-19 14:57:40 +00:00
|
|
|
Global.animation_timer.start()
|
2020-01-18 19:06:47 +00:00
|
|
|
2: # Ping pong loop
|
2020-01-15 20:01:43 +00:00
|
|
|
animation_forward = true
|
|
|
|
_on_AnimationTimer_timeout()
|
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
func play_animation(play : bool, forward_dir : bool) -> void:
|
2020-05-09 18:38:28 +00:00
|
|
|
first_frame = 0
|
2020-06-04 18:05:36 +00:00
|
|
|
last_frame = Global.current_project.frames.size() - 1
|
2020-05-09 18:38:28 +00:00
|
|
|
if Global.play_only_tags:
|
2020-06-04 18:05:36 +00:00
|
|
|
for tag in Global.current_project.animation_tags:
|
|
|
|
if Global.current_project.current_frame + 1 >= tag.from && Global.current_project.current_frame + 1 <= tag.to:
|
2020-06-02 02:14:05 +00:00
|
|
|
first_frame = tag.from - 1
|
2020-06-04 18:05:36 +00:00
|
|
|
last_frame = min(Global.current_project.frames.size() - 1, tag.to - 1)
|
2020-05-09 18:38:28 +00:00
|
|
|
|
|
|
|
if first_frame == last_frame:
|
|
|
|
if forward_dir:
|
|
|
|
Global.play_forward.pressed = false
|
|
|
|
else:
|
|
|
|
Global.play_backwards.pressed = false
|
|
|
|
return
|
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
if forward_dir:
|
2020-04-23 21:10:21 +00:00
|
|
|
Global.play_backwards.disconnect("toggled", self, "_on_PlayBackwards_toggled")
|
2020-04-19 17:39:08 +00:00
|
|
|
Global.play_backwards.pressed = false
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(Global.play_backwards.get_child(0), "play_backwards.png")
|
2020-04-23 21:10:21 +00:00
|
|
|
Global.play_backwards.connect("toggled", self, "_on_PlayBackwards_toggled")
|
2020-04-19 17:39:08 +00:00
|
|
|
else:
|
2020-04-23 21:10:21 +00:00
|
|
|
Global.play_forward.disconnect("toggled", self, "_on_PlayForward_toggled")
|
2020-04-19 17:39:08 +00:00
|
|
|
Global.play_forward.pressed = false
|
2020-05-06 12:19:53 +00:00
|
|
|
Global.change_button_texturerect(Global.play_forward.get_child(0), "play.png")
|
2020-04-23 21:10:21 +00:00
|
|
|
Global.play_forward.connect("toggled", self, "_on_PlayForward_toggled")
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
if play:
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.animation_timer.set_one_shot(true) # The wait_time can't change correctly if it is playing
|
|
|
|
var duration : float = Global.current_project.frames[Global.current_project.current_frame].duration
|
2020-12-17 00:20:47 +00:00
|
|
|
var fps = Global.current_project.fps
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.animation_timer.wait_time = duration * (1 / fps)
|
2020-04-19 17:39:08 +00:00
|
|
|
Global.animation_timer.start()
|
|
|
|
animation_forward = forward_dir
|
|
|
|
else:
|
|
|
|
Global.animation_timer.stop()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_NextFrame_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.current_frame < Global.current_project.frames.size() - 1:
|
|
|
|
Global.current_project.current_frame += 1
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_PreviousFrame_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.current_frame > 0:
|
|
|
|
Global.current_project.current_frame -= 1
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_LastFrame_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = Global.current_project.frames.size() - 1
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_FirstFrame_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = 0
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
func _on_FPSValue_value_changed(value : float) -> void:
|
2020-12-17 00:20:47 +00:00
|
|
|
Global.current_project.fps = float(value)
|
|
|
|
Global.animation_timer.wait_time = 1 / Global.current_project.fps
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
|
|
|
func _on_PastOnionSkinning_value_changed(value : float) -> void:
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.onion_skinning_past_rate = int(value)
|
|
|
|
Global.canvas.update()
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
|
|
|
func _on_FutureOnionSkinning_value_changed(value : float) -> void:
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.onion_skinning_future_rate = int(value)
|
|
|
|
Global.canvas.update()
|
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
|
|
|
func _on_BlueRedMode_toggled(button_pressed : bool) -> void:
|
2020-01-15 20:01:43 +00:00
|
|
|
Global.onion_skinning_blue_red = button_pressed
|
|
|
|
Global.canvas.update()
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
# Layer buttons
|
|
|
|
|
|
|
|
func add_layer(is_new := true) -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
2020-06-01 13:42:53 +00:00
|
|
|
var l := Layer.new()
|
|
|
|
if !is_new: # Clone layer
|
2020-06-04 18:05:36 +00:00
|
|
|
l.name = Global.current_project.layers[Global.current_project.current_layer].name + " (" + tr("copy") + ")"
|
2020-06-01 13:42:53 +00:00
|
|
|
new_layers.append(l)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undos += 1
|
|
|
|
Global.current_project.undo_redo.create_action("Add Layer")
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
for f in Global.current_project.frames:
|
2020-02-20 00:14:15 +00:00
|
|
|
var new_layer := Image.new()
|
|
|
|
if is_new:
|
2020-06-04 20:20:20 +00:00
|
|
|
new_layer.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
|
2020-03-09 01:26:13 +00:00
|
|
|
else: # Clone layer
|
2020-06-04 18:05:36 +00:00
|
|
|
new_layer.copy_from(f.cels[Global.current_project.current_layer].image)
|
2020-02-20 00:14:15 +00:00
|
|
|
|
|
|
|
new_layer.lock()
|
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
var new_cels : Array = f.cels.duplicate()
|
|
|
|
new_cels.append(Cel.new(new_layer, 1))
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer + 1)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
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()
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
func _on_RemoveLayer_pressed() -> void:
|
2020-06-05 01:30:31 +00:00
|
|
|
if Global.current_project.layers.size() == 1:
|
|
|
|
return
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
|
|
|
new_layers.remove(Global.current_project.current_layer)
|
|
|
|
Global.current_project.undos += 1
|
|
|
|
Global.current_project.undo_redo.create_action("Remove Layer")
|
|
|
|
if Global.current_project.current_layer > 0:
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer - 1)
|
2020-03-08 19:25:09 +00:00
|
|
|
else:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
2020-02-22 15:00:39 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
for f in Global.current_project.frames:
|
2020-06-02 23:14:24 +00:00
|
|
|
var new_cels : Array = f.cels.duplicate()
|
2020-06-04 18:05:36 +00:00
|
|
|
new_cels.remove(Global.current_project.current_layer)
|
|
|
|
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-04-22 13:56:03 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
func change_layer_order(rate : int) -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
var change = Global.current_project.current_layer + rate
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
|
|
|
var temp = new_layers[Global.current_project.current_layer]
|
|
|
|
new_layers[Global.current_project.current_layer] = new_layers[change]
|
2020-01-18 19:06:47 +00:00
|
|
|
new_layers[change] = temp
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.create_action("Change Layer Order")
|
|
|
|
for f in Global.current_project.frames:
|
2020-06-02 23:14:24 +00:00
|
|
|
var new_cels : Array = f.cels.duplicate()
|
2020-06-04 18:05:36 +00:00
|
|
|
var temp_canvas = new_cels[Global.current_project.current_layer]
|
|
|
|
new_cels[Global.current_project.current_layer] = new_cels[change]
|
2020-06-02 23:14:24 +00:00
|
|
|
new_cels[change] = temp_canvas
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-02-29 22:57:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", change)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
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()
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-04-22 13:56:03 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
func _on_MergeDownLayer_pressed() -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
2020-06-02 02:14:05 +00:00
|
|
|
# Loop through the array to create new classes for each element, so that they
|
|
|
|
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
|
|
|
|
for i in new_layers.size():
|
|
|
|
var new_linked_cels = new_layers[i].linked_cels.duplicate()
|
|
|
|
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undos += 1
|
|
|
|
Global.current_project.undo_redo.create_action("Merge Layer")
|
|
|
|
for f in Global.current_project.frames:
|
2020-06-02 23:14:24 +00:00
|
|
|
var new_cels : Array = f.cels.duplicate()
|
|
|
|
for i in new_cels.size():
|
|
|
|
new_cels[i] = Cel.new(new_cels[i].image, new_cels[i].opacity)
|
2020-03-28 13:56:01 +00:00
|
|
|
var selected_layer := Image.new()
|
2020-06-04 18:05:36 +00:00
|
|
|
selected_layer.copy_from(new_cels[Global.current_project.current_layer].image)
|
2020-03-28 13:56:01 +00:00
|
|
|
selected_layer.lock()
|
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
if f.cels[Global.current_project.current_layer].opacity < 1: # If we have layer transparency
|
2020-02-29 23:43:48 +00:00
|
|
|
for xx in selected_layer.get_size().x:
|
|
|
|
for yy in selected_layer.get_size().y:
|
|
|
|
var pixel_color : Color = selected_layer.get_pixel(xx, yy)
|
2020-06-04 18:05:36 +00:00
|
|
|
var alpha : float = pixel_color.a * f.cels[Global.current_project.current_layer].opacity
|
2020-02-29 23:43:48 +00:00
|
|
|
selected_layer.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
|
|
|
|
|
|
|
|
var new_layer := Image.new()
|
2020-06-04 18:05:36 +00:00
|
|
|
new_layer.copy_from(f.cels[Global.current_project.current_layer - 1].image)
|
2020-02-29 23:43:48 +00:00
|
|
|
new_layer.lock()
|
2020-06-30 12:07:09 +00:00
|
|
|
new_layer.blend_rect(selected_layer, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
|
2020-06-04 18:05:36 +00:00
|
|
|
new_cels.remove(Global.current_project.current_layer)
|
|
|
|
if !selected_layer.is_invisible() and Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels.size() > 1 and (f in Global.current_project.layers[Global.current_project.current_layer - 1].linked_cels):
|
|
|
|
new_layers[Global.current_project.current_layer - 1].linked_cels.erase(f)
|
|
|
|
new_cels[Global.current_project.current_layer - 1].image = new_layer
|
2020-04-22 13:56:03 +00:00
|
|
|
else:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(f.cels[Global.current_project.current_layer - 1].image, "data", new_layer.data)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f.cels[Global.current_project.current_layer - 1].image, "data", f.cels[Global.current_project.current_layer - 1].image.data)
|
2020-02-29 23:43:48 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-02-29 23:43:48 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
new_layers.remove(Global.current_project.current_layer)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", Global.current_project.current_layer - 1)
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
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()
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-04-11 02:36:51 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
func _on_OpacitySlider_value_changed(value) -> void:
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].opacity = value / 100
|
2020-01-18 19:06:47 +00:00
|
|
|
Global.layer_opacity_slider.value = value
|
2020-04-15 17:59:49 +00:00
|
|
|
Global.layer_opacity_slider.value = value
|
2020-01-18 19:06:47 +00:00
|
|
|
Global.layer_opacity_spinbox.value = value
|
|
|
|
Global.canvas.update()
|
2020-03-31 16:14:13 +00:00
|
|
|
|
2020-04-02 00:29:14 +00:00
|
|
|
|
|
|
|
func _on_OnionSkinningSettings_popup_hide() -> void:
|
|
|
|
Global.can_draw = true
|
2020-10-03 19:46:24 +00:00
|
|
|
|