From 35a9cd1d63fcb8444e1952aa3ae07d1f4c4e2abd Mon Sep 17 00:00:00 2001 From: Yuri Rubinsky Date: Fri, 6 Jan 2023 14:20:25 +0300 Subject: Fix errors when creating/deleting `VisualShaderNodeExpression` in graph --- editor/plugins/visual_shader_editor_plugin.cpp | 30 +++++--------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 3e70d4ce11..5abfbe922f 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2941,7 +2941,7 @@ void VisualShaderEditor::_add_node(int p_idx, const Vector &p_ops, Stri VisualShaderNodeExpression *expr = Object::cast_to(vsnode.ptr()); if (expr) { - undo_redo->add_do_method(expr, "set_size", Size2(250 * EDSCALE, 150 * EDSCALE)); + expr->set_size(Size2(250 * EDSCALE, 150 * EDSCALE)); } bool created_expression_port = false; @@ -2950,9 +2950,7 @@ void VisualShaderEditor::_add_node(int p_idx, const Vector &p_ops, Stri VisualShaderNode::PortType input_port_type = visual_shader->get_node(type, to_node)->get_input_port_type(to_slot); if (expr && expr->is_editable() && input_port_type != VisualShaderNode::PORT_TYPE_SAMPLER) { - undo_redo->add_do_method(expr, "add_output_port", 0, input_port_type, "output0"); - undo_redo->add_undo_method(expr, "remove_output_port", 0); - + expr->add_output_port(0, input_port_type, "output0"); String initial_expression_code; switch (input_port_type) { @@ -2981,9 +2979,8 @@ void VisualShaderEditor::_add_node(int p_idx, const Vector &p_ops, Stri break; } - undo_redo->add_do_method(expr, "set_expression", initial_expression_code); - undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, id_to_use); - + expr->set_expression(initial_expression_code); + expr->set_size(Size2(500 * EDSCALE, 200 * EDSCALE)); created_expression_port = true; } if (vsnode->get_output_port_count() > 0 || created_expression_port) { @@ -3019,10 +3016,7 @@ void VisualShaderEditor::_add_node(int p_idx, const Vector &p_ops, Stri VisualShaderNode::PortType output_port_type = visual_shader->get_node(type, from_node)->get_output_port_type(from_slot); if (expr && expr->is_editable()) { - undo_redo->add_do_method(expr, "add_input_port", 0, output_port_type, "input0"); - undo_redo->add_undo_method(expr, "remove_input_port", 0); - undo_redo->add_do_method(graph_plugin.ptr(), "update_node", type, id_to_use); - + expr->add_input_port(0, output_port_type, "input0"); created_expression_port = true; } @@ -3335,20 +3329,6 @@ void VisualShaderEditor::_delete_nodes(int p_type, const List &p_nodes) { undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F), F); undo_redo->add_undo_method(graph_plugin.ptr(), "add_node", type, F); - // restore size, inputs and outputs if node is group - VisualShaderNodeGroupBase *group = Object::cast_to(node.ptr()); - if (group) { - undo_redo->add_undo_method(group, "set_size", group->get_size()); - undo_redo->add_undo_method(group, "set_inputs", group->get_inputs()); - undo_redo->add_undo_method(group, "set_outputs", group->get_outputs()); - } - - // restore expression text if node is expression - VisualShaderNodeExpression *expression = Object::cast_to(node.ptr()); - if (expression) { - undo_redo->add_undo_method(expression, "set_expression", expression->get_expression()); - } - VisualShaderNodeParameter *parameter = Object::cast_to(node.ptr()); if (parameter) { parameter_names.insert(parameter->get_parameter_name()); -- cgit v1.2.3