1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-02-07 19:09:50 +00:00

Fix LayerButton drag and drop passing wrong parameter to BaseLayer.accepts_child()

It was passing the index of the layer as an integer instead of a BaseLayer class. Also made some code stylistic changes.
This commit is contained in:
Emmanouil Papadeas 2023-03-25 18:42:50 +02:00
parent b384e706a9
commit 4e9b4c33f7

View file

@ -184,7 +184,7 @@ func _select_current_layer() -> void:
Global.current_project.change_cel(-1, layer) Global.current_project.change_cel(-1, layer)
func get_drag_data(_position) -> Array: func get_drag_data(_position: Vector2) -> Array:
var layers := range( var layers := range(
layer - Global.current_project.layers[layer].get_child_count(true), layer + 1 layer - Global.current_project.layers[layer].get_child_count(true), layer + 1
) )
@ -201,9 +201,13 @@ func get_drag_data(_position) -> Array:
return ["Layer", layer] return ["Layer", layer]
func can_drop_data(_pos, data) -> bool: func can_drop_data(_pos: Vector2, data) -> bool:
if typeof(data) == TYPE_ARRAY: if typeof(data) != TYPE_ARRAY:
if data[0] == "Layer": Global.animation_timeline.drag_highlight.visible = false
return false
if data[0] != "Layer":
Global.animation_timeline.drag_highlight.visible = false
return false
var curr_layer: BaseLayer = Global.current_project.layers[layer] var curr_layer: BaseLayer = Global.current_project.layers[layer]
var drag_layer: BaseLayer = Global.current_project.layers[data[1]] var drag_layer: BaseLayer = Global.current_project.layers[data[1]]
@ -226,7 +230,7 @@ func can_drop_data(_pos, data) -> bool:
return false return false
# If accepted as a child, is it in the center region? # If accepted as a child, is it in the center region?
if ( if (
Global.current_project.layers[layer].accepts_child(data[1]) Global.current_project.layers[layer].accepts_child(drag_layer)
and _get_region_rect(0.25, 0.75).has_point(get_global_mouse_position()) and _get_region_rect(0.25, 0.75).has_point(get_global_mouse_position())
): ):
# Drawn regions are adjusted a bit from actual to clarify drop position # Drawn regions are adjusted a bit from actual to clarify drop position
@ -245,13 +249,11 @@ func can_drop_data(_pos, data) -> bool:
Global.animation_timeline.drag_highlight.rect_size = region.size Global.animation_timeline.drag_highlight.rect_size = region.size
Global.animation_timeline.drag_highlight.visible = true Global.animation_timeline.drag_highlight.visible = true
return true return true
Global.animation_timeline.drag_highlight.visible = false
return false
func drop_data(_pos, data) -> void: func drop_data(_pos: Vector2, data) -> void:
var drop_layer: int = data[1] var drop_layer: int = data[1]
var project = Global.current_project var project: Project = Global.current_project
project.undo_redo.create_action("Change Layer Order") project.undo_redo.create_action("Change Layer Order")
var layers: Array = project.layers # This shouldn't be modified directly var layers: Array = project.layers # This shouldn't be modified directly
@ -303,7 +305,7 @@ func drop_data(_pos, data) -> void:
# If accepted as a child, is it in the center region? # If accepted as a child, is it in the center region?
if ( if (
layers[layer].accepts_child(data[1]) layers[layer].accepts_child(layers[drop_layer])
and _get_region_rect(0.25, 0.75).has_point(get_global_mouse_position()) and _get_region_rect(0.25, 0.75).has_point(get_global_mouse_position())
): ):
to_index = layer to_index = layer