From feb12559e660f2b579ab50d948e4f4f458b1c35f Mon Sep 17 00:00:00 2001 From: "Andrii Doroshenko (Xrayez)" Date: Mon, 10 Dec 2018 14:20:58 +0200 Subject: Properly reselect duplicated visual shader nodes This makes it much easier to drag duplicated nodes away from original ones. --- editor/plugins/visual_shader_editor_plugin.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'editor') diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index f55adf6c7d..d3295c0f51 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -633,6 +633,7 @@ void VisualShaderEditor::_duplicate_nodes() { VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); List nodes; + Set excluded; for (int i = 0; i < graph->get_child_count(); i++) { @@ -642,11 +643,13 @@ void VisualShaderEditor::_duplicate_nodes() { Ref node = visual_shader->get_node(type, id); Ref output = node; if (output.is_valid()) { // can't duplicate output + excluded.insert(id); continue; } if (node.is_valid() && gn->is_selected()) { nodes.push_back(id); } + excluded.insert(id); } } @@ -685,15 +688,16 @@ void VisualShaderEditor::_duplicate_nodes() { undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); - //reselect + // reselect duplicated nodes by excluding the other ones for (int i = 0; i < graph->get_child_count(); i++) { - if (Object::cast_to(graph->get_child(i))) { - int id = String(graph->get_child(i)->get_name()).to_int(); - if (nodes.find(id)) { - Object::cast_to(graph->get_child(i))->set_selected(true); + GraphNode *gn = Object::cast_to(graph->get_child(i)); + if (gn) { + int id = String(gn->get_name()).to_int(); + if (!excluded.has(id)) { + gn->set_selected(true); } else { - Object::cast_to(graph->get_child(i))->set_selected(false); + gn->set_selected(false); } } } -- cgit v1.2.3