From add0105c4e89e586fb3d3a9646a9ffc747d2e881 Mon Sep 17 00:00:00 2001 From: Mariano Javier Suligoy Date: Sat, 25 Jul 2015 22:05:45 -0300 Subject: [PATCH] Little fix: don't create an empty undo/redo command when trying to add a second Input GraphNode --- scene/resources/shader_graph.cpp | 9 +++++++++ scene/resources/shader_graph.h | 2 ++ tools/editor/plugins/shader_graph_editor_plugin.cpp | 3 +++ 3 files changed, 14 insertions(+) diff --git a/scene/resources/shader_graph.cpp b/scene/resources/shader_graph.cpp index 108aad3c56c..95226676984 100644 --- a/scene/resources/shader_graph.cpp +++ b/scene/resources/shader_graph.cpp @@ -142,6 +142,15 @@ ShaderGraph::GraphError ShaderGraph::get_graph_error(ShaderType p_type) const { return shader[p_type].error; } +int ShaderGraph::node_count(ShaderType p_which, int p_type) +{ + int count=0; + for (Map::Element *E=shader[p_which].node_map.front();E;E=E->next()) + if (E->get().type==p_type) + count++; + return count; +} + void ShaderGraph::_bind_methods() { ObjectTypeDB::bind_method(_MD("_update_shader"),&ShaderGraph::_update_shader); diff --git a/scene/resources/shader_graph.h b/scene/resources/shader_graph.h index d3a297cd6c4..b93567538dc 100644 --- a/scene/resources/shader_graph.h +++ b/scene/resources/shader_graph.h @@ -365,6 +365,8 @@ public: GraphError get_graph_error(ShaderType p_type) const; + int node_count(ShaderType p_which, int p_type); + static int get_type_input_count(NodeType p_type); static int get_type_output_count(NodeType p_type); static SlotType get_type_input_type(NodeType p_type,int p_idx); diff --git a/tools/editor/plugins/shader_graph_editor_plugin.cpp b/tools/editor/plugins/shader_graph_editor_plugin.cpp index 3ab536ab6ed..370688d6f5b 100644 --- a/tools/editor/plugins/shader_graph_editor_plugin.cpp +++ b/tools/editor/plugins/shader_graph_editor_plugin.cpp @@ -2162,6 +2162,9 @@ void ShaderGraphView::_notification(int p_what) { void ShaderGraphView::add_node(int p_type, const Vector2 &location) { + if ((p_type==ShaderGraph::NODE_INPUT||p_type==ShaderGraph::NODE_INPUT) && graph->node_count(type, p_type)>0) + return; + List existing; graph->get_node_list(type,&existing); existing.sort();