diff --git a/Scripts/AnimationTimeline.gd b/Scripts/AnimationTimeline.gd index 77dc4c9..185e36f 100644 --- a/Scripts/AnimationTimeline.gd +++ b/Scripts/AnimationTimeline.gd @@ -66,18 +66,18 @@ func _on_DeleteFrame_pressed(frame := -1) -> void: if current_frame > 0 && current_frame == new_canvases.size(): # If it's the last frame current_frame -= 1 + var new_animation_tags := Global.animation_tags.duplicate(true) # Loop through the tags to see if the frame is in one - for tag in Global.animation_tags: + for tag in new_animation_tags: if frame + 1 >= tag[2] && frame + 1 <= tag[3]: if tag[3] == tag[2]: # If we're deleting the only frame in the tag - Global.animation_tags.erase(tag) + new_animation_tags.erase(tag) else: tag[3] -= 1 elif frame + 1 < tag[2]: tag[2] -= 1 tag[3] -= 1 - Global.animation_tags = Global.animation_tags # To execute animation_tags_changed() Global.undos += 1 Global.undo_redo.create_action("Remove Frame") @@ -85,15 +85,18 @@ func _on_DeleteFrame_pressed(frame := -1) -> void: Global.undo_redo.add_do_property(Global, "canvases", new_canvases) Global.undo_redo.add_do_property(Global, "canvas", new_canvases[current_frame]) Global.undo_redo.add_do_property(Global, "current_frame", current_frame) + Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags) for i in range(frame, new_canvases.size()): var c : Canvas = new_canvases[i] Global.undo_redo.add_do_property(c, "frame", i) Global.undo_redo.add_undo_property(c, "frame", c.frame) + Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases) Global.undo_redo.add_undo_property(Global, "canvas", canvas) Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame) + Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags) Global.undo_redo.add_do_method(Global, "redo", [canvas]) Global.undo_redo.add_undo_method(Global, "undo", [canvas]) @@ -120,11 +123,11 @@ func _on_CopyFrame_pressed(frame := -1) -> void: tex.create_from_image(sprite, 0) new_canvas.layers.append([sprite, tex, layer[2]]) + var new_animation_tags := Global.animation_tags.duplicate(true) # Loop through the tags to see if the frame is in one - for tag in Global.animation_tags: + for tag in new_animation_tags: if frame + 1 >= tag[2] && frame + 1 <= tag[3]: tag[3] += 1 - Global.animation_tags = Global.animation_tags # To execute animation_tags_changed() Global.undos += 1 Global.undo_redo.create_action("Add Frame") @@ -134,6 +137,7 @@ func _on_CopyFrame_pressed(frame := -1) -> void: Global.undo_redo.add_do_property(Global, "canvases", new_canvases) Global.undo_redo.add_do_property(Global, "canvas", new_canvas) Global.undo_redo.add_do_property(Global, "current_frame", frame + 1) + Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags) for i in range(Global.layers.size()): for child in Global.layers[i][3].get_children(): Global.undo_redo.add_do_property(child, "pressed", false) @@ -150,6 +154,7 @@ func _on_CopyFrame_pressed(frame := -1) -> void: Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases) Global.undo_redo.add_undo_property(Global, "canvas", Global.canvas) Global.undo_redo.add_undo_property(Global, "current_frame", frame) + Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags) Global.undo_redo.commit_action() diff --git a/Scripts/Dialogs/FrameTagDialog.gd b/Scripts/Dialogs/FrameTagDialog.gd index 4b280bf..d7bacff 100644 --- a/Scripts/Dialogs/FrameTagDialog.gd +++ b/Scripts/Dialogs/FrameTagDialog.gd @@ -88,21 +88,39 @@ func _on_TagOptions_confirmed() -> void: if tag_from > tag_to: tag_from = tag_to + var new_animation_tags := Global.animation_tags.duplicate(true) if current_tag_id == Global.animation_tags.size(): - Global.animation_tags.append([tag_name, tag_color, tag_from, tag_to]) - Global.animation_tags = Global.animation_tags # To execute animation_tags_changed() + new_animation_tags.append([tag_name, tag_color, tag_from, tag_to]) else: - Global.animation_tags[current_tag_id][0] = tag_name - Global.animation_tags[current_tag_id][1] = tag_color - Global.animation_tags[current_tag_id][2] = tag_from - Global.animation_tags[current_tag_id][3] = tag_to + new_animation_tags[current_tag_id][0] = tag_name + new_animation_tags[current_tag_id][1] = tag_color + new_animation_tags[current_tag_id][2] = tag_from + new_animation_tags[current_tag_id][3] = tag_to + + # Handle Undo/Redo + Global.undos += 1 + Global.undo_redo.create_action("Modify Frame Tag") + Global.undo_redo.add_do_method(Global, "general_redo") + Global.undo_redo.add_undo_method(Global, "general_undo") + Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags) + Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags) + Global.undo_redo.commit_action() _on_FrameTagDialog_about_to_show() func _on_TagOptions_custom_action(action : String) -> void: if action == "delete_tag": - Global.animation_tags.remove(current_tag_id) - Global.animation_tags = Global.animation_tags # To execute animation_tags_changed() + var new_animation_tags := Global.animation_tags.duplicate(true) + new_animation_tags.remove(current_tag_id) + # Handle Undo/Redo + Global.undos += 1 + Global.undo_redo.create_action("Delete Frame Tag") + Global.undo_redo.add_do_method(Global, "general_redo") + Global.undo_redo.add_undo_method(Global, "general_undo") + Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags) + Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags) + Global.undo_redo.commit_action() + options_dialog.hide() _on_FrameTagDialog_about_to_show() diff --git a/Scripts/Global.gd b/Scripts/Global.gd index ce5c45d..84fc342 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -431,6 +431,7 @@ func find_node_by_name(root, node_name) -> Node: return found return null + func notification_label(text : String) -> void: var notification : Label = load("res://Prefabs/NotificationLabel.tscn").instance() notification.text = tr(text)