Skip to content

Commit c6ef1c1

Browse files
committed
BlockCanvas: Drag & drop the node's set property block from Inspector if CTRL is pressed
Drag & drop the node's set property block from Inspector if the modifier key CTRL is pressed. To detect pressing CTRL key, hook the input event and set the _modifier_ctrl flag with the CTRL key's pressed state. If the _modifier_ctrl is true, then drop a set Variable block. Otherwise, it should be a get Variable block of the property. https://phabricator.endlessm.com/T35649
1 parent 89beea9 commit c6ef1c1

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

addons/block_code/ui/block_canvas/block_canvas.gd

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ var zoom: float:
5454
get:
5555
return _window.scale.x
5656

57+
var _modifier_ctrl := false
58+
5759
signal reconnect_block(block: Block)
5860
signal add_block_code
5961
signal open_scene
@@ -126,20 +128,41 @@ func _drop_obj_property(at_position: Vector2, data: Variant) -> void:
126128
var property_name = data["property"]
127129
var property_value = data["value"]
128130

129-
# Prepare a block to get the property's value
130-
var block_definition = (
131-
BlockDefinition
132-
. new(
133-
&"%s_get_%s" % [object_name, property_name],
134-
object_name,
135-
"The %s property" % property_name,
136-
"Variables",
137-
Types.BlockType.VALUE,
138-
typeof(property_value),
139-
"%s" % property_name.capitalize().to_lower(),
140-
"%s" % property_name,
131+
# Prepare a Variable block to set / get the property's value according to
132+
# the modifier KEY_CTRL pressing.
133+
var block_definition: BlockDefinition
134+
var property_type = typeof(property_value)
135+
if _modifier_ctrl:
136+
var type_string: String = Types.VARIANT_TYPE_TO_STRING[property_type]
137+
block_definition = (
138+
BlockDefinition
139+
. new(
140+
&"%s_set_%s" % [object_name, property_name],
141+
object_name,
142+
"Set the %s property" % property_name,
143+
"Variables",
144+
Types.BlockType.STATEMENT,
145+
property_type,
146+
"set %s to {value: %s}" % [property_name.capitalize().to_lower(), type_string],
147+
"%s = {value}" % property_name,
148+
{"value": property_value},
149+
)
150+
)
151+
else:
152+
block_definition = (
153+
BlockDefinition
154+
. new(
155+
&"%s_get_%s" % [object_name, property_name],
156+
object_name,
157+
"The %s property" % property_name,
158+
"Variables",
159+
Types.BlockType.VALUE,
160+
property_type,
161+
"%s" % property_name.capitalize().to_lower(),
162+
"%s" % property_name,
163+
)
141164
)
142-
)
165+
143166
var block = _context.block_script.instantiate_block(block_definition)
144167
add_block(block, at_position)
145168
reconnect_block.emit(block)
@@ -410,6 +433,12 @@ func _on_replace_block_code_button_pressed():
410433
replace_block_code.emit()
411434

412435

436+
func _input(event):
437+
if event is InputEventKey:
438+
if event.keycode == KEY_CTRL:
439+
_modifier_ctrl = event.pressed
440+
441+
413442
func _gui_input(event):
414443
if event is InputEventKey:
415444
if event.keycode == KEY_SHIFT:

0 commit comments

Comments
 (0)