@@ -7,6 +7,7 @@ static var main_panel: MainPanel
77static var block_code_button : Button
88
99var editor_inspector : EditorInspector
10+ var editor_selection : EditorSelection
1011
1112var selected_block_code_node : BlockCode
1213
@@ -51,6 +52,7 @@ func _enter_tree():
5152 Types .init_cast_graph ()
5253
5354 editor_inspector = EditorInterface .get_inspector ()
55+ editor_selection = EditorInterface .get_selection ()
5456
5557 main_panel = MainPanel .instantiate ()
5658 main_panel .undo_redo = get_undo_redo ()
@@ -101,25 +103,42 @@ func _ready():
101103
102104
103105func _on_scene_changed (scene_root : Node ):
104- BlockCodePlugin . main_panel .switch_scene (scene_root )
106+ main_panel .switch_scene (scene_root )
105107 _on_editor_inspector_edited_object_changed ()
106108
107109
108110func _on_editor_inspector_edited_object_changed ():
109- var edited_node = editor_inspector .get_edited_object () as Node
111+ var edited_object = editor_inspector .get_edited_object ()
112+ # var edited_node = edited_object as Node
113+ var selected_nodes = editor_selection .get_selected_nodes ()
114+
115+ if edited_object is BlockCode and selected_nodes .has (edited_object ):
116+ # If a BlockCode node is being edited, and it was explicitly selected
117+ # (as opposed to edited in the Inspector alone), select its parent node
118+ # as well. This provides a clearer indication of what is being edited.
119+ # Changing the selection will cause edited_object_changed to fire again,
120+ # so we will return early to avoid duplicate work.
121+ var parent_node = edited_object .get_parent ()
122+ if parent_node :
123+ EditorInterface .get_selection ().add_node .call_deferred (parent_node )
124+ make_bottom_panel_item_visible (main_panel )
125+ return
126+
127+ if edited_object and edited_object .get_class () == "MultiNodeEdit" :
128+ # If multiple nodes are shown in the inspector, we will find the first
129+ # BlockCode node in the list of selected nodes and use that. This
130+ # occurs when the user selects multiple items in the Scene panel, or
131+ # when we select the parent of a BlockCode node.
132+ edited_object = selected_nodes .filter (func (node ): return node is BlockCode ).pop_front ()
110133
111134 # We will edit either the selected node (if it is a BlockCode node) or
112- # the first BlockCode child of that node.
113- selected_block_code_node = list_block_code_for_node (edited_node ).pop_front ()
135+ # the first BlockCode child of that node. Keep track of the block code node
136+ # being edited so we know to monitor for changes from EditorInspector.
137+ selected_block_code_node = list_block_code_for_node (edited_object as Node ).pop_front ()
114138 if not is_block_code_editable (selected_block_code_node ):
115139 selected_block_code_node = null
116140
117- BlockCodePlugin .main_panel .switch_block_code_node (selected_block_code_node )
118- if edited_node is BlockCode :
119- # If the user explicitly chose a BlockCode node, show the Block Code
120- # editor. We only do this for the BlockCode node itself, rather than
121- # nodes containing BlockCode, to avoid conflicts with other panels.
122- make_bottom_panel_item_visible (main_panel )
141+ main_panel .switch_block_code_node (selected_block_code_node )
123142
124143
125144static func is_block_code_editable (block_code : BlockCode ) -> bool :
0 commit comments