Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Support dragging and dropping block resources to the canvas #205

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions addons/block_code/ui/block_canvas/block_canvas.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extends MarginContainer

const BlockCodePlugin = preload("res://addons/block_code/block_code_plugin.gd")
const BlockDefinition = preload("res://addons/block_code/code_generation/block_definition.gd")
const BlockTreeUtil = preload("res://addons/block_code/ui/block_tree_util.gd")
const DragManager = preload("res://addons/block_code/drag_manager/drag_manager.gd")
const InstructionTree = preload("res://addons/block_code/instruction_tree/instruction_tree.gd")
Expand Down Expand Up @@ -55,6 +56,27 @@ func _ready():
_populate_block_scenes_by_class()


func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
return true


func _drop_data(at_position: Vector2, data: Variant) -> void:
if typeof(data) != TYPE_DICTIONARY:
return

data = data as Dictionary

if data.get("type") != "files":
return

for file in data.get("files", []):
var resource = load(file)
if resource is BlockDefinition:
var block = Util.instantiate_block(resource)
add_block(block, at_position)
reconnect_block.emit(block)


func _populate_block_scenes_by_class():
for _class in ProjectSettings.get_global_class_list():
if not _class.base.ends_with("Block"):
Expand Down
2 changes: 2 additions & 0 deletions addons/block_code/ui/block_canvas/block_canvas.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ script = ExtResource("1_tk8h2")

[node name="Panel" type="Panel" parent="."]
layout_mode = 2
mouse_filter = 2

[node name="WindowContainer" type="Control" parent="."]
clip_contents = true
layout_mode = 2
mouse_filter = 2

[node name="Window" type="Control" parent="WindowContainer"]
unique_name_in_owner = true
Expand Down