Skip to content

Commit 58983d0

Browse files
committed
Stop changing the editor selection
Back in a808f67 and 43dd08b, the editor selection was dynamically updated so that both the BlockCode node and its parent were selected. This would open the parent node in the 2D/3D scene editor while the BlockCode node was open in the block canvas. However, selecting both nodes at the same time puts the editor into a multi-selection mode that makes interaction with the scene tree dock awkward. For example, clicking on another node does not select it for dragging. Furthermore, since some parts of the code operate on the selection while others wait to see the inspector's edited object is, there can be strange interactions when the selection is changed in the middle of an input action. What we really want is a way to say "make this the active scene in the scene editor" without selecting the node like we can with BlockCode nodes and the block canvas. That doesn't appear possible with Godot, so just always look at what the currently edited object in the inspector is and stop trying to activate the BlockCode parent in the scene editor. https://phabricator.endlessm.com/T35648
1 parent 760a579 commit 58983d0

3 files changed

Lines changed: 9 additions & 48 deletions

File tree

addons/block_code/block_code_plugin.gd

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const BlockInspectorPlugin := preload("res://addons/block_code/inspector_plugin/
1313
var block_inspector_plugin: BlockInspectorPlugin
1414

1515
var editor_inspector: EditorInspector
16-
var editor_selection: EditorSelection
1716

1817
var _selected_block_code: BlockCode
1918

@@ -34,7 +33,6 @@ func _enter_tree():
3433
Types.init_cast_graph()
3534

3635
editor_inspector = EditorInterface.get_inspector()
37-
editor_selection = EditorInterface.get_selection()
3836

3937
main_panel = MainPanelScene.instantiate()
4038
main_panel.script_window_requested.connect(script_window_requested)
@@ -100,31 +98,14 @@ func _ready():
10098

10199
func _on_editor_inspector_edited_object_changed():
102100
var edited_object = editor_inspector.get_edited_object()
103-
#var edited_node = edited_object as Node
104-
var selected_nodes = editor_selection.get_selected_nodes()
105-
106-
if edited_object is BlockCode:
101+
var block_code_node = edited_object as BlockCode
102+
if block_code_node:
103+
# If a block code node was explicitly selected, activate the
104+
# Block Code panel.
107105
make_bottom_panel_item_visible(main_panel)
108-
109-
if edited_object is BlockCode and selected_nodes.size() == 1 and edited_object.owner and edited_object != _selected_block_code:
110-
# If a BlockCode node is being edited, and it was explicitly selected
111-
# (as opposed to edited in the Inspector alone), select its parent node
112-
# as well. This provides a clearer indication of what is being edited.
113-
# Changing the selection will cause edited_object_changed to fire again,
114-
# so we will return early to avoid duplicate work.
115-
var parent_node = edited_object.get_parent()
116-
if parent_node:
117-
editor_selection.add_node.call_deferred(parent_node)
118-
return
119-
120-
if edited_object and edited_object.get_class() == "MultiNodeEdit":
121-
# If multiple nodes are shown in the inspector, we will find the first
122-
# BlockCode node in the list of selected nodes and use that. This
123-
# occurs when the user selects multiple items in the Scene panel, or
124-
# when we select the parent of a BlockCode node.
125-
edited_object = selected_nodes.filter(func(node): return node is BlockCode).pop_front()
126-
127-
var block_code_node = list_block_code_nodes_for_node(edited_object as Node).pop_front()
106+
else:
107+
# Find the first block code child.
108+
block_code_node = list_block_code_nodes_for_node(edited_object as Node).pop_front()
128109
select_block_code_node(block_code_node)
129110

130111

addons/block_code/ui/main_panel.gd

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func _on_block_canvas_add_block_code():
217217

218218
undo_redo.add_do_method(edited_node, "add_child", block_code, true)
219219
undo_redo.add_do_property(block_code, "owner", scene_root)
220-
undo_redo.add_do_method(self, "_select_block_code_node", edited_node)
220+
undo_redo.add_do_property(_context, "block_code_node", block_code)
221221
undo_redo.add_do_reference(block_code)
222222
undo_redo.add_undo_method(edited_node, "remove_child", block_code)
223223
undo_redo.add_undo_property(block_code, "owner", null)
@@ -246,26 +246,11 @@ func _on_block_canvas_replace_block_code():
246246
# Ideally this should fix itself in a future version of Godot.
247247

248248
undo_redo.add_do_method(scene_root, "set_editable_instance", edited_node, true)
249-
undo_redo.add_do_method(self, "_select_block_code_node", edited_node)
250249
undo_redo.add_undo_method(scene_root, "set_editable_instance", edited_node, false)
251250

252251
undo_redo.commit_action()
253252

254253

255-
func _select_block_code_node(edited_node: Node):
256-
var block_code_nodes = BlockCodePlugin.list_block_code_nodes_for_node(edited_node)
257-
if block_code_nodes.size() > 0:
258-
_set_selection([block_code_nodes.pop_front()])
259-
else:
260-
_set_selection([edited_node])
261-
262-
263-
func _set_selection(nodes: Array[Node]):
264-
EditorInterface.get_selection().clear()
265-
for node in nodes:
266-
EditorInterface.get_selection().add_node(node)
267-
268-
269254
func _create_variable(variable: VariableDefinition):
270255
if _context.block_code_node == null:
271256
print("No script loaded to add variable to.")

addons/block_code/ui/title_bar/title_bar.gd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ signal node_name_changed(node_name: String)
99

1010
@onready var _block_code_icon = load("res://addons/block_code/block_code_node/block_code_node.svg") as Texture2D
1111
@onready var _editor_inspector: EditorInspector = EditorInterface.get_inspector()
12-
@onready var _editor_selection: EditorSelection = EditorInterface.get_selection()
1312
@onready var _node_option_button: OptionButton = %NodeOptionButton
1413

1514

@@ -62,8 +61,4 @@ func _get_block_script_index(block_script: BlockScriptSerialization) -> int:
6261

6362
func _on_node_option_button_item_selected(index):
6463
var block_code_node = _node_option_button.get_item_metadata(index) as BlockCode
65-
var parent_node = block_code_node.get_parent() as Node
66-
_editor_selection.clear()
67-
_editor_selection.add_node(block_code_node)
68-
if parent_node:
69-
_editor_selection.add_node(parent_node)
64+
_context.block_code_node = block_code_node

0 commit comments

Comments
 (0)