Removed more animation related code.

This commit is contained in:
Relintai 2020-11-29 23:31:43 +01:00
parent 3098b48301
commit 42d5b1daa7
7 changed files with 36 additions and 232 deletions

View File

@ -116,9 +116,7 @@ var patterns_popup : Popup
var animation_timeline : Panel
var frame_ids : HBoxContainer
var layers_container : VBoxContainer
var frames_container : VBoxContainer
var tag_container : Control
var tag_dialog : AcceptDialog
@ -219,8 +217,6 @@ func refresh_nodes():
animation_timeline = find_node_by_name(control, "AnimationTimeline")
layers_container = find_node_by_name(animation_timeline, "LayersContainer")
frames_container = find_node_by_name(animation_timeline, "FramesContainer")
frame_ids = find_node_by_name(animation_timeline, "FrameIDs")
tag_container = find_node_by_name(animation_timeline, "TagContainer")
tag_dialog = find_node_by_name(animation_timeline, "FrameTagDialog")

View File

@ -98,12 +98,6 @@ func change_project() -> void:
for container in DrawGD.layers_container.get_children():
container.queue_free()
remove_cel_buttons()
for frame_id in DrawGD.frame_ids.get_children():
DrawGD.frame_ids.remove_child(frame_id)
frame_id.queue_free()
# Create new ones
for i in range(layers.size() - 1, -1, -1):
# Create layer buttons
@ -115,28 +109,8 @@ func change_project() -> void:
DrawGD.layers_container.add_child(layer_container)
layer_container.label.text = layers[i].name
layer_container.line_edit.text = layers[i].name
DrawGD.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()): # Create Cel buttons
var cel_button = load("res://addons/draw_gd/src/UI/Timeline/CelButton.tscn").instance()
cel_button.frame = j
cel_button.layer = i
cel_button.texture = frames[j].cels[i].image_texture
if j == current_frame and i == current_layer:
cel_button.pressed = true
layers[i].frame_container.add_child(cel_button)
for j in range(frames.size()): # Create frame ID labels
var label := Label.new()
label.rect_min_size.x = 36
label.align = Label.ALIGN_CENTER
label.text = str(j + 1)
#if j == current_frame:
#label.add_color_override("font_color", DrawGD.control.theme.get_color("Selected Color", "Label"))
DrawGD.frame_ids.add_child(label)
layer_container.cel_button.texture = frames[0].cels[0].image_texture
var layer_button = DrawGD.layers_container.get_child(DrawGD.layers_container.get_child_count() - 1 - current_layer)
layer_button.pressed = true
@ -350,7 +324,6 @@ func size_changed(value : Vector2) -> void:
func frames_changed(value : Array) -> void:
frames = value
remove_cel_buttons()
for frame_id in DrawGD.frame_ids.get_children():
DrawGD.frame_ids.remove_child(frame_id)
@ -384,8 +357,6 @@ func layers_changed(value : Array) -> void:
for container in DrawGD.layers_container.get_children():
container.queue_free()
remove_cel_buttons()
for i in range(layers.size() - 1, -1, -1):
var layer_container = load("res://addons/draw_gd/src/UI/Timeline/LayerButton.tscn").instance()
layer_container.i = i
@ -398,30 +369,16 @@ func layers_changed(value : Array) -> void:
DrawGD.layers_container.add_child(layer_container)
layer_container.label.text = layers[i].name
layer_container.line_edit.text = layers[i].name
if frames.size() > 0:
layer_container.cel_button.texture = frames[0].cels[0].image_texture
DrawGD.frames_container.add_child(layers[i].frame_container)
for j in range(frames.size()):
var cel_button = load("res://addons/draw_gd/src/UI/Timeline/CelButton.tscn").instance()
cel_button.frame = j
cel_button.layer = i
cel_button.texture = frames[j].cels[i].image_texture
layers[i].frame_container.add_child(cel_button)
var layer_button = DrawGD.layers_container.get_child(DrawGD.layers_container.get_child_count() - 1 - current_layer)
layer_button.pressed = true
self.current_frame = current_frame # Call frame_changed to update UI
toggle_layer_buttons_layers()
func remove_cel_buttons() -> void:
for container in DrawGD.frames_container.get_children():
for button in container.get_children():
container.remove_child(button)
button.queue_free()
DrawGD.frames_container.remove_child(container)
func frame_changed(value : int) -> void:
current_frame = value
@ -429,7 +386,7 @@ func frame_changed(value : int) -> void:
var text_color := Color.white
if DrawGD.theme_type == DrawGD.Theme_Types.CARAMEL || DrawGD.theme_type == DrawGD.Theme_Types.LIGHT:
text_color = Color.black
DrawGD.frame_ids.get_child(i).add_color_override("font_color", text_color)
for layer in layers: # De-select all the other frames
if i < layer.frame_container.get_child_count():
layer.frame_container.get_child(i).pressed = false

View File

@ -292,16 +292,18 @@ margin_bottom = 123.0
size_flags_vertical = 3
[node name="LayersAndFrames" type="HBoxContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll"]
margin_right = 252.0
margin_right = 888.0
margin_bottom = 116.0
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="LayerVBoxCont" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames"]
margin_right = 212.0
margin_right = 888.0
margin_bottom = 116.0
size_flags_horizontal = 3
[node name="LayerLabel" type="Label" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames/LayerVBoxCont"]
margin_right = 212.0
margin_right = 888.0
margin_bottom = 16.0
rect_min_size = Vector2( 0, 16 )
text = "Layers"
@ -310,34 +312,12 @@ valign = 1
[node name="LayersContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames/LayerVBoxCont"]
margin_top = 20.0
margin_right = 212.0
margin_right = 888.0
margin_bottom = 56.0
size_flags_horizontal = 3
[node name="LayerContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames/LayerVBoxCont/LayersContainer" instance=ExtResource( 18 )]
margin_right = 212.0
[node name="FrameButtonsAndIds" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames"]
margin_left = 216.0
margin_right = 252.0
margin_bottom = 116.0
[node name="FrameIDs" type="HBoxContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames/FrameButtonsAndIds"]
margin_right = 36.0
margin_bottom = 16.0
rect_min_size = Vector2( 0, 16 )
[node name="Label" type="Label" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames/FrameButtonsAndIds/FrameIDs"]
margin_top = 1.0
margin_right = 36.0
margin_bottom = 15.0
rect_min_size = Vector2( 36, 0 )
text = "1"
align = 1
[node name="FramesContainer" type="VBoxContainer" parent="AnimationContainer/TimelineContainer/PanelContainer/TimelineScroll/LayersAndFrames/FrameButtonsAndIds"]
margin_top = 20.0
margin_right = 36.0
margin_bottom = 20.0
margin_right = 888.0
[node name="AnimationTimer" type="Timer" parent="."]

View File

@ -1,15 +1,10 @@
tool
extends Button
var frame := 0
var layer := 0
extends Control
var texture : TextureRect = null
var DrawGD : Node = null
var popup_menu : PopupMenu = null
func _enter_tree() -> void:
var n : Node = get_parent()
while n:
@ -18,117 +13,5 @@ func _enter_tree() -> void:
break
n = n.get_parent()
popup_menu = get_node("PopupMenu")
texture = get_node("MC/CelTexture")
hint_tooltip = tr("Frame: %s, Layer: %s") % [frame + 1, layer]
if DrawGD.current_project.frames[frame] in DrawGD.current_project.layers[layer].linked_cels:
get_node("LinkedIndicator").visible = true
popup_menu.set_item_text(4, "Unlink Cel")
popup_menu.set_item_metadata(4, "Unlink Cel")
else:
get_node("LinkedIndicator").visible = false
popup_menu.set_item_text(4, "Link Cel")
popup_menu.set_item_metadata(4, "Link Cel")
func _on_CelButton_pressed() -> void:
if Input.is_action_just_released("left_mouse"):
DrawGD.current_project.current_frame = frame
DrawGD.current_project.current_layer = layer
elif Input.is_action_just_released("right_mouse"):
if DrawGD.current_project.frames.size() == 1:
popup_menu.set_item_disabled(0, true)
popup_menu.set_item_disabled(2, true)
popup_menu.set_item_disabled(3, true)
else:
popup_menu.set_item_disabled(0, false)
if frame > 0:
popup_menu.set_item_disabled(2, false)
if frame < DrawGD.current_project.frames.size() - 1:
popup_menu.set_item_disabled(3, false)
popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE))
pressed = !pressed
elif Input.is_action_just_released("middle_mouse"): # Middle mouse click
pressed = !pressed
DrawGD.animation_timeline._on_DeleteFrame_pressed(frame)
else: # An example of this would be Space
pressed = !pressed
func _on_PopupMenu_id_pressed(ID : int) -> void:
match ID:
0: # Remove Frame
DrawGD.animation_timeline._on_DeleteFrame_pressed(frame)
1: # Clone Frame
DrawGD.animation_timeline._on_CopyFrame_pressed(frame)
2: # Move Left
change_frame_order(-1)
3: # Move Right
change_frame_order(1)
4: # Unlink Cel
var cel_index : int = DrawGD.current_project.layers[layer].linked_cels.find(DrawGD.current_project.frames[frame])
var f = DrawGD.current_project.frames[frame]
var new_layers : Array = DrawGD.current_project.layers.duplicate()
# Loop through the array to create new classes for each element, so that they
# won't be the same as the original array's classes. Needed for undo/redo to work properly.
for i in new_layers.size():
var new_linked_cels = new_layers[i].linked_cels.duplicate()
new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels)
var new_cels : Array = f.cels.duplicate()
for i in new_cels.size():
new_cels[i] = Cel.new(new_cels[i].image, new_cels[i].opacity)
if popup_menu.get_item_metadata(4) == "Unlink Cel":
new_layers[layer].linked_cels.remove(cel_index)
var sprite := Image.new()
sprite.copy_from(DrawGD.current_project.frames[frame].cels[layer].image)
sprite.lock()
new_cels[layer].image = sprite
DrawGD.current_project.undo_redo.create_action("Unlink Cel")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
elif popup_menu.get_item_metadata(4) == "Link Cel":
new_layers[layer].linked_cels.append(DrawGD.current_project.frames[frame])
DrawGD.current_project.undo_redo.create_action("Link Cel")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "layers", new_layers)
if new_layers[layer].linked_cels.size() > 1:
# If there are already linked cels, set the current cel's image
# to the first linked cel's image
new_cels[layer].image = new_layers[layer].linked_cels[0].cels[layer].image
new_cels[layer].image_texture = new_layers[layer].linked_cels[0].cels[layer].image_texture
DrawGD.current_project.undo_redo.add_do_property(f, "cels", new_cels)
DrawGD.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "layers", DrawGD.current_project.layers)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()
func change_frame_order(rate : int) -> void:
var change = frame + rate
var new_frames : Array = DrawGD.current_project.frames.duplicate()
var temp = new_frames[frame]
new_frames[frame] = new_frames[change]
new_frames[change] = temp
DrawGD.current_project.undo_redo.create_action("Change Frame Order")
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "frames", new_frames)
if DrawGD.current_project.current_frame == frame:
DrawGD.current_project.undo_redo.add_do_property(DrawGD.current_project, "current_frame", change)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "current_frame", DrawGD.current_project.current_frame)
DrawGD.current_project.undo_redo.add_undo_property(DrawGD.current_project, "frames", DrawGD.current_project.frames)
DrawGD.current_project.undo_redo.add_undo_method(DrawGD, "undo")
DrawGD.current_project.undo_redo.add_do_method(DrawGD, "redo")
DrawGD.current_project.undo_redo.commit_action()

View File

@ -3,23 +3,18 @@
[ext_resource path="res://addons/draw_gd/src/UI/Timeline/CelButton.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/src/UI/TransparentChecker.tscn" type="PackedScene" id=2]
[node name="CelButton" type="Button"]
[node name="CelButton" type="MarginContainer"]
margin_top = 18.0
margin_right = 36.0
margin_bottom = 54.0
rect_min_size = Vector2( 36, 36 )
hint_tooltip = "Frame: 1, Layer: 0"
mouse_filter = 2
mouse_default_cursor_shape = 2
toggle_mode = true
button_mask = 7
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MC2" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 36.0
margin_bottom = 36.0
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
@ -32,8 +27,8 @@ size_flags_horizontal = 3
size_flags_vertical = 3
[node name="MC" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_right = 36.0
margin_bottom = 36.0
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
@ -50,19 +45,3 @@ stretch_mode = 6
__meta__ = {
"_edit_use_anchors_": false
}
[node name="PopupMenu" type="PopupMenu" parent="."]
margin_right = 20.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
items = [ "Remove Frame", null, 0, false, true, -1, 0, null, "", false, "Clone Frame", null, 0, false, false, -1, 0, null, "", false, "Move Left", null, 0, false, true, -1, 0, null, "", false, "Move Right", null, 0, false, true, -1, 0, null, "", false, "Link Cel", null, 0, false, false, -1, 0, null, "", false ]
[node name="LinkedIndicator" type="Polygon2D" parent="."]
visible = false
color = Color( 0.0627451, 0.741176, 0.215686, 1 )
invert_enable = true
invert_border = 1.0
polygon = PoolVector2Array( 0, 0, 36, 0, 36, 36, 0, 36 )
[connection signal="pressed" from="." to="." method="_on_CelButton_pressed"]
[connection signal="id_pressed" from="PopupMenu" to="." method="_on_PopupMenu_id_pressed"]

View File

@ -8,6 +8,7 @@ var lock_button : BaseButton
var linked_button : BaseButton
var label : Label
var line_edit : LineEdit
var cel_button : Node
var DrawGD : Node = null
@ -25,6 +26,7 @@ func _enter_tree() -> void:
init()
func init():
cel_button = $HBoxContainer/CelButton
visibility_button = DrawGD.find_node_by_name(self, "VisibilityButton")
lock_button = DrawGD.find_node_by_name(self, "LockButton")
linked_button = DrawGD.find_node_by_name(self, "LinkButton")

View File

@ -1,15 +1,16 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=6 format=2]
[ext_resource path="res://addons/draw_gd/src/UI/Timeline/LayerButton.gd" type="Script" id=1]
[ext_resource path="res://addons/draw_gd/assets/graphics/dark_themes/layers/layer_visible.png" type="Texture" id=2]
[ext_resource path="res://addons/draw_gd/assets/graphics/dark_themes/layers/unlock.png" type="Texture" id=3]
[ext_resource path="res://addons/draw_gd/assets/graphics/dark_themes/layers/unlinked_layer.png" type="Texture" id=4]
[ext_resource path="res://addons/draw_gd/src/UI/Timeline/CelButton.tscn" type="PackedScene" id=5]
[node name="LayerContainer" type="Button"]
margin_right = 210.0
margin_right = 262.0
margin_bottom = 36.0
rect_min_size = Vector2( 212, 36 )
size_flags_horizontal = 0
size_flags_horizontal = 3
toggle_mode = true
action_mode = 0
script = ExtResource( 1 )
@ -26,12 +27,18 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="CelButton" parent="HBoxContainer" instance=ExtResource( 5 )]
margin_top = 0.0
margin_bottom = 36.0
[node name="EmptySpacer" type="Control" parent="HBoxContainer"]
margin_left = 40.0
margin_right = 40.0
margin_bottom = 36.0
[node name="LayerButtons" type="HBoxContainer" parent="HBoxContainer"]
margin_left = 4.0
margin_right = 108.0
margin_left = 44.0
margin_right = 148.0
margin_bottom = 36.0
[node name="VisibilityButton" type="Button" parent="HBoxContainer/LayerButtons" groups=[
@ -138,8 +145,8 @@ __meta__ = {
}
[node name="LayerName" type="HBoxContainer" parent="HBoxContainer"]
margin_left = 112.0
margin_right = 216.0
margin_left = 152.0
margin_right = 256.0
margin_bottom = 36.0
rect_min_size = Vector2( 104, 0 )
mouse_default_cursor_shape = 2