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:
|
2020-04-11 17:10:07 +00:00
|
|
|
hint_tooltip = "Frame: %s, Layer: %s" % [frame + 1, layer]
|
2020-06-02 23:14:24 +00:00
|
|
|
if Global.frames[frame] in Global.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-04-17 21:35:42 +00:00
|
|
|
|
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"):
|
|
|
|
Global.current_frame = frame
|
2020-01-18 19:06:47 +00:00
|
|
|
Global.current_layer = layer
|
2019-12-21 02:20:55 +00:00
|
|
|
elif Input.is_action_just_released("right_mouse"):
|
2020-06-02 23:14:24 +00:00
|
|
|
if Global.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-02 23:14:24 +00:00
|
|
|
if frame < Global.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-02 23:14:24 +00:00
|
|
|
var cel_index : int = Global.layers[layer].linked_cels.find(Global.frames[frame])
|
|
|
|
var f = Global.frames[frame]
|
2020-06-02 02:14:05 +00:00
|
|
|
var new_layers : Array = Global.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)
|
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-02 23:14:24 +00:00
|
|
|
sprite.copy_from(Global.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-04-22 16:01:33 +00:00
|
|
|
Global.undo_redo.create_action("Unlink Cel")
|
|
|
|
Global.undo_redo.add_do_property(Global, "layers", new_layers)
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
2020-04-22 16:01:33 +00:00
|
|
|
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-04-21 18:34:45 +00:00
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.undo_redo.add_do_method(Global, "redo")
|
2020-04-22 16:01:33 +00:00
|
|
|
Global.undo_redo.commit_action()
|
|
|
|
elif popup_menu.get_item_metadata(4) == "Link Cel":
|
2020-06-02 23:14:24 +00:00
|
|
|
new_layers[layer].linked_cels.append(Global.frames[frame])
|
2020-04-22 16:01:33 +00:00
|
|
|
Global.undo_redo.create_action("Link Cel")
|
|
|
|
Global.undo_redo.add_do_property(Global, "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
|
|
|
|
Global.undo_redo.add_do_property(f, "cels", new_cels)
|
|
|
|
Global.undo_redo.add_undo_property(f, "cels", f.cels)
|
2020-04-22 16:01:33 +00:00
|
|
|
|
|
|
|
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.undo_redo.add_do_method(Global, "redo")
|
2020-04-22 16:01:33 +00:00
|
|
|
Global.undo_redo.commit_action()
|
2020-03-21 20:55:36 +00:00
|
|
|
|
2019-12-21 02:20:55 +00:00
|
|
|
|
2019-11-19 21:23:43 +00:00
|
|
|
func change_frame_order(rate : int) -> void:
|
|
|
|
var change = frame + rate
|
2020-06-02 23:14:24 +00:00
|
|
|
var new_frames : Array = Global.frames.duplicate()
|
|
|
|
var temp = new_frames[frame]
|
|
|
|
new_frames[frame] = new_frames[change]
|
|
|
|
new_frames[change] = temp
|
2019-11-19 21:23:43 +00:00
|
|
|
|
|
|
|
Global.undo_redo.create_action("Change Frame Order")
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_do_property(Global, "frames", new_frames)
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-03-06 20:44:48 +00:00
|
|
|
if Global.current_frame == frame:
|
|
|
|
Global.undo_redo.add_do_property(Global, "current_frame", change)
|
|
|
|
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
|
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_undo_property(Global, "frames", Global.frames)
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-06-02 23:14:24 +00:00
|
|
|
Global.undo_redo.add_undo_method(Global, "undo")
|
|
|
|
Global.undo_redo.add_do_method(Global, "redo")
|
2019-11-20 12:42:52 +00:00
|
|
|
Global.undo_redo.commit_action()
|