diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index b4516eddd..c5bb90a63 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -99,7 +99,7 @@ func _on_LayerVBox_resized() -> void: frame_scroll_bar.margin_left = frame_scroll_container.rect_position.x tag_spacer.rect_min_size.x = ( frame_scroll_container.rect_global_position.x - - tag_spacer.rect_global_position.x + - tag_scroll_container.rect_global_position.x ) @@ -268,14 +268,18 @@ func _on_CopyFrame_pressed() -> void: copy_frames(indices) -func copy_frames(indices := []) -> void: +func copy_frames(indices := [], destination := -1) -> void: var project: Project = Global.current_project if indices.size() == 0: indices.append(project.current_frame) var copied_frames := [] - var copied_indices := range(indices[-1] + 1, indices[-1] + 1 + indices.size()) + var copied_indices := [] # the indices of newly copied frames + if destination != -1: + copied_indices = range((destination + 1), (destination + 1) + indices.size()) + else: + copied_indices = range(indices[-1] + 1, indices[-1] + 1 + indices.size()) var new_animation_tags := project.animation_tags.duplicate() # Loop through the tags to create new classes for them, so that they won't be the same @@ -331,9 +335,9 @@ func copy_frames(indices := []) -> void: # Loop through the tags to see if the frame is in one for tag in new_animation_tags: - if indices[-1] + 1 >= tag.from && indices[-1] + 1 <= tag.to: + if copied_indices[0] >= tag.from && copied_indices[0] <= tag.to: tag.to += 1 - elif indices[-1] + 1 < tag.from: + elif copied_indices[0] < tag.from: tag.from += 1 tag.to += 1 @@ -341,8 +345,8 @@ func copy_frames(indices := []) -> void: project.undo_redo.add_undo_method(Global, "undo_or_redo", true) 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", indices[-1] + 1) - project.undo_redo.add_undo_method(project, "change_cel", indices[-1]) + project.undo_redo.add_do_method(project, "change_cel", copied_indices[0]) + 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() @@ -350,8 +354,8 @@ func copy_frames(indices := []) -> void: # Select all the new frames so that it is easier to move/offset collectively if user wants # For ease in animation workflow, the new current frame will be the first duplicated frame # instead of the last - var range_start: int = indices[-1] + indices.size() - var range_end = indices[0] + indices.size() + 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 @@ -363,6 +367,31 @@ func copy_frames(indices := []) -> void: Global.current_project.change_cel(range_end, -1) +func _on_CopyTag_pressed() -> void: + $"%TagList".clear() + if Global.current_project.animation_tags.empty(): + return + for tag in Global.current_project.animation_tags: + var img = Image.new() + img.create(5, 5, true, Image.FORMAT_RGBA8) + img.fill(tag.color) + var tex = ImageTexture.new() + tex.create_from_image(img) + $"%TagList".add_icon_item(tex, tag.name) + + if not $"%TagList".is_connected("id_pressed", self, "_on_TagList_id_pressed"): + $"%TagList".connect("id_pressed", self, "_on_TagList_id_pressed") + $"%TagList".popup(Rect2(get_global_mouse_position(), Vector2.ONE)) + + +func _on_TagList_id_pressed(id: int) -> void: + var tag: AnimationTag = Global.current_project.animation_tags[id] + var frames = [] + for i in range(tag.from - 1, tag.to): + frames.append(i) + copy_frames(frames, Global.current_project.current_frame) + + func _on_FrameTagButton_pressed() -> void: find_node("FrameTagDialog").popup_centered() diff --git a/src/UI/Timeline/AnimationTimeline.tscn b/src/UI/Timeline/AnimationTimeline.tscn index 089afddac..fe87247aa 100644 --- a/src/UI/Timeline/AnimationTimeline.tscn +++ b/src/UI/Timeline/AnimationTimeline.tscn @@ -313,7 +313,7 @@ theme = SubResource( 20 ) scroll_vertical_enabled = false [node name="AnimationTools" type="PanelContainer" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer"] -margin_left = 159.0 +margin_left = 135.0 margin_right = 677.0 margin_bottom = 38.0 size_flags_horizontal = 10 @@ -321,7 +321,7 @@ size_flags_horizontal = 10 [node name="AnimationButtons" type="HBoxContainer" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools"] margin_left = 7.0 margin_top = 7.0 -margin_right = 511.0 +margin_right = 535.0 margin_bottom = 31.0 rect_min_size = Vector2( 0, 24 ) size_flags_horizontal = 3 @@ -332,7 +332,7 @@ __meta__ = { } [node name="FrameButtons" type="HBoxContainer" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons"] -margin_right = 140.0 +margin_right = 164.0 margin_bottom = 24.0 [node name="AddFrame" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]] @@ -411,12 +411,39 @@ margin_right = 5.0 margin_bottom = 7.0 texture = ExtResource( 27 ) -[node name="FrameTagButton" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]] +[node name="CopyTag" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]] margin_left = 72.0 margin_top = 2.0 margin_right = 92.0 margin_bottom = 22.0 rect_min_size = Vector2( 20, 0 ) +hint_tooltip = "Clone an Existing Tag" +mouse_default_cursor_shape = 2 +size_flags_horizontal = 0 +size_flags_vertical = 4 + +[node name="TextureRect" type="TextureRect" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/CopyTag"] +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +margin_left = -5.0 +margin_top = -7.0 +margin_right = 5.0 +margin_bottom = 7.0 +texture = ExtResource( 27 ) + +[node name="TagList" type="PopupMenu" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/CopyTag"] +unique_name_in_owner = true +margin_right = 20.0 +margin_bottom = 20.0 + +[node name="FrameTagButton" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]] +margin_left = 96.0 +margin_top = 2.0 +margin_right = 116.0 +margin_bottom = 22.0 +rect_min_size = Vector2( 20, 0 ) hint_tooltip = "Manage frame tags" focus_mode = 0 mouse_default_cursor_shape = 2 @@ -438,9 +465,9 @@ __meta__ = { } [node name="MoveLeft" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]] -margin_left = 96.0 +margin_left = 120.0 margin_top = 2.0 -margin_right = 116.0 +margin_right = 140.0 margin_bottom = 22.0 rect_min_size = Vector2( 20, 0 ) hint_tooltip = "Move the selected frame to the left." @@ -465,9 +492,9 @@ __meta__ = { } [node name="MoveRight" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]] -margin_left = 120.0 +margin_left = 144.0 margin_top = 2.0 -margin_right = 140.0 +margin_right = 164.0 margin_bottom = 22.0 rect_min_size = Vector2( 20, 0 ) hint_tooltip = "Move the selected frame to the right." @@ -488,8 +515,8 @@ margin_bottom = 5.5 texture = ExtResource( 8 ) [node name="PlaybackButtons" type="HBoxContainer" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons"] -margin_left = 180.0 -margin_right = 320.0 +margin_left = 204.0 +margin_right = 344.0 margin_bottom = 24.0 [node name="FirstFrame" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/PlaybackButtons" groups=["UIButtons"]] @@ -663,8 +690,8 @@ __meta__ = { } [node name="LoopButtons" type="HBoxContainer" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons"] -margin_left = 360.0 -margin_right = 504.0 +margin_left = 384.0 +margin_right = 528.0 margin_bottom = 24.0 [node name="OnionSkinningSettings" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/LoopButtons" groups=["UIButtons"]] @@ -987,6 +1014,7 @@ color = Color( 0, 0.741176, 1, 0.501961 ) [connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/AddFrame" to="." method="add_frame"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/DeleteFrame" to="." method="_on_DeleteFrame_pressed"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/CopyFrame" to="." method="_on_CopyFrame_pressed"] +[connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/CopyTag" to="." method="_on_CopyTag_pressed"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/FrameTagButton" to="." method="_on_FrameTagButton_pressed"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/MoveLeft" to="." method="_on_MoveLeft_pressed"] [connection signal="pressed" from="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons/MoveRight" to="." method="_on_MoveRight_pressed"]