2019-09-09 22:57:46 +00:00
|
|
|
extends Button
|
|
|
|
|
|
|
|
var frame := 0
|
2020-01-18 19:06:47 +00:00
|
|
|
var layer := 0
|
2020-02-10 22:06:24 +00:00
|
|
|
|
2020-04-22 16:01:33 +00:00
|
|
|
onready var popup_menu : PopupMenu = $PopupMenu
|
2019-09-09 22:57:46 +00:00
|
|
|
|
2020-04-17 21:35:42 +00:00
|
|
|
|
2020-02-28 01:27:22 +00:00
|
|
|
func _ready() -> void:
|
2021-01-30 21:57:33 +00:00
|
|
|
rect_min_size.x = Global.animation_timeline.cel_size
|
|
|
|
rect_min_size.y = Global.animation_timeline.cel_size
|
|
|
|
|
2020-08-27 17:02:53 +00:00
|
|
|
hint_tooltip = tr("Frame: %s, Layer: %s") % [frame + 1, layer]
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.frames[frame] in Global.current_project.layers[layer].linked_cels:
|
2020-03-18 00:02:41 +00:00
|
|
|
get_node("LinkedIndicator").visible = true
|
2020-04-22 16:01:33 +00:00
|
|
|
popup_menu.set_item_text(4, "Unlink Cel")
|
|
|
|
popup_menu.set_item_metadata(4, "Unlink Cel")
|
2020-03-18 00:57:23 +00:00
|
|
|
else:
|
|
|
|
get_node("LinkedIndicator").visible = false
|
2020-04-22 16:01:33 +00:00
|
|
|
popup_menu.set_item_text(4, "Link Cel")
|
|
|
|
popup_menu.set_item_metadata(4, "Link Cel")
|
2020-02-28 01:27:22 +00:00
|
|
|
|
2020-08-26 09:45:32 +00:00
|
|
|
# Reset the checkers size because it assumes you want the same size as the canvas
|
|
|
|
var checker = $CelTexture/TransparentChecker
|
|
|
|
checker.rect_size = checker.get_parent().rect_size
|
|
|
|
|
2020-04-17 21:35:42 +00:00
|
|
|
|
2021-01-30 21:57:33 +00:00
|
|
|
func _on_CelButton_resized() -> void:
|
|
|
|
get_node("CelTexture").rect_min_size.x = rect_min_size.x - 4
|
|
|
|
get_node("CelTexture").rect_min_size.y = rect_min_size.y - 4
|
|
|
|
|
|
|
|
get_node("LinkedIndicator").polygon[1].x = rect_min_size.x
|
|
|
|
get_node("LinkedIndicator").polygon[2].x = rect_min_size.x
|
|
|
|
get_node("LinkedIndicator").polygon[2].y = rect_min_size.y
|
|
|
|
get_node("LinkedIndicator").polygon[3].y = rect_min_size.y
|
|
|
|
|
|
|
|
|
2020-05-01 19:17:05 +00:00
|
|
|
func _on_CelButton_pressed() -> void:
|
2019-11-19 21:23:43 +00:00
|
|
|
if Input.is_action_just_released("left_mouse"):
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.current_frame = frame
|
|
|
|
Global.current_project.current_layer = layer
|
2019-12-21 02:20:55 +00:00
|
|
|
elif Input.is_action_just_released("right_mouse"):
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.frames.size() == 1:
|
2019-11-19 21:23:43 +00:00
|
|
|
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)
|
2020-06-04 18:05:36 +00:00
|
|
|
if frame < Global.current_project.frames.size() - 1:
|
2019-11-19 21:23:43 +00:00
|
|
|
popup_menu.set_item_disabled(3, false)
|
|
|
|
popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE))
|
|
|
|
pressed = !pressed
|
2020-04-18 23:27:23 +00:00
|
|
|
elif Input.is_action_just_released("middle_mouse"): # Middle mouse click
|
2019-12-21 02:20:55 +00:00
|
|
|
pressed = !pressed
|
2020-04-17 21:35:42 +00:00
|
|
|
Global.animation_timeline._on_DeleteFrame_pressed(frame)
|
2020-04-18 23:27:23 +00:00
|
|
|
else: # An example of this would be Space
|
|
|
|
pressed = !pressed
|
2020-04-17 21:35:42 +00:00
|
|
|
|
2019-11-19 21:23:43 +00:00
|
|
|
|
|
|
|
func _on_PopupMenu_id_pressed(ID : int) -> void:
|
|
|
|
match ID:
|
2020-02-22 15:00:39 +00:00
|
|
|
0: # Remove Frame
|
2020-04-17 21:35:42 +00:00
|
|
|
Global.animation_timeline._on_DeleteFrame_pressed(frame)
|
2020-03-03 01:05:48 +00:00
|
|
|
1: # Clone Frame
|
2020-04-17 01:25:08 +00:00
|
|
|
Global.animation_timeline._on_CopyFrame_pressed(frame)
|
2020-03-03 01:05:48 +00:00
|
|
|
2: # Move Left
|
2019-11-19 21:23:43 +00:00
|
|
|
change_frame_order(-1)
|
2020-03-03 01:05:48 +00:00
|
|
|
3: # Move Right
|
2019-11-19 21:23:43 +00:00
|
|
|
change_frame_order(1)
|
2020-04-07 21:46:45 +00:00
|
|
|
4: # Unlink Cel
|
2020-06-04 18:05:36 +00:00
|
|
|
var cel_index : int = Global.current_project.layers[layer].linked_cels.find(Global.current_project.frames[frame])
|
|
|
|
var f = Global.current_project.frames[frame]
|
|
|
|
var new_layers : Array = Global.current_project.layers.duplicate()
|
2020-06-02 02:14:05 +00:00
|
|
|
# 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)
|
2020-06-02 23:14:24 +00:00
|
|
|
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)
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-04-22 16:01:33 +00:00
|
|
|
if popup_menu.get_item_metadata(4) == "Unlink Cel":
|
2020-06-01 13:42:53 +00:00
|
|
|
new_layers[layer].linked_cels.remove(cel_index)
|
2020-04-22 16:01:33 +00:00
|
|
|
var sprite := Image.new()
|
2020-06-04 18:05:36 +00:00
|
|
|
sprite.copy_from(Global.current_project.frames[frame].cels[layer].image)
|
2020-04-22 16:01:33 +00:00
|
|
|
sprite.lock()
|
2020-06-02 23:14:24 +00:00
|
|
|
new_cels[layer].image = sprite
|
2020-04-21 18:34:45 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.create_action("Unlink Cel")
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
|
|
|
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-04-21 18:34:45 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-04-22 16:01:33 +00:00
|
|
|
elif popup_menu.get_item_metadata(4) == "Link Cel":
|
2020-06-04 18:05:36 +00:00
|
|
|
new_layers[layer].linked_cels.append(Global.current_project.frames[frame])
|
|
|
|
Global.current_project.undo_redo.create_action("Link Cel")
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
|
2020-06-01 13:42:53 +00:00
|
|
|
if new_layers[layer].linked_cels.size() > 1:
|
2020-04-22 16:01:33 +00:00
|
|
|
# If there are already linked cels, set the current cel's image
|
|
|
|
# to the first linked cel's image
|
2020-06-02 23:14:24 +00:00
|
|
|
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
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-04-22 16:01:33 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "layers", Global.current_project.layers)
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2020-12-10 18:39:29 +00:00
|
|
|
5: # Frame Properties
|
2020-10-19 14:57:40 +00:00
|
|
|
Global.frame_properties.popup_centered()
|
|
|
|
Global.dialog_open(true)
|
|
|
|
Global.frame_properties.set_frame_label(frame)
|
2020-12-16 20:54:08 +00:00
|
|
|
Global.frame_properties.set_frame_dur(Global.current_project.frames[frame].duration)
|
2019-12-21 02:20:55 +00:00
|
|
|
|
2021-01-29 20:00:48 +00:00
|
|
|
|
2019-11-19 21:23:43 +00:00
|
|
|
func change_frame_order(rate : int) -> void:
|
|
|
|
var change = frame + rate
|
2020-06-04 18:05:36 +00:00
|
|
|
var new_frames : Array = Global.current_project.frames.duplicate()
|
2020-06-02 23:14:24 +00:00
|
|
|
var temp = new_frames[frame]
|
|
|
|
new_frames[frame] = new_frames[change]
|
|
|
|
new_frames[change] = temp
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.create_action("Change Frame Order")
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
if Global.current_project.current_frame == frame:
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", change)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
|
2020-03-06 20:44:48 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "frames", Global.current_project.frames)
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-06-04 18:05:36 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
|
|
|
Global.current_project.undo_redo.commit_action()
|
2021-01-29 20:00:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
func get_drag_data(_position) -> Array:
|
|
|
|
var button := Button.new()
|
|
|
|
button.rect_size = rect_size
|
|
|
|
button.theme = Global.control.theme
|
|
|
|
var texture_rect := TextureRect.new()
|
|
|
|
texture_rect.rect_size = $CelTexture.rect_size
|
|
|
|
texture_rect.rect_position = $CelTexture.rect_position
|
|
|
|
texture_rect.expand = true
|
|
|
|
texture_rect.texture = $CelTexture.texture
|
|
|
|
button.add_child(texture_rect)
|
|
|
|
set_drag_preview(button)
|
|
|
|
|
|
|
|
return [frame, layer]
|
|
|
|
|
|
|
|
|
|
|
|
func can_drop_data(_pos, data) -> bool:
|
|
|
|
if typeof(data) == TYPE_ARRAY:
|
|
|
|
var new_frame = data[0]
|
|
|
|
var new_layer = data[1]
|
|
|
|
if Global.current_project.frames[frame] in Global.current_project.layers[layer].linked_cels or Global.current_project.frames[new_frame] in Global.current_project.layers[new_layer].linked_cels:
|
|
|
|
# If the cel we're dragging or the cel we are targeting are linked, don't allow dragging
|
|
|
|
return false
|
|
|
|
else:
|
|
|
|
return true
|
|
|
|
else:
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
func drop_data(_pos, data) -> void:
|
|
|
|
var new_frame = data[0]
|
|
|
|
var new_layer = data[1]
|
|
|
|
|
|
|
|
var this_frame_new_cels = Global.current_project.frames[frame].cels.duplicate()
|
|
|
|
var new_frame_new_cels
|
|
|
|
var temp = this_frame_new_cels[layer]
|
|
|
|
this_frame_new_cels[layer] = Global.current_project.frames[new_frame].cels[new_layer]
|
|
|
|
if frame == new_frame:
|
|
|
|
this_frame_new_cels[new_layer] = temp
|
|
|
|
else:
|
|
|
|
new_frame_new_cels = Global.current_project.frames[new_frame].cels.duplicate()
|
|
|
|
new_frame_new_cels[new_layer] = temp
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.create_action("Move Cels")
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project.frames[frame], "cels", this_frame_new_cels)
|
|
|
|
|
|
|
|
if frame != new_frame: # If the cel moved to a different frame
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project.frames[new_frame], "cels", new_frame_new_cels)
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", frame)
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_frame", Global.current_project.current_frame)
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project.frames[new_frame], "cels", Global.current_project.frames[new_frame].cels)
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.add_undo_property(Global.current_project.frames[frame], "cels", Global.current_project.frames[frame].cels)
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.current_project.undo_redo.add_do_method(Global, "redo")
|
|
|
|
Global.current_project.undo_redo.commit_action()
|