1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

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

* Don't select new cels

* sync with 1.x version
This commit is contained in:
Variable 2023-11-21 19:49:13 +05:00 committed by GitHub
parent f70f3d3458
commit 8784427c72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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: