@@ -160,28 +160,32 @@ func _get_or_create_block_extension() -> BlockExtension:
160
160
func _on_block_extension_changed ():
161
161
_update_template_editor ()
162
162
163
-
164
163
func _gui_input (event ):
165
- if event is InputEventKey :
166
- if event .pressed and event .keycode == KEY_DELETE :
167
- # Always accept the Delete key so it doesn't propagate to the
168
- # BlockCode node in the scene tree.
169
- accept_event ()
170
-
171
- if not can_delete :
172
- return
173
-
174
- var dialog := ConfirmationDialog .new ()
175
- var num_blocks = _count_child_blocks (self ) + 1
176
- # FIXME: Maybe this should use block_name or label, but that
177
- # requires one to be both unique and human friendly.
178
- if num_blocks > 1 :
179
- dialog .dialog_text = "Delete %d blocks?" % num_blocks
180
- else :
181
- dialog .dialog_text = "Delete block?"
182
- dialog .confirmed .connect (remove_from_tree )
183
- EditorInterface .popup_dialog_centered (dialog )
184
-
164
+ if event is InputEventKey :
165
+ if event .pressed :
166
+ if event .keycode == KEY_DELETE :
167
+ # Always accept the Delete key so it doesn't propagate to the
168
+ # BlockCode node in the scene tree.
169
+ accept_event ()
170
+
171
+ if not can_delete :
172
+ return
173
+
174
+ var dialog := ConfirmationDialog .new ()
175
+ var num_blocks = _count_child_blocks (self ) + 1
176
+ # FIXME: Maybe this should use block_name or label, but that
177
+ # requires one to be both unique and human friendly.
178
+ if num_blocks > 1 :
179
+ dialog .dialog_text = "Delete %d blocks?" % num_blocks
180
+ else :
181
+ dialog .dialog_text = "Delete block?"
182
+ dialog .confirmed .connect (remove_from_tree )
183
+ EditorInterface .popup_dialog_centered (dialog )
184
+ elif event .ctrl_pressed and not event .shift_pressed and not event .alt_pressed and not event .meta_pressed :
185
+ if event .keycode == KEY_D :
186
+ # Handle duplicate key
187
+ accept_event ()
188
+ confirm_duplicate ()
185
189
186
190
func remove_from_tree ():
187
191
var parent = get_parent ()
@@ -190,6 +194,30 @@ func remove_from_tree():
190
194
queue_free ()
191
195
modified .emit ()
192
196
197
+ func confirm_duplicate ():
198
+ if not can_delete :
199
+ return
200
+
201
+ var new_block : Block = _context .block_script .instantiate_block (definition )
202
+
203
+ var new_parent : Node = get_parent ()
204
+ while not new_parent .name == "Window" :
205
+ new_parent = new_parent .get_parent ()
206
+
207
+ if not _block_canvas :
208
+ _block_canvas = get_parent ()
209
+ while not _block_canvas .name == "BlockCanvas" :
210
+ _block_canvas = _block_canvas .get_parent ()
211
+
212
+ new_parent .add_child (new_block )
213
+ new_block .global_position = global_position + (Vector2 (100 , 50 ) * new_parent .scale )
214
+
215
+ _copy_snapped_blocks (self , new_block )
216
+
217
+ _block_canvas .reconnect_block .emit (new_block )
218
+
219
+ modified .emit ()
220
+
193
221
194
222
static func get_block_class ():
195
223
push_error ("Unimplemented." )
@@ -239,3 +267,27 @@ func _count_child_blocks(node: Node) -> int:
239
267
count += _count_child_blocks (child )
240
268
241
269
return count
270
+
271
+ func _copy_snapped_blocks (copy_from : Node , copy_to : Node ):
272
+ var copy_to_child : Node
273
+ var child_index := 0
274
+ var maximum_count := copy_to .get_child_count ()
275
+
276
+ for copy_from_child in copy_from .get_children ():
277
+ if child_index + 1 > maximum_count :
278
+ return
279
+
280
+ copy_to_child = copy_to .get_child (child_index )
281
+ child_index += 1
282
+
283
+ if copy_from_child is SnapPoint and copy_from_child .has_snapped_block ():
284
+ copy_to_child .add_child (_context .block_script .instantiate_block (copy_from_child .snapped_block .definition ))
285
+ _block_canvas .reconnect_block .emit (copy_to_child .snapped_block )
286
+ elif copy_from_child .name .begins_with ("ParameterInput" ):
287
+ var raw_input = copy_from_child .get_raw_input ()
288
+
289
+ if not raw_input is Block :
290
+ copy_to_child .set_raw_input (raw_input )
291
+
292
+ if copy_from_child is Container :
293
+ _copy_snapped_blocks (copy_from_child , copy_to_child )
0 commit comments