8000 WIP: Support dragging and dropping block resources to the canvas · endlessm/godot-block-coding@987af25 · GitHub
[go: up one dir, main page]

Skip to content

Commit 987af25

Browse files
committed
WIP: Support dragging and dropping block resources to the canvas
Ideally, this work will allow us to replace our own DragManager and instead use the drag and drop system built in to Godot.
1 parent aa80f0c commit 987af25

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
extends MarginContainer
33

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

5758

59+
func _can_drop_data(at_position: Vector2, data: Variant) -> bool:
60+
return true
61+
62+
63+
func _drop_data(at_position: Vector2, data: Variant) -> void:
64+
if typeof(data) != TYPE_DICTIONARY:
65+
return
66+
67+
data = data as Dictionary
68+
69+
if data.get("type") != "files":
70+
return
71+
72+
for file in data.get("files", []):
73+
var resource = load(file)
74+
if resource is BlockDefinition:
75+
var block = Util.instantiate_block(resource)
76+
add_block(block, at_position)
77+
reconnect_block.emit(block)
78+
79+
5880
func _populate_block_scenes_by_class():
5981
for _class in ProjectSettings.get_global_class_list():
6082
if not _class.base.ends_with("Block"):

addons/block_code/ui/block_canvas/block_canvas.tscn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ script = ExtResource("1_tk8h2")
1515

1616
[node name="Panel" type="Panel" parent="."]
1717
layout_mode = 2
18+
mouse_filter = 2
1819

1920
[node name="WindowContainer" type="Control" parent="."]
2021
clip_contents = true
2122
layout_mode = 2
23+
mouse_filter = 2
2224

2325
[node name="Window" type="Control" parent="WindowContainer"]
2426
unique_name_in_owner = true

0 commit comments

Comments
 (0)
0