Skip to content

Commit 19eb9f6

Browse files
authored
Merge pull request #369 from endlessm/picker-not-editable
Make blocks in Picker not editable
2 parents 18c8de5 + 6e318f2 commit 19eb9f6

File tree

7 files changed

+48
-1
lines changed

7 files changed

+48
-1
lines changed

addons/block_code/drag_manager/drag_manager.gd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ func drag_ended():
8282
connect_block_canvas_signals(block)
8383
block.grab_focus()
8484

85-
# Allow the block to be deleted now that it's on the canvas.
85+
# Allow the block to be deleted and edited now that it's on the canvas.
8686
block.can_delete = true
87+
block.editable = true
8788

8889
_block_canvas.release_scope()
8990

addons/block_code/ui/blocks/block/block.gd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ signal modified
1010
## Color of block (optionally used to draw block color)
1111
@export var color: Color = Color(1., 1., 1.)
1212

13+
## Whether the parameter inputs inside the block can be edited.
14+
@export var editable: bool = true:
15+
set = _set_editable
16+
1317
# FIXME Note: This used to be a NodePath. There is a bug in Godot 4.2 that causes the
1418
# reference to not be set properly when the node is duplicated. Since we don't
1519
# use the Node duplicate function anymore, this is okay.
@@ -56,6 +60,11 @@ func _ready():
5660
_on_definition_changed()
5761

5862

63+
func _set_editable(value) -> void:
64+
editable = value
65+
template_editor.editable = value
66+
67+
5968
func _block_on_focus_entered():
6069
z_index = 1
6170
if bottom_snap:

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.gd

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@ var _drag_start: Vector2 = Vector2.INF
5656
_v3_z_line_edit: "",
5757
}
5858

59+
## Whether the text inputs can be edited, and whether the options selection have any effect.
60+
@export var editable: bool = true:
61+
set = _set_editable
62+
63+
64+
func _set_editable(value) -> void:
65+
if not is_node_ready():
66+
await ready
67+
editable = value
68+
_line_edit.editable = value
69+
_x_line_edit.editable = value
70+
_y_line_edit.editable = value
71+
_v3_x_line_edit.editable = value
72+
_v3_y_line_edit.editable = value
73+
_v3_z_line_edit.editable = value
74+
5975

6076
## Sets the value using [param raw_input], which could be one of a variety of types
6177
## depending on [member variant_type]. The value could also be a [Block], in which
@@ -180,6 +196,8 @@ func get_snapped_block() -> Block:
180196

181197

182198
func _validate_and_submit_edit_text(line_edit: Node, type: Variant.Type):
199+
if not editable:
200+
return
183201
if _last_submitted_text[line_edit] == line_edit.text:
184202
return
185203
match type:
@@ -319,6 +337,8 @@ func _update_option_input(current_value: Variant = null):
319337

320338

321339
func _on_color_input_color_changed(color):
340+
if not editable:
341+
return
322342
_update_background_color(color)
323343
modified.emit()
324344

@@ -328,6 +348,8 @@ func _update_background_color(new_color):
328348

329349

330350
func _on_option_input_item_selected(index):
351+
if not editable:
352+
return
331353
modified.emit()
332354

333355

addons/block_code/ui/blocks/utilities/parameter_input/parameter_input.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ grow_horizontal = 2
3434
grow_vertical = 2
3535
mouse_filter = 2
3636
script = ExtResource("1_rgmxn")
37+
editable = null
3738

3839
[node name="Background" type="Control" parent="."]
3940
unique_name_in_owner = true

addons/block_code/ui/blocks/utilities/template_editor/template_editor.gd

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const CollapsableSettingsScene = preload("res://addons/block_code/ui/blocks/util
3636
parameter_defaults = value
3737
_update_from_format_string()
3838

39+
## Whether the parameter inputs can be edited.
40+
@export var editable: bool = true:
41+
set = _set_editable
42+
3943
var parent_block: Block
4044
var _parameter_inputs_by_name: Dictionary
4145

@@ -48,6 +52,13 @@ func _ready() -> void:
4852
_update_from_format_string()
4953

5054

55+
func _set_editable(value) -> void:
56+
editable = value
57+
for parameter_name in _parameter_inputs_by_name:
58+
var parameter_input: ParameterInput = _parameter_inputs_by_name[parameter_name]
59+
parameter_input.editable = value
60+
61+
5162
## Set the values of all input parameters based from a dictionary of raw values.
5263
## Parameters not included in [param raw_values] will be reset to their
5364
## defaults according to [member parameter_defaults].
@@ -125,6 +136,7 @@ func _append_input_parameter(container: Container, parameter: Dictionary, id: in
125136
parameter_input.placeholder = parameter["name"]
126137
parameter_input.variant_type = parameter["type"]
127138
parameter_input.drag_started.connect(_on_parameter_input_drag_started)
139+
parameter_input.editable = editable
128140

129141
if default_value is OptionData:
130142
var option_data := default_value as OptionData

addons/block_code/ui/blocks/utilities/template_editor/template_editor.tscn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ grow_horizontal = 2
1010
grow_vertical = 2
1111
mouse_filter = 2
1212
script = ExtResource("1_7extq")
13+
editable = null
1314

1415
[node name="Container" type="HBoxContainer" parent="."]
1516
unique_name_in_owner = true

addons/block_code/ui/picker/categories/block_category_display.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func _get_or_create_block(block_definition: BlockDefinition) -> Block:
6666
if block == null:
6767
block = _context.block_script.instantiate_block(block_definition)
6868
block.can_delete = false
69+
block.editable = false
6970
block.drag_started.connect(func(block: Block, offset: Vector2): block_picked.emit(block, offset))
7071
_blocks_container.add_child(block)
7172
_blocks[block_definition.name] = block

0 commit comments

Comments
 (0)