Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.x] Make cloned frames only select a cel if it's coresponding original cel was selected as well #941

Merged
merged 3 commits into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions src/UI/Timeline/AnimationTimeline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,11 @@ func delete_frames(indices := []) -> void:


func _on_CopyFrame_pressed() -> void:
copy_frames()
# Do not select new cels, If they are copied.
copy_frames([], -1, false)


func copy_frames(indices := [], destination := -1) -> void:
func copy_frames(indices := [], destination := -1, select_all_cels := true) -> void:
var project: Project = Global.current_project

if indices.size() == 0:
Expand Down Expand Up @@ -300,13 +301,16 @@ func copy_frames(indices := [], destination := -1) -> void:
)
project.undos += 1
project.undo_redo.create_action("Add Frame")
var last_focus_cels = []
for f in indices:
var src_frame: Frame = project.frames[f]
var new_frame := Frame.new()
copied_frames.append(new_frame)

new_frame.duration = src_frame.duration
for l in range(project.layers.size()):
if [f, l] in project.selected_cels:
last_focus_cels.append([copied_indices[indices.find(f)], l])
var src_cel: BaseCel = project.frames[f].cels[l] # Cel we're copying from, the source
var new_cel: BaseCel
var selected_id := -1
Expand Down Expand Up @@ -346,29 +350,38 @@ func copy_frames(indices := [], destination := -1) -> void:
tag.to += 1
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
# Note: temporarily set the selected cels to an empty array (needed for undo/redo)
project.undo_redo.add_do_property(Global.current_project, "selected_cels", [])
project.undo_redo.add_undo_property(Global.current_project, "selected_cels", [])
project.undo_redo.add_do_method(project, "add_frames", copied_frames, copied_indices)
project.undo_redo.add_undo_method(project, "remove_frames", copied_indices)
project.undo_redo.add_do_method(project, "change_cel", copied_indices[0])
if select_all_cels:
# Select all the new frames so that it is easier to move/offset collectively if user wants
# To ease animation workflow, new current frame is the first copied frame instead of the last
var all_new_cels = []
var range_start: int = copied_indices[-1]
var range_end = copied_indices[0]
var frame_diff_sign = sign(range_end - range_start)
if frame_diff_sign == 0:
frame_diff_sign = 1
for i in range(range_start, range_end + frame_diff_sign, frame_diff_sign):
for j in range(0, Global.current_project.layers.size()):
var frame_layer := [i, j]
if !all_new_cels.has(frame_layer):
all_new_cels.append(frame_layer)
project.undo_redo.add_do_property(Global.current_project, "selected_cels", all_new_cels)
project.undo_redo.add_do_method(project, "change_cel", range_end)
else:
project.undo_redo.add_do_property(Global.current_project, "selected_cels", last_focus_cels)
project.undo_redo.add_do_method(project, "change_cel", copied_indices[0])
project.undo_redo.add_undo_property(
Global.current_project, "selected_cels", project.selected_cels
)
project.undo_redo.add_undo_method(project, "change_cel", project.current_frame)
project.undo_redo.add_do_property(project, "animation_tags", new_animation_tags)
project.undo_redo.add_undo_property(project, "animation_tags", project.animation_tags)
project.undo_redo.commit_action()
# Select all the new frames so that it is easier to move/offset collectively if user wants
# To ease animation workflow, new current frame is the first copied frame instead of the last
var range_start: int = copied_indices[-1]
var range_end = copied_indices[0]
var frame_diff_sign = sign(range_end - range_start)
if frame_diff_sign == 0:
frame_diff_sign = 1
for i in range(range_start, range_end + frame_diff_sign, frame_diff_sign):
for j in range(0, Global.current_project.layers.size()):
var frame_layer := [i, j]
if !Global.current_project.selected_cels.has(frame_layer):
Global.current_project.selected_cels.append(frame_layer)
Global.current_project.change_cel(range_end, -1)
yield(get_tree(), "idle_frame")
yield(get_tree(), "idle_frame")
adjust_scroll_container()


func _on_FrameTagButton_pressed() -> void:
Expand Down