2021-06-04 23:11:22 +00:00
|
|
|
extends Button
|
|
|
|
|
|
|
|
var frame := 0
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
onready var popup_menu: PopupMenu = $PopupMenu
|
|
|
|
onready var frame_properties: ConfirmationDialog = Global.control.find_node("FrameProperties")
|
2021-06-04 23:37:33 +00:00
|
|
|
|
2021-06-04 23:11:22 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
connect("pressed", self, "_button_pressed")
|
|
|
|
|
|
|
|
|
|
|
|
func _button_pressed() -> void:
|
2021-06-04 23:37:33 +00:00
|
|
|
if Input.is_action_just_released("left_mouse"):
|
2021-07-08 17:46:56 +00:00
|
|
|
Global.canvas.selection.transform_content_confirm()
|
2021-11-25 12:48:30 +00:00
|
|
|
var prev_curr_frame: int = Global.current_project.current_frame
|
2021-06-11 22:06:13 +00:00
|
|
|
if Input.is_action_pressed("shift"):
|
|
|
|
var frame_diff_sign = sign(frame - prev_curr_frame)
|
|
|
|
if frame_diff_sign == 0:
|
|
|
|
frame_diff_sign = 1
|
|
|
|
for i in range(prev_curr_frame, frame + 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)
|
|
|
|
elif Input.is_action_pressed("ctrl"):
|
|
|
|
for j in range(0, Global.current_project.layers.size()):
|
|
|
|
var frame_layer := [frame, j]
|
|
|
|
if !Global.current_project.selected_cels.has(frame_layer):
|
|
|
|
Global.current_project.selected_cels.append(frame_layer)
|
2021-11-25 12:48:30 +00:00
|
|
|
else: # If the button is pressed without Shift or Control
|
2021-06-11 22:06:13 +00:00
|
|
|
Global.current_project.selected_cels.clear()
|
|
|
|
var frame_layer := [frame, Global.current_project.current_layer]
|
|
|
|
if !Global.current_project.selected_cels.has(frame_layer):
|
|
|
|
Global.current_project.selected_cels.append(frame_layer)
|
|
|
|
|
2021-06-04 23:37:33 +00:00
|
|
|
Global.current_project.current_frame = frame
|
2021-06-11 22:06:13 +00:00
|
|
|
|
2021-06-04 23:37:33 +00:00
|
|
|
elif Input.is_action_just_released("right_mouse"):
|
|
|
|
if Global.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 < Global.current_project.frames.size() - 1:
|
|
|
|
popup_menu.set_item_disabled(3, false)
|
|
|
|
popup_menu.popup(Rect2(get_global_mouse_position(), Vector2.ONE))
|
|
|
|
pressed = !pressed
|
2021-06-11 22:06:13 +00:00
|
|
|
elif Input.is_action_just_released("middle_mouse"):
|
2021-06-04 23:37:33 +00:00
|
|
|
pressed = !pressed
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.animation_timeline.delete_frame(frame)
|
|
|
|
else: # An example of this would be Space
|
2021-06-04 23:37:33 +00:00
|
|
|
pressed = !pressed
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_PopupMenu_id_pressed(id: int) -> void:
|
2021-06-04 23:37:33 +00:00
|
|
|
match id:
|
2021-11-25 12:48:30 +00:00
|
|
|
0: # Remove Frame
|
|
|
|
Global.animation_timeline.delete_frame(frame)
|
|
|
|
1: # Clone Frame
|
|
|
|
Global.animation_timeline.copy_frame(frame)
|
|
|
|
2: # Move Left
|
2021-06-04 23:37:33 +00:00
|
|
|
change_frame_order(-1)
|
2021-11-25 12:48:30 +00:00
|
|
|
3: # Move Right
|
2021-06-04 23:37:33 +00:00
|
|
|
change_frame_order(1)
|
2021-11-25 12:48:30 +00:00
|
|
|
4: # Frame Properties
|
2021-11-23 00:36:22 +00:00
|
|
|
frame_properties.popup_centered()
|
2021-06-04 23:37:33 +00:00
|
|
|
Global.dialog_open(true)
|
2021-11-23 00:36:22 +00:00
|
|
|
frame_properties.set_frame_label(frame)
|
|
|
|
frame_properties.set_frame_dur(Global.current_project.frames[frame].duration)
|
2021-06-04 23:37:33 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func change_frame_order(rate: int) -> void:
|
2021-06-04 23:37:33 +00:00
|
|
|
var change = frame + rate
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_frames: Array = Global.current_project.frames.duplicate()
|
2021-06-04 23:37:33 +00:00
|
|
|
var temp = new_frames[frame]
|
|
|
|
new_frames[frame] = new_frames[change]
|
|
|
|
new_frames[change] = temp
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.create_action("Change Frame Order")
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(
|
|
|
|
Global.current_project, "frames", Global.current_project.frames
|
|
|
|
)
|
2021-06-04 23:37:33 +00:00
|
|
|
|
|
|
|
if Global.current_project.current_frame == frame:
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_frame", change
|
|
|
|
)
|
2021-06-11 22:06:13 +00:00
|
|
|
else:
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_frame", Global.current_project.current_frame
|
|
|
|
)
|
2021-06-04 23:37:33 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(
|
|
|
|
Global.current_project, "current_frame", Global.current_project.current_frame
|
|
|
|
)
|
2021-06-04 23:37:33 +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-06-05 23:19:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
func get_drag_data(_position) -> Array:
|
|
|
|
var button := Button.new()
|
|
|
|
button.rect_size = rect_size
|
|
|
|
button.theme = Global.control.theme
|
|
|
|
button.text = text
|
|
|
|
set_drag_preview(button)
|
|
|
|
|
|
|
|
return ["Frame", frame]
|
|
|
|
|
|
|
|
|
|
|
|
func can_drop_data(_pos, data) -> bool:
|
|
|
|
if typeof(data) == TYPE_ARRAY:
|
|
|
|
return data[0] == "Frame"
|
|
|
|
else:
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
|
|
func drop_data(_pos, data) -> void:
|
|
|
|
var new_frame = data[1]
|
|
|
|
if frame == new_frame:
|
|
|
|
return
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var new_frames: Array = Global.current_project.frames.duplicate()
|
2021-06-05 23:19:34 +00:00
|
|
|
var temp = new_frames[frame]
|
|
|
|
new_frames[frame] = new_frames[new_frame]
|
|
|
|
new_frames[new_frame] = temp
|
|
|
|
|
|
|
|
Global.current_project.undo_redo.create_action("Change Frame Order")
|
|
|
|
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(
|
|
|
|
Global.current_project, "frames", Global.current_project.frames
|
|
|
|
)
|
2021-06-05 23:19:34 +00:00
|
|
|
|
2021-06-27 15:15:06 +00:00
|
|
|
if Global.current_project.current_frame == new_frame:
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_frame", frame
|
|
|
|
)
|
2021-06-27 15:15:06 +00:00
|
|
|
else:
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_do_property(
|
|
|
|
Global.current_project, "current_frame", Global.current_project.current_frame
|
|
|
|
)
|
2021-06-05 23:19:34 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
Global.current_project.undo_redo.add_undo_property(
|
|
|
|
Global.current_project, "current_frame", Global.current_project.current_frame
|
|
|
|
)
|
2021-06-05 23:19:34 +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()
|