diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2019-06-27 15:14:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-27 15:14:54 +0200 |
commit | f35fd681acba34817d14e236f20a6065a069aea0 (patch) | |
tree | 91a806a5607cc198692fa7ed239e16ab2ac04d86 /scene/resources/visual_shader.cpp | |
parent | 11b8bf5572405a6b19d0ec80f0141c3b1e472a44 (diff) | |
parent | 0aec3c3113ce8319ffdc795ee2d06a7ec04036fc (diff) |
Merge pull request #30114 from Chaosus/vs_context_menu
Shows menu when dragging connection on empty space in visual shader
Diffstat (limited to 'scene/resources/visual_shader.cpp')
-rw-r--r-- | scene/resources/visual_shader.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index a3813f8fc6..7265c9b457 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -257,7 +257,7 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port); VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port); - if (MAX(0, from_port_type - 2) != (MAX(0, to_port_type - 2))) { + if (!is_port_types_compatible(from_port_type, to_port_type)) { return false; } @@ -271,6 +271,10 @@ bool VisualShader::can_connect_nodes(Type p_type, int p_from_node, int p_from_po return true; } +bool VisualShader::is_port_types_compatible(int p_a, int p_b) const { + return MAX(0, p_a - 2) == (MAX(0, p_b - 2)); +} + void VisualShader::connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port) { ERR_FAIL_INDEX(p_type, TYPE_MAX); Graph *g = &graph[p_type]; @@ -295,8 +299,8 @@ Error VisualShader::connect_nodes(Type p_type, int p_from_node, int p_from_port, VisualShaderNode::PortType from_port_type = g->nodes[p_from_node].node->get_output_port_type(p_from_port); VisualShaderNode::PortType to_port_type = g->nodes[p_to_node].node->get_input_port_type(p_to_port); - if (MAX(0, from_port_type - 2) != (MAX(0, to_port_type - 2))) { - ERR_EXPLAIN("Incompatible port types (scalar/vec/bool with transform"); + if (!is_port_types_compatible(from_port_type, to_port_type)) { + ERR_EXPLAIN("Incompatible port types (scalar/vec/bool) with transform"); ERR_FAIL_V(ERR_INVALID_PARAMETER); return ERR_INVALID_PARAMETER; } |