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

[Continuation] Auto select cloned frames, reuse tag animations #861

Merged
merged 35 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8db9e6e
Duplicated frames
Variable-ind May 16, 2023
1f96aa1
Added Clone Tag feature
Variable-ind May 17, 2023
cdd2017
fix remaining tag issues
Variable-ind May 17, 2023
378a5f5
Update AnimationTimeline.gd
Variable-ind May 17, 2023
7429a95
formatting
Variable-ind May 17, 2023
fe21da6
formatting
Variable-ind May 17, 2023
5a39035
add icon and other remaining stuff
Variable-ind May 17, 2023
39ea228
formatting
Variable-ind May 17, 2023
3463a17
formatting
Variable-ind May 17, 2023
8fed73b
Update AnimationTimeline.gd
Variable-ind May 17, 2023
1073635
Update AnimationTimeline.gd
Variable-ind May 17, 2023
dd23394
some bug fixes
Variable-ind May 17, 2023
dee18a7
some bug fixes
Variable-ind May 17, 2023
b73d7ab
make empty tags appear as (Untitled)
Variable-ind May 17, 2023
d38e0c6
Merge branch 'Orama-Interactive:master' into select_frames
Variable-ind May 17, 2023
a907803
linting
Variable-ind May 17, 2023
e5fc0c7
Delete copy_frame.png
Variable-ind May 17, 2023
4836c92
Delete copy_tag.png
Variable-ind May 17, 2023
9529174
Add files via upload
Variable-ind May 17, 2023
3b9a0c2
removed separate button and use tag button
Variable-ind May 17, 2023
4076459
UI improvements to
Variable-ind May 18, 2023
9d03cc9
Merge branch 'master' into select_frames
Variable-ind May 18, 2023
1c952c5
remove some lines that appeared
Variable-ind May 18, 2023
3541cc4
Update AnimationTimeline.gd
Variable-ind May 18, 2023
d54753c
moved paste tag code to it's own script
Variable-ind May 18, 2023
032b702
Merge branch 'Orama-Interactive:master' into select_frames
Variable-ind May 18, 2023
02b0a96
formatting
Variable-ind May 18, 2023
1902938
Add files via upload
Variable-ind May 18, 2023
cdf7913
Merge branch 'Orama-Interactive:master' into select_frames
Variable-ind May 19, 2023
2a6ef83
test lint disabling
Variable-ind May 19, 2023
e0a2fdc
Update AnimationTimeline.gd
Variable-ind May 19, 2023
224e7ed
increase max file lines to 2000
Variable-ind May 19, 2023
bc9795f
Merge branch 'Orama-Interactive:master' into select_frames
Variable-ind May 26, 2023
b5ba9b3
Merge branch 'Orama-Interactive:master' into select_frames
Variable-ind Jun 15, 2023
cd4d558
Removed accidental changes by commit:.....
Variable-ind Jun 15, 2023
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
2 changes: 2 additions & 0 deletions .gdlintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
disable:
- no-elif-return
- no-else-return

max-file-lines: 2000
51 changes: 30 additions & 21 deletions src/UI/Timeline/AnimationTimeline.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func _ready() -> void:
frame_scroll_bar.connect("value_changed", self, "_frame_scroll_changed")
Global.animation_timer.wait_time = 1 / Global.current_project.fps
fps_spinbox.value = Global.current_project.fps

# config loading
layer_frame_h_split.split_offset = Global.config_cache.get_value("timeline", "layer_size", 0)
self.cel_size = Global.config_cache.get_value("timeline", "cel_size", cel_size) # Call setter
Expand All @@ -62,7 +61,6 @@ func _ready() -> void:
# emit signals that were supposed to be emitted (Check if it's still required in godot 4)
$"%PastPlacement".emit_signal("item_selected", 0 if past_above else 1)
$"%FuturePlacement".emit_signal("item_selected", 0 if future_above else 1)

# Makes sure that the frame and tag scroll bars are in the right place:
Global.layer_vbox.call_deferred("emit_signal", "resized")

Expand Down Expand Up @@ -151,10 +149,8 @@ func add_frame() -> void:
var project: Project = Global.current_project
var frame_add_index := project.current_frame + 1
var frame: Frame = project.new_empty_frame()

project.undos += 1
project.undo_redo.create_action("Add Frame")

for l in range(project.layers.size()):
if project.layers[l].new_cels_linked: # If the link button is pressed
var prev_cel: BaseCel = project.frames[project.current_frame].cels[l]
Expand Down Expand Up @@ -282,15 +278,19 @@ 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
# as project.animation_tags's classes. Needed for undo/redo to work properly.
Expand All @@ -301,16 +301,13 @@ func copy_frames(indices := []) -> void:
new_animation_tags[i].from,
new_animation_tags[i].to
)

project.undos += 1
project.undo_redo.create_action("Add Frame")

for f in indices:
var src_frame: Frame = project.frames[f]
var new_frame := Frame.new()
copied_frames.append(new_frame)

var src_frame: Frame = project.frames[f]

new_frame.duration = src_frame.duration
for l in range(project.layers.size()):
var src_cel: BaseCel = project.frames[f].cels[l] # Cel we're copying from, the source
Expand All @@ -322,9 +319,9 @@ func copy_frames(indices := []) -> void:
)
if src_cel.selected != null:
selected_id = src_cel.selected.id

else:
new_cel = src_cel.get_script().new()

if project.layers[l].new_cels_linked:
if src_cel.link_set == null:
src_cel.link_set = {}
Expand All @@ -337,29 +334,44 @@ func copy_frames(indices := []) -> void:
else:
new_cel.set_content(src_cel.copy_content())
new_cel.opacity = src_cel.opacity

if new_cel is Cel3D:
if selected_id in new_cel.object_properties.keys():
if selected_id != -1:
new_cel.selected = new_cel.get_object_from_id(selected_id)
new_frame.cels.append(new_cel)

# 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:
for tag in new_animation_tags: # Loop through the tags to see if the frame is in one
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

project.undo_redo.add_do_method(Global, "undo_or_redo", false)
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()
# 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 Expand Up @@ -423,7 +435,6 @@ func _on_PlayForward_toggled(button_pressed: bool) -> void:
Global.change_button_texturerect(Global.play_forward.get_child(0), "pause.png")
else:
Global.change_button_texturerect(Global.play_forward.get_child(0), "play.png")

play_animation(button_pressed, true)


Expand All @@ -432,7 +443,6 @@ func _on_PlayBackwards_toggled(button_pressed: bool) -> void:
Global.change_button_texturerect(Global.play_backwards.get_child(0), "pause.png")
else:
Global.change_button_texturerect(Global.play_backwards.get_child(0), "play_backwards.png")

play_animation(button_pressed, false)


Expand Down Expand Up @@ -927,7 +937,6 @@ func project_frame_added(frame: int) -> void:
frame_scroll_container.call_deferred( # Make it visible, yes 3 call_deferreds are required
"call_deferred", "call_deferred", "ensure_control_visible", button
)

var layer := Global.cel_vbox.get_child_count() - 1
for cel_hbox in Global.cel_vbox.get_children():
var cel_button = project.frames[frame].cels[layer].instantiate_cel_button()
Expand Down
54 changes: 29 additions & 25 deletions src/UI/Timeline/AnimationTimeline.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=44 format=2]
[gd_scene load_steps=45 format=2]

[ext_resource path="res://src/UI/Timeline/AnimationTimeline.gd" type="Script" id=1]
[ext_resource path="res://assets/graphics/layers/new.png" type="Texture" id=2]
Expand All @@ -11,6 +11,7 @@
[ext_resource path="res://src/UI/Nodes/ValueSlider.tscn" type="PackedScene" id=9]
[ext_resource path="res://assets/graphics/misc/value_arrow.svg" type="Texture" id=10]
[ext_resource path="res://src/UI/Timeline/FrameScrollContainer.gd" type="Script" id=11]
[ext_resource path="res://src/UI/Timeline/PasteTagPopup.gd" type="Script" id=12]
[ext_resource path="res://assets/graphics/timeline/new_frame.png" type="Texture" id=19]
[ext_resource path="res://assets/graphics/timeline/remove_frame.png" type="Texture" id=20]
[ext_resource path="res://assets/graphics/timeline/go_to_first_frame.png" type="Texture" id=21]
Expand All @@ -26,6 +27,27 @@
[ext_resource path="res://assets/graphics/timeline/loop.png" type="Texture" id=31]
[ext_resource path="res://src/UI/Timeline/FrameTagDialog.tscn" type="PackedScene" id=42]

[sub_resource type="StyleBoxEmpty" id=15]

[sub_resource type="StyleBoxEmpty" id=16]

[sub_resource type="StyleBoxEmpty" id=17]

[sub_resource type="StyleBoxEmpty" id=18]

[sub_resource type="StyleBoxEmpty" id=19]

[sub_resource type="Theme" id=20]
HScrollBar/icons/decrement = null
HScrollBar/icons/decrement_highlight = null
HScrollBar/icons/increment = null
HScrollBar/icons/increment_highlight = null
HScrollBar/styles/grabber = SubResource( 15 )
HScrollBar/styles/grabber_highlight = SubResource( 16 )
HScrollBar/styles/grabber_pressed = SubResource( 17 )
HScrollBar/styles/scroll = SubResource( 18 )
HScrollBar/styles/scroll_focus = SubResource( 19 )

[sub_resource type="InputEventAction" id=21]
action = "go_to_first_frame"

Expand Down Expand Up @@ -62,27 +84,6 @@ action = "go_to_last_frame"
[sub_resource type="ShortCut" id=14]
shortcut = SubResource( 22 )

[sub_resource type="StyleBoxEmpty" id=15]

[sub_resource type="StyleBoxEmpty" id=16]

[sub_resource type="StyleBoxEmpty" id=17]

[sub_resource type="StyleBoxEmpty" id=18]

[sub_resource type="StyleBoxEmpty" id=19]

[sub_resource type="Theme" id=20]
HScrollBar/icons/decrement = null
HScrollBar/icons/decrement_highlight = null
HScrollBar/icons/increment = null
HScrollBar/icons/increment_highlight = null
HScrollBar/styles/grabber = SubResource( 15 )
HScrollBar/styles/grabber_highlight = SubResource( 16 )
HScrollBar/styles/grabber_pressed = SubResource( 17 )
HScrollBar/styles/scroll = SubResource( 18 )
HScrollBar/styles/scroll_focus = SubResource( 19 )

[node name="AnimationTimeline" type="Panel"]
margin_right = 902.0
margin_bottom = 160.0
Expand Down Expand Up @@ -309,6 +310,7 @@ size_flags_horizontal = 3
margin_right = 677.0
margin_bottom = 38.0
size_flags_horizontal = 3
theme = SubResource( 20 )
Copy link
Member

@OverloadedOrama OverloadedOrama Jun 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the changes in the AnimationTimeline scene in this PR are undoing the changes in commit 361fe36, which removed the custom theme for the AnimationToolsScrollContainer node. I'd recommend merging the latest master branch to your branch (or rebasing), then reverting AnimationTimeline.tscn (to be the same as the master branch's), and then re-adding the new PasteTagPopup node, to ensure no conflicts will occurr.

scroll_vertical_enabled = false

[node name="AnimationTools" type="PanelContainer" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer"]
Expand Down Expand Up @@ -432,9 +434,6 @@ margin_top = -7.0
margin_right = 7.0
margin_bottom = 7.0
texture = ExtResource( 28 )
__meta__ = {
"_edit_use_anchors_": false
}

[node name="MoveLeft" type="Button" parent="TimelineContainer/TimelineButtons/VBoxContainer/AnimationToolsScrollContainer/AnimationTools/AnimationButtons/FrameButtons" groups=["UIButtons"]]
margin_left = 96.0
Expand Down Expand Up @@ -980,6 +979,11 @@ margin_bottom = 40.0
mouse_filter = 2
color = Color( 0, 0.741176, 1, 0.501961 )

[node name="PasteTagPopup" type="PopupMenu" parent="."]
margin_right = 20.0
margin_bottom = 20.0
script = ExtResource( 12 )

[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/VBoxContainer/LayerButtons/AddLayer" to="." method="add_layer" binds= [ 0 ]]
[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/VBoxContainer/LayerButtons/RemoveLayer" to="." method="_on_RemoveLayer_pressed"]
[connection signal="pressed" from="TimelineContainer/TimelineButtons/LayerTools/VBoxContainer/LayerButtons/MoveUpLayer" to="." method="change_layer_order" binds= [ true ]]
Expand Down
38 changes: 38 additions & 0 deletions src/UI/Timeline/PasteTagPopup.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
extends PopupMenu


func _ready() -> void:
var tag_container: Control = Global.animation_timeline.find_node("TagContainer")
connect("id_pressed", self, "_on_TagList_id_pressed")
tag_container.connect("gui_input", self, "_on_TagContainer_gui_input")


func _on_TagContainer_gui_input(event: InputEvent) -> void:
if !event is InputEventMouseButton:
return
if Input.is_action_just_released("right_mouse"):
clear()
if Global.current_project.animation_tags.empty():
return
add_separator("Paste content from tag:")
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)
var title = tag.name
if title == "":
title = "(Untitled)"
add_icon_item(tex, title)
var frame_idx = Global.current_project.current_frame + 2
add_separator(str("The pasted frames will start at (Frame ", frame_idx, ")"))
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 - 1]
var frames = []
for i in range(tag.from - 1, tag.to):
frames.append(i)
Global.animation_timeline.copy_frames(frames, Global.current_project.current_frame)