Fix errors when deleting a graph node

This commit is contained in:
Marc Gilleron 2021-12-15 01:36:46 +00:00
parent 7ce6ac8148
commit cf4f1139a4
4 changed files with 16 additions and 0 deletions

View File

@ -16,6 +16,7 @@
const char *VoxelGraphEditor::SIGNAL_NODE_SELECTED = "node_selected";
const char *VoxelGraphEditor::SIGNAL_NOTHING_SELECTED = "nothing_selected";
const char *VoxelGraphEditor::SIGNAL_NODES_DELETED = "nodes_deleted";
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -617,6 +618,8 @@ void VoxelGraphEditor::_on_graph_edit_delete_nodes_request() {
}
_undo_redo->commit_action();
emit_signal(SIGNAL_NODES_DELETED);
}
void VoxelGraphEditor::_on_graph_node_dragged(Vector2 from, Vector2 to, int id) {
@ -998,4 +1001,5 @@ void VoxelGraphEditor::_bind_methods() {
ADD_SIGNAL(MethodInfo(SIGNAL_NODE_SELECTED, PropertyInfo(Variant::INT, "node_id")));
ADD_SIGNAL(MethodInfo(SIGNAL_NOTHING_SELECTED, PropertyInfo(Variant::INT, "nothing_selected")));
ADD_SIGNAL(MethodInfo(SIGNAL_NODES_DELETED, PropertyInfo(Variant::INT, "nodes_deleted")));
}

View File

@ -18,6 +18,7 @@ class VoxelGraphEditor : public Control {
public:
static const char *SIGNAL_NODE_SELECTED;
static const char *SIGNAL_NOTHING_SELECTED;
static const char *SIGNAL_NODES_DELETED;
VoxelGraphEditor();

View File

@ -15,6 +15,8 @@ VoxelGraphEditorPlugin::VoxelGraphEditorPlugin(EditorNode *p_node) {
callable_mp(this, &VoxelGraphEditorPlugin::_on_graph_editor_node_selected));
_graph_editor->connect(VoxelGraphEditor::SIGNAL_NOTHING_SELECTED,
callable_mp(this, &VoxelGraphEditorPlugin::_on_graph_editor_nothing_selected));
_graph_editor->connect(VoxelGraphEditor::SIGNAL_NODES_DELETED,
callable_mp(this, &VoxelGraphEditorPlugin::_on_graph_editor_nodes_deleted));
_bottom_panel_button = add_control_to_bottom_panel(_graph_editor, TTR("Voxel Graph"));
_bottom_panel_button->hide();
}
@ -114,6 +116,14 @@ void VoxelGraphEditorPlugin::_on_graph_editor_nothing_selected() {
}
}
void VoxelGraphEditorPlugin::_on_graph_editor_nodes_deleted() {
// When deleting nodes, the selected one can be in them, but the inspector wrapper will still point at it.
// Clean it up and inspect the graph itself.
Ref<VoxelGeneratorGraph> graph = _graph_editor->get_graph();
ERR_FAIL_COND(graph.is_null());
get_editor_interface()->inspect_object(*graph);
}
void VoxelGraphEditorPlugin::_bind_methods() {
// ClassDB::bind_method(D_METHOD("_on_graph_editor_node_selected", "node_id"),
// &VoxelGraphEditorPlugin::_on_graph_editor_node_selected);

View File

@ -18,6 +18,7 @@ public:
private:
void _on_graph_editor_node_selected(uint32_t node_id);
void _on_graph_editor_nothing_selected();
void _on_graph_editor_nodes_deleted();
void _hide_deferred();
static void _bind_methods();