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
|
|
|
|
2019-11-19 21:23:43 +00:00
|
|
|
onready var popup_menu := $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-03-18 00:57:23 +00:00
|
|
|
if Global.canvases[frame] in Global.layers[layer][5]:
|
2020-03-18 00:02:41 +00:00
|
|
|
get_node("LinkedIndicator").visible = true
|
2020-04-07 21:46:45 +00:00
|
|
|
popup_menu.set_item_disabled(4, false) # Unlink cel
|
2020-03-18 00:57:23 +00:00
|
|
|
else:
|
|
|
|
get_node("LinkedIndicator").visible = false
|
2020-04-07 21:46:45 +00:00
|
|
|
popup_menu.set_item_disabled(4, true) # Unlink cel
|
2020-02-28 01:27:22 +00:00
|
|
|
|
2020-04-17 21:35:42 +00:00
|
|
|
|
2019-09-09 22:57:46 +00:00
|
|
|
func _on_FrameButton_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"):
|
2019-11-19 21:23:43 +00:00
|
|
|
if Global.canvases.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.canvases.size() - 1:
|
|
|
|
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-03-21 20:55:36 +00:00
|
|
|
var cel_index : int = Global.layers[layer][5].find(Global.canvases[frame])
|
|
|
|
Global.layers[layer][5].remove(cel_index)
|
2020-03-18 00:57:23 +00:00
|
|
|
_ready()
|
2019-11-19 21:23:43 +00:00
|
|
|
|
2020-03-21 20:55:36 +00:00
|
|
|
var sprite := Image.new()
|
|
|
|
sprite.copy_from(Global.canvases[frame].layers[layer][0])
|
|
|
|
sprite.lock()
|
|
|
|
Global.canvases[frame].layers[layer][0] = sprite
|
|
|
|
var tex := ImageTexture.new()
|
|
|
|
tex.create_from_image(sprite, 0)
|
|
|
|
Global.canvases[frame].layers[layer][1] = tex
|
2020-03-21 22:30:10 +00:00
|
|
|
Global.canvases[frame].update()
|
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
|
|
|
|
var new_canvases := Global.canvases.duplicate()
|
|
|
|
var temp = new_canvases[frame]
|
|
|
|
new_canvases[frame] = new_canvases[change]
|
|
|
|
new_canvases[change] = temp
|
|
|
|
|
|
|
|
Global.undo_redo.create_action("Change Frame Order")
|
|
|
|
Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
|
|
|
|
Global.undo_redo.add_do_property(Global.canvases[frame], "frame", change)
|
|
|
|
Global.undo_redo.add_do_property(Global.canvases[change], "frame", frame)
|
|
|
|
|
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)
|
|
|
|
|
2019-11-19 21:23:43 +00:00
|
|
|
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
|
|
|
|
Global.undo_redo.add_undo_property(Global.canvases[frame], "frame", frame)
|
|
|
|
Global.undo_redo.add_undo_property(Global.canvases[change], "frame", change)
|
|
|
|
|
|
|
|
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvases[frame]])
|
|
|
|
Global.undo_redo.add_do_method(Global, "redo", [Global.canvases[frame]])
|
2019-11-20 12:42:52 +00:00
|
|
|
Global.undo_redo.commit_action()
|