@@ -4,19 +4,65 @@ extends MarginContainer
44
55signal node_name_changed (node_name : String )
66
7- @onready var _node_name := % NodeName
8- @onready var _class_name := % ClassName
7+ @onready var _block_code_icon = load ("res://addons/block_code/block_code_node/block_code_node.svg" ) as Texture2D
8+ @onready var _editor_inspector : EditorInspector = EditorInterface .get_inspector ()
9+ @onready var _editor_selection : EditorSelection = EditorInterface .get_selection ()
10+ @onready var _node_option_button : OptionButton = % NodeOptionButton
11+
12+
13+ func _ready ():
14+ _node_option_button .connect ("item_selected" , _on_node_option_button_item_selected )
15+
16+
17+ func scene_selected (scene_root : Node ):
18+ _update_node_option_button_options ()
19+ var current_block_code = _editor_inspector .get_edited_object () as BlockCode
20+ if not current_block_code :
21+ bsd_selected (null )
922
1023
1124func bsd_selected (bsd : BlockScriptData ):
12- _class_name .text = bsd .script_inherits
25+ # TODO: We should listen for property changes in all BlockCode nodes and
26+ # their parents. As a workaround for the UI displaying stale data,
27+ # we'll crudely update the list of BlockCode nodes whenever the
28+ # selection changes.
29+
30+ _update_node_option_button_options ()
31+
32+ var select_index = _get_index_for_bsd (bsd )
33+ if _node_option_button .selected != select_index :
34+ _node_option_button .select (select_index )
35+
36+
37+ func _update_node_option_button_options ():
38+ _node_option_button .clear ()
39+
40+ var scene_root = EditorInterface .get_edited_scene_root ()
41+
42+ if not scene_root :
43+ return
44+
45+ for block_code_node in scene_root .find_children ("*" , "BlockCode" ):
46+ var node_item_index = _node_option_button .item_count
47+ var node_label = "{name} ({type} )" .format ({"name" : scene_root .get_path_to (block_code_node ).get_concatenated_names (), "type" : block_code_node .bsd .script_inherits })
48+ _node_option_button .add_item (node_label )
49+ _node_option_button .set_item_icon (node_item_index , _block_code_icon )
50+ _node_option_button .set_item_metadata (node_item_index , block_code_node )
1351
1452
15- # func node_selected(node_data: NodeData):
16- # _node_name.text = node_data.node_name
17- # _class_name.text = node_data.node_class_name
53+ func _get_index_for_bsd (bsd : BlockScriptData ) -> int :
54+ for index in range (_node_option_button .item_count ):
55+ var block_code_node = _node_option_button .get_item_metadata (index )
56+ if block_code_node .bsd == bsd :
57+ return index
58+ return - 1
1859
1960
20- func _on_node_name_text_changed (new_text : String ):
21- # node_name_changed.emit(new_text)
22- pass
61+ func _on_node_option_button_item_selected (index ):
62+ var block_code_node = _node_option_button .get_item_metadata (index ) as BlockCode
63+ # FIXME: We should clear the existing selection, but at the moment this
64+ # causes the new node to be deselected due to signal handlers being
65+ # called in the wrong order.
66+ # _editor_selection.clear()
67+ if block_code_node :
68+ EditorInterface .edit_node (block_code_node )
0 commit comments