1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Implement layer and frame dragging and dropping to re-arrange them in the timeline

Part of #306
This commit is contained in:
Manolis Papadeas 2021-06-06 02:19:34 +03:00
parent c765d6876b
commit e9bf310934
3 changed files with 100 additions and 16 deletions

View file

@ -128,13 +128,13 @@ func get_drag_data(_position) -> Array:
button.add_child(texture_rect)
set_drag_preview(button)
return [frame, layer]
return ["Cel", 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 typeof(data) == TYPE_ARRAY and data[0] == "Cel":
var new_frame = data[1]
var new_layer = data[2]
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
@ -145,8 +145,8 @@ func can_drop_data(_pos, data) -> bool:
func drop_data(_pos, data) -> void:
var new_frame = data[0]
var new_layer = data[1]
var new_frame = data[1]
var new_layer = data[2]
var this_frame_new_cels = Global.current_project.frames[frame].cels.duplicate()
var new_frame_new_cels

View file

@ -69,3 +69,44 @@ func change_frame_order(rate : int) -> void:
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()
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
var new_frames : Array = Global.current_project.frames.duplicate()
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)
if Global.current_project.current_frame == frame:
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_frame", new_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", Global.current_project.frames)
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()

View file

@ -3,20 +3,16 @@ extends Button
var layer := 0
var visibility_button : BaseButton
var lock_button : BaseButton
var linked_button : BaseButton
var label : Label
var line_edit : LineEdit
onready var visibility_button : BaseButton = find_node("VisibilityButton")
onready var lock_button : BaseButton = find_node("LockButton")
onready var linked_button : BaseButton = find_node("LinkButton")
onready var label : Label = find_node("Label")
onready var line_edit : LineEdit = find_node("LineEdit")
func _ready() -> void:
rect_min_size.y = Global.animation_timeline.cel_size
visibility_button = find_node("VisibilityButton")
lock_button = find_node("LockButton")
linked_button = find_node("LinkButton")
label = find_node("Label")
line_edit = find_node("LineEdit")
var layer_buttons = find_node("LayerButtons")
for child in layer_buttons.get_children():
@ -87,3 +83,50 @@ func _on_LinkButton_pressed() -> void:
# If button is pressed and there are no linked cels in the layer
Global.current_project.layers[layer].linked_cels.append(Global.current_project.frames[Global.current_project.current_frame])
Global.current_project.layers[layer].frame_container.get_child(Global.current_project.current_frame)._ready()
func get_drag_data(_position) -> Array:
var button := Button.new()
button.rect_size = rect_size
button.theme = Global.control.theme
button.text = label.text
set_drag_preview(button)
return ["Layer", layer]
func can_drop_data(_pos, data) -> bool:
if typeof(data) == TYPE_ARRAY:
return data[0] == "Layer"
else:
return false
func drop_data(_pos, data) -> void:
var new_layer = data[1]
if layer == new_layer:
return
var new_layers : Array = Global.current_project.layers.duplicate()
var temp = new_layers[layer]
new_layers[layer] = new_layers[new_layer]
new_layers[new_layer] = temp
Global.current_project.undo_redo.create_action("Change Layer Order")
for f in Global.current_project.frames:
var new_cels : Array = f.cels.duplicate()
var temp_canvas = new_cels[layer]
new_cels[layer] = new_cels[new_layer]
new_cels[new_layer] = temp_canvas
Global.current_project.undo_redo.add_do_property(f, "cels", new_cels)
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
if Global.current_project.current_layer == layer:
Global.current_project.undo_redo.add_do_property(Global.current_project, "current_layer", new_layer)
Global.current_project.undo_redo.add_undo_property(Global.current_project, "current_layer", Global.current_project.current_layer)
Global.current_project.undo_redo.add_do_property(Global.current_project, "layers", new_layers)
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()