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 | |
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')
-rw-r--r-- | scene/gui/graph_edit.cpp | 12 | ||||
-rw-r--r-- | scene/resources/visual_shader.cpp | 10 | ||||
-rw-r--r-- | scene/resources/visual_shader.h | 1 |
3 files changed, 18 insertions, 5 deletions
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index dabff08fea..f238aeb392 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -479,7 +479,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { connecting_color = gn->get_connection_input_color(j); connecting_target = false; connecting_to = pos; - just_disconnected = true; + just_disconnected = false; return; } @@ -550,11 +550,18 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { emit_signal("connection_request", from, from_slot, to, to_slot); } else if (!just_disconnected) { + String from = connecting_from; int from_slot = connecting_index; Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y); - emit_signal("connection_to_empty", from, from_slot, ofs); + + if (!connecting_out) { + emit_signal("connection_from_empty", from, from_slot, ofs); + } else { + emit_signal("connection_to_empty", from, from_slot, ofs); + } } + connecting = false; top_layer->update(); update(); @@ -1292,6 +1299,7 @@ void GraphEdit::_bind_methods() { ADD_SIGNAL(MethodInfo("duplicate_nodes_request")); ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); + ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("delete_nodes_request")); ADD_SIGNAL(MethodInfo("_begin_node_move")); ADD_SIGNAL(MethodInfo("_end_node_move")); 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; } diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h index a36776e701..83db51b1b0 100644 --- a/scene/resources/visual_shader.h +++ b/scene/resources/visual_shader.h @@ -138,6 +138,7 @@ public: Error connect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); void disconnect_nodes(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); void connect_nodes_forced(Type p_type, int p_from_node, int p_from_port, int p_to_node, int p_to_port); + bool is_port_types_compatible(int p_a, int p_b) const; void rebuild(); void get_node_connections(Type p_type, List<Connection> *r_connections) const; |