Properly reselect duplicated visual shader nodes
This makes it much easier to drag duplicated nodes away from original ones.
This commit is contained in:
parent
9105538b45
commit
feb12559e6
|
@ -633,6 +633,7 @@ void VisualShaderEditor::_duplicate_nodes() {
|
||||||
VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
|
VisualShader::Type type = VisualShader::Type(edit_type->get_selected());
|
||||||
|
|
||||||
List<int> nodes;
|
List<int> nodes;
|
||||||
|
Set<int> excluded;
|
||||||
|
|
||||||
for (int i = 0; i < graph->get_child_count(); i++) {
|
for (int i = 0; i < graph->get_child_count(); i++) {
|
||||||
|
|
||||||
|
@ -642,11 +643,13 @@ void VisualShaderEditor::_duplicate_nodes() {
|
||||||
Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
|
Ref<VisualShaderNode> node = visual_shader->get_node(type, id);
|
||||||
Ref<VisualShaderNodeOutput> output = node;
|
Ref<VisualShaderNodeOutput> output = node;
|
||||||
if (output.is_valid()) { // can't duplicate output
|
if (output.is_valid()) { // can't duplicate output
|
||||||
|
excluded.insert(id);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (node.is_valid() && gn->is_selected()) {
|
if (node.is_valid() && gn->is_selected()) {
|
||||||
nodes.push_back(id);
|
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->add_undo_method(this, "_update_graph");
|
||||||
undo_redo->commit_action();
|
undo_redo->commit_action();
|
||||||
|
|
||||||
//reselect
|
// reselect duplicated nodes by excluding the other ones
|
||||||
for (int i = 0; i < graph->get_child_count(); i++) {
|
for (int i = 0; i < graph->get_child_count(); i++) {
|
||||||
|
|
||||||
if (Object::cast_to<GraphNode>(graph->get_child(i))) {
|
GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i));
|
||||||
int id = String(graph->get_child(i)->get_name()).to_int();
|
if (gn) {
|
||||||
if (nodes.find(id)) {
|
int id = String(gn->get_name()).to_int();
|
||||||
Object::cast_to<GraphNode>(graph->get_child(i))->set_selected(true);
|
if (!excluded.has(id)) {
|
||||||
|
gn->set_selected(true);
|
||||||
} else {
|
} else {
|
||||||
Object::cast_to<GraphNode>(graph->get_child(i))->set_selected(false);
|
gn->set_selected(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue