diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index 3d4d40266..d28b70e72 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -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: @@ -300,6 +301,7 @@ 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() @@ -307,6 +309,8 @@ func copy_frames(indices := [], destination := -1) -> void: 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 @@ -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: