2020-01-15 20:01:43 +00:00
|
|
|
extends Panel
|
|
|
|
|
2021-07-25 18:49:37 +00:00
|
|
|
var is_animation_running := false
|
2021-11-25 12:48:30 +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
|
2021-01-30 21:57:33 +00:00
|
|
|
var is_mouse_hover := false
|
|
|
|
var cel_size := 36 setget cel_size_changed
|
|
|
|
var min_cel_size := 36
|
|
|
|
var max_cel_size := 144
|
2021-11-26 01:38:00 +00:00
|
|
|
var past_above_canvas := true
|
|
|
|
var future_above_canvas := true
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2022-02-07 16:10:29 +00:00
|
|
|
onready var timeline_scroll: ScrollContainer = find_node("TimelineScroll")
|
|
|
|
onready var tag_scroll_container: ScrollContainer = find_node("TagScroll")
|
|
|
|
onready var fps_spinbox: SpinBox = find_node("FPSValue")
|
2021-11-25 12:48:30 +00:00
|
|
|
onready var onion_skinning_button: BaseButton = find_node("OnionSkinning")
|
|
|
|
onready var loop_animation_button: BaseButton = find_node("LoopAnim")
|
2021-11-23 00:36:22 +00:00
|
|
|
|
2020-05-01 17:47:10 +00:00
|
|
|
|
2020-04-02 00:29:14 +00:00
|
|
|
func _ready() -> void:
|
|
|
|
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-12-17 00:52:13 +00:00
|
|
|
fps_spinbox.value = Global.current_project.fps
|
2020-04-02 00:29:14 +00:00
|
|
|
|
2020-04-17 01:25:08 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _input(event: InputEvent) -> void:
|
2021-01-30 21:57:33 +00:00
|
|
|
var mouse_pos := get_global_mouse_position()
|
|
|
|
var timeline_rect := Rect2(rect_global_position, rect_size)
|
|
|
|
if timeline_rect.has_point(mouse_pos):
|
|
|
|
if Input.is_key_pressed(KEY_CONTROL):
|
2021-11-25 12:48:30 +00:00
|
|
|
self.cel_size += (
|
|
|
|
2 * int(event.is_action("zoom_in"))
|
|
|
|
- 2 * int(event.is_action("zoom_out"))
|
|
|
|
)
|
2021-01-30 21:57:33 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _h_scroll_changed(value: float) -> void:
|
2020-04-02 00:29:14 +00:00
|
|
|
# Let the main timeline ScrollContainer affect the tag ScrollContainer too
|
2021-11-25 12:48:30 +00:00
|
|
|
tag_scroll_container.get_child(0).rect_min_size.x = (
|
|
|
|
timeline_scroll.get_child(0).rect_size.x
|
|
|
|
- 212
|
|
|
|
)
|
2020-04-02 00:29:14 +00:00
|
|
|
tag_scroll_container.scroll_horizontal = value
|
|
|
|
|
2020-03-31 16:14:13 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func cel_size_changed(value: int) -> void:
|
2021-01-30 21:57:33 +00:00
|
|
|
cel_size = clamp(value, min_cel_size, max_cel_size)
|
|
|
|
for layer_button in Global.layers_container.get_children():
|
|
|
|
layer_button.rect_min_size.y = cel_size
|
|
|
|
layer_button.rect_size.y = cel_size
|
2021-12-23 17:58:07 +00:00
|
|
|
for container in Global.frames_container.get_children():
|
|
|
|
for cel_button in container.get_children():
|
2021-01-30 21:57:33 +00:00
|
|
|
cel_button.rect_min_size.x = cel_size
|
|
|
|
cel_button.rect_min_size.y = cel_size
|
|
|
|
cel_button.rect_size.x = cel_size
|
|
|
|
cel_button.rect_size.y = cel_size
|
|
|
|
|
|
|
|
for frame_id in Global.frame_ids.get_children():
|
|
|
|
frame_id.rect_min_size.x = cel_size
|
|
|
|
frame_id.rect_size.x = cel_size
|
|
|
|
|
|
|
|
for tag_c in Global.tag_container.get_children():
|
2021-11-16 22:21:29 +00:00
|
|
|
var tag_base_size = cel_size + 4
|
2021-11-25 12:48:30 +00:00
|
|
|
var tag: AnimationTag = tag_c.tag
|
|
|
|
# Added 1 to answer to get starting position of next cel
|
|
|
|
tag_c.rect_position.x = (tag.from - 1) * tag_base_size + 1
|
|
|
|
var tag_size: int = tag.to - tag.from
|
|
|
|
# We dont need the 4 pixels at the end of last cel
|
|
|
|
tag_c.rect_min_size.x = (tag_size + 1) * tag_base_size - 4
|
|
|
|
# We dont need the 4 pixels at the end of last cel
|
|
|
|
tag_c.rect_size.x = (tag_size + 1) * tag_base_size - 4
|
2021-01-30 21:57:33 +00:00
|
|
|
tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0)
|
|
|
|
tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32)
|
|
|
|
|
|
|
|
|
2020-01-15 20:01:43 +00:00
|
|
|
func add_frame() -> void:
|
2021-12-01 18:02:39 +00:00
|
|
|
var project: Project = Global.current_project
|
2021-12-01 18:50:50 +00:00
|
|
|
var frame: Frame = project.new_empty_frame()
|
2021-12-01 18:02:39 +00:00
|
|
|
var new_frames: Array = project.frames.duplicate()
|
2021-12-23 17:58:07 +00:00
|
|
|
var new_layers: Array = project.duplicate_layers()
|
2021-12-01 18:02:39 +00:00
|
|
|
new_frames.insert(project.current_frame + 1, frame)
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
for l_i in range(new_layers.size()):
|
2021-11-25 12:48:30 +00:00
|
|
|
if new_layers[l_i].new_cels_linked: # If the link button is pressed
|
2020-06-02 23:14:24 +00:00
|
|
|
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
|
|
|
|
2021-12-01 18:02:39 +00:00
|
|
|
project.undos += 1
|
|
|
|
project.undo_redo.create_action("Add Frame")
|
2021-12-02 00:22:32 +00:00
|
|
|
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
|
|
|
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
2020-03-04 23:53:48 +00:00
|
|
|
|
2021-12-01 18:02:39 +00:00
|
|
|
project.undo_redo.add_do_property(project, "frames", new_frames)
|
|
|
|
project.undo_redo.add_do_property(project, "current_frame", project.current_frame + 1)
|
|
|
|
project.undo_redo.add_do_property(project, "layers", new_layers)
|
2020-03-18 00:56:29 +00:00
|
|
|
|
2021-12-01 18:02:39 +00:00
|
|
|
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, "layers", project.layers)
|
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
delete_frame(frame)
|
|
|
|
|
|
|
|
|
|
|
|
func delete_frame(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
|
|
|
|
2021-11-25 12:48:30 +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
|
2021-11-25 12:48:30 +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():
|
2021-11-25 12:48:30 +00:00
|
|
|
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-06-02 02:14:05 +00:00
|
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
2021-12-23 17:58:07 +00:00
|
|
|
var new_layers: Array = Global.current_project.duplicate_layers()
|
2020-06-02 02:14:05 +00:00
|
|
|
|
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)
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
|
|
|
)
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2020-04-15 17:59:49 +00:00
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-12-02 00:22:32 +00:00
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
copy_frame(frame)
|
|
|
|
|
|
|
|
|
|
|
|
func copy_frame(frame := -1) -> void:
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2020-04-17 01:25:08 +00:00
|
|
|
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()
|
2021-12-23 17:58:07 +00:00
|
|
|
var new_layers: Array = Global.current_project.duplicate_layers()
|
2020-06-02 23:14:24 +00:00
|
|
|
new_frames.insert(frame + 1, new_frame)
|
2020-04-16 00:00:40 +00:00
|
|
|
|
2021-12-31 02:05:04 +00:00
|
|
|
var prev_frame: Frame = Global.current_project.frames[frame]
|
|
|
|
for cel in prev_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)
|
2021-07-22 00:10:00 +00:00
|
|
|
var sprite_texture := ImageTexture.new()
|
|
|
|
sprite_texture.create_from_image(sprite, 0)
|
|
|
|
new_frame.cels.append(Cel.new(sprite, cel.opacity, sprite_texture))
|
|
|
|
|
2021-12-31 02:05:04 +00:00
|
|
|
new_frame.duration = prev_frame.duration
|
2021-07-22 00:10:00 +00:00
|
|
|
for l_i in range(new_layers.size()):
|
2021-11-25 12:48:30 +00:00
|
|
|
if new_layers[l_i].new_cels_linked: # If the link button is pressed
|
2021-07-22 00:10:00 +00:00
|
|
|
new_layers[l_i].linked_cels.append(new_frame)
|
|
|
|
new_frame.cels[l_i].image = new_layers[l_i].linked_cels[0].cels[l_i].image
|
|
|
|
new_frame.cels[l_i].image_texture = new_layers[l_i].linked_cels[0].cels[l_i].image_texture
|
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():
|
2021-11-25 12:48:30 +00:00
|
|
|
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-06-02 02:14:05 +00:00
|
|
|
|
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")
|
2021-12-02 00:22:32 +00:00
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
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)
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_frame", frame + 1
|
|
|
|
)
|
2021-07-22 00:10:00 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "animation_tags", new_animation_tags
|
|
|
|
)
|
|
|
|
|
|
|
|
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, "layers", Global.current_project.layers
|
|
|
|
)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(
|
|
|
|
Global.current_project, "animation_tags", Global.current_project.animation_tags
|
|
|
|
)
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-11-23 00:36:22 +00:00
|
|
|
find_node("FrameTagDialog").popup_centered()
|
2020-04-04 21:35:11 +00:00
|
|
|
|
2021-01-29 20:00:48 +00:00
|
|
|
|
2020-10-03 19:46:24 +00:00
|
|
|
func _on_MoveLeft_pressed() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
var frame: int = Global.current_project.current_frame
|
2020-10-03 19:46:24 +00:00
|
|
|
if frame == 0:
|
|
|
|
return
|
2021-06-04 23:37:33 +00:00
|
|
|
Global.frame_ids.get_child(frame).change_frame_order(-1)
|
2020-10-03 19:46:24 +00:00
|
|
|
|
2021-01-29 20:00:48 +00:00
|
|
|
|
2020-10-03 19:46:24 +00:00
|
|
|
func _on_MoveRight_pressed() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
var frame: int = Global.current_project.current_frame
|
2020-10-03 19:46:24 +00:00
|
|
|
if frame == last_frame:
|
|
|
|
return
|
2021-06-04 23:37:33 +00:00
|
|
|
Global.frame_ids.get_child(frame).change_frame_order(1)
|
2020-04-04 21:35:11 +00:00
|
|
|
|
2021-01-29 20:00:48 +00:00
|
|
|
|
2020-03-26 18:56:30 +00:00
|
|
|
func _on_OnionSkinning_pressed() -> void:
|
|
|
|
Global.onion_skinning = !Global.onion_skinning
|
2021-11-26 00:55:08 +00:00
|
|
|
Global.canvas.refresh_onion()
|
2021-11-25 12:48:30 +00:00
|
|
|
var texture_button: TextureRect = 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
|
|
|
|
2021-01-29 20:00:48 +00:00
|
|
|
|
2020-03-31 16:14:13 +00:00
|
|
|
func _on_OnionSkinningSettings_pressed() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
$OnionSkinningSettings.popup(
|
|
|
|
Rect2(
|
|
|
|
onion_skinning_button.rect_global_position.x - $OnionSkinningSettings.rect_size.x - 16,
|
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
var texture_button: TextureRect = loop_animation_button.get_child(0)
|
2020-01-15 20:01:43 +00:00
|
|
|
match animation_loop:
|
2021-11-25 12:48:30 +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")
|
2021-11-23 00:36:22 +00:00
|
|
|
loop_animation_button.hint_tooltip = "Cycle loop"
|
2021-11-25 12:48:30 +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")
|
2021-11-23 00:36:22 +00:00
|
|
|
loop_animation_button.hint_tooltip = "Ping-pong loop"
|
2021-11-25 12:48:30 +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")
|
2021-11-23 00:36:22 +00:00
|
|
|
loop_animation_button.hint_tooltip = "No loop"
|
2020-01-15 20:01:43 +00:00
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
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:
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame += 1
|
2021-11-25 12:48:30 +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
|
2020-01-15 20:01:43 +00:00
|
|
|
else:
|
|
|
|
match animation_loop:
|
2021-11-25 12:48:30 +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()
|
2021-07-25 18:49:37 +00:00
|
|
|
is_animation_running = false
|
2021-11-25 12:48:30 +00:00
|
|
|
1: # Cycle loop
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = first_frame
|
2021-11-25 12:48:30 +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()
|
2021-11-25 12:48:30 +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:
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame -= 1
|
2021-11-25 12:48:30 +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:
|
2021-11-25 12:48:30 +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()
|
2021-07-25 18:49:37 +00:00
|
|
|
is_animation_running = false
|
2021-11-25 12:48:30 +00:00
|
|
|
1: # Cycle loop
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = last_frame
|
2021-11-25 12:48:30 +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()
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-11-25 12:48:30 +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:
|
2021-11-25 12:48:30 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.animation_timer.set_one_shot(true) # wait_time can't change correctly if it's 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()
|
|
|
|
|
2021-07-25 18:49:37 +00:00
|
|
|
is_animation_running = play
|
|
|
|
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
func _on_NextFrame_pressed() -> void:
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
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:
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
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:
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
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:
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = 0
|
2020-04-19 17:39:08 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-12-01 00:28:12 +00:00
|
|
|
func _on_PastPlacement_item_selected(index: int) -> void:
|
2021-11-26 01:38:00 +00:00
|
|
|
past_above_canvas = (index == 0)
|
|
|
|
Global.canvas.get_node("OnionPast").set("show_behind_parent", !past_above_canvas)
|
2021-11-26 00:55:08 +00:00
|
|
|
|
|
|
|
|
2021-12-01 00:28:12 +00:00
|
|
|
func _on_FuturePlacement_item_selected(index: int) -> void:
|
2021-11-26 01:38:00 +00:00
|
|
|
future_above_canvas = (index == 0)
|
|
|
|
Global.canvas.get_node("OnionFuture").set("show_behind_parent", !future_above_canvas)
|
2021-11-26 00:55:08 +00:00
|
|
|
|
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
# Layer buttons
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
2020-01-18 19:06:47 +00:00
|
|
|
func add_layer(is_new := true) -> void:
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_layers: Array = Global.current_project.layers.duplicate()
|
2020-06-01 13:42:53 +00:00
|
|
|
var l := Layer.new()
|
2021-11-25 12:48:30 +00:00
|
|
|
if !is_new: # Clone layer
|
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
new_layer.create(
|
|
|
|
Global.current_project.size.x,
|
|
|
|
Global.current_project.size.y,
|
|
|
|
false,
|
|
|
|
Image.FORMAT_RGBA8
|
|
|
|
)
|
|
|
|
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
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_cels: Array = f.cels.duplicate()
|
2020-06-02 23:14:24 +00:00
|
|
|
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
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_layer", Global.current_project.layers.size()
|
|
|
|
)
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
|
|
|
2021-12-02 00:22:32 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
2020-06-04 18:05:36 +00:00
|
|
|
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
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_layers: Array = Global.current_project.layers.duplicate()
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +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:
|
2021-11-25 12:48:30 +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)
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
|
|
|
)
|
2021-12-02 00:22:32 +00:00
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-01-18 19:06:47 +00:00
|
|
|
|
2020-04-22 13:56:03 +00:00
|
|
|
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_layers: Array = Global.current_project.layers.duplicate()
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +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
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_layer", change
|
|
|
|
)
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
|
|
|
2021-12-02 00:22:32 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-12-23 17:58:07 +00:00
|
|
|
var new_layers: Array = Global.current_project.duplicate_layers()
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_cels: Array = f.cels.duplicate()
|
2020-06-02 23:14:24 +00:00
|
|
|
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
|
|
|
|
2021-09-22 18:54:16 +00:00
|
|
|
selected_layer.lock()
|
2021-11-25 12:48:30 +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:
|
2021-11-25 12:48:30 +00:00
|
|
|
var pixel_color: Color = selected_layer.get_pixel(xx, yy)
|
|
|
|
var alpha: float = (
|
|
|
|
pixel_color.a
|
|
|
|
* f.cels[Global.current_project.current_layer].opacity
|
|
|
|
)
|
|
|
|
selected_layer.set_pixel(
|
|
|
|
xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha)
|
|
|
|
)
|
2021-09-22 18:54:16 +00:00
|
|
|
selected_layer.unlock()
|
2020-02-29 23:43:48 +00:00
|
|
|
|
|
|
|
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)
|
2021-11-25 12:48:30 +00:00
|
|
|
new_layer.blend_rect(
|
|
|
|
selected_layer, Rect2(Vector2.ZERO, Global.current_project.size), Vector2.ZERO
|
|
|
|
)
|
2020-06-04 18:05:36 +00:00
|
|
|
new_cels.remove(Global.current_project.current_layer)
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
|
|
|
)
|
|
|
|
):
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +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)
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_layer", Global.current_project.current_layer - 1
|
|
|
|
)
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2021-11-25 12:48:30 +00:00
|
|
|
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
|
|
|
|
2021-12-02 00:22:32 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
|
2020-06-04 18:05:36 +00:00
|
|
|
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:
|
2021-11-25 12:48:30 +00:00
|
|
|
var current_frame: Frame = Global.current_project.frames[Global.current_project.current_frame]
|
|
|
|
var cel: Cel = current_frame.cels[Global.current_project.current_layer]
|
2021-07-09 00:38:06 +00:00
|
|
|
cel.opacity = value / 100
|
2020-01-18 19:06:47 +00:00
|
|
|
Global.layer_opacity_slider.value = value
|
|
|
|
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
|