diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 731194b8722e..e66e977926f9 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2256,41 +2256,33 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da undo_redo->create_action(TTR("Add Node(s) From Tree")); int base_id = script->get_available_id(); - if (nodes.size() > 1) { - use_node = true; - } - - for (int i = 0; i < nodes.size(); i++) { - NodePath np = nodes[i]; - Node *node = get_node(np); - if (!node) { - continue; - } - - Ref n; + if (use_node || nodes.size() > 1) { + for (int i = 0; i < nodes.size(); i++) { + NodePath np = nodes[i]; + Node *node = get_node(np); + if (!node) { + continue; + } - if (use_node) { + Ref n; Ref scene_node; scene_node.instance(); scene_node->set_node_path(sn->get_path_to(node)); n = scene_node; - } else { - // ! Doesn't work properly - Ref call; - call.instance(); - call->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); - call->set_base_path(sn->get_path_to(node)); - call->set_base_type(node->get_class()); - n = call; - method_select->select_from_instance(node, "", true, node->get_class()); - selecting_method_id = base_id; - } - undo_redo->add_do_method(script.ptr(), "add_node", default_func, base_id, n, pos); - undo_redo->add_undo_method(script.ptr(), "remove_node", default_func, base_id); + undo_redo->add_do_method(script.ptr(), "add_node", default_func, base_id, n, pos); + undo_redo->add_undo_method(script.ptr(), "remove_node", default_func, base_id); - base_id++; - pos += Vector2(25, 25); + base_id++; + pos += Vector2(25, 25); + } + } else { + NodePath np = nodes[0]; + Node *node = get_node(np); + drop_position = pos; + drop_node = node; + drop_path = sn->get_path_to(node); + new_connect_node_select->select_from_instance(node, "", false, node->get_class()); } undo_redo->add_do_method(this, "_update_graph"); undo_redo->add_undo_method(this, "_update_graph"); @@ -3499,6 +3491,11 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri Set vn; + if (drop_position != Vector2()) { + pos = drop_position; + } + drop_position = Vector2(); + bool port_node_exists = true; StringName func = _get_function_of_node(port_action_node); @@ -3553,18 +3550,63 @@ void VisualScriptEditor::_selected_connect_node(const String &p_text, const Stri if (p_category == String("method")) { Ref n; n.instance(); + + if (!drop_path.is_empty()) { + if (drop_path == String(".")) { + n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_SELF); + } else { + n->set_call_mode(VisualScriptFunctionCall::CALL_MODE_NODE_PATH); + n->set_base_path(drop_path); + } + } + if (drop_node) { + n->set_base_type(drop_node->get_class()); + if (drop_node->get_script_instance()) { + n->set_base_script(drop_node->get_script_instance()->get_script()->get_path()); + } + } vnode = n; } else if (p_category == String("set")) { Ref n; n.instance(); + if (!drop_path.is_empty()) { + if (drop_path == String(".")) { + n->set_call_mode(VisualScriptPropertySet::CALL_MODE_SELF); + } else { + n->set_call_mode(VisualScriptPropertySet::CALL_MODE_NODE_PATH); + n->set_base_path(drop_path); + } + } + if (drop_node) { + n->set_base_type(drop_node->get_class()); + if (drop_node->get_script_instance()) { + n->set_base_script(drop_node->get_script_instance()->get_script()->get_path()); + } + } vnode = n; script_prop_set = n; } else if (p_category == String("get")) { Ref n; n.instance(); n->set_property(p_text); + if (!drop_path.is_empty()) { + if (drop_path == String(".")) { + n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_SELF); + } else { + n->set_call_mode(VisualScriptPropertyGet::CALL_MODE_NODE_PATH); + n->set_base_path(drop_path); + } + } + if (drop_node) { + n->set_base_type(drop_node->get_class()); + if (drop_node->get_script_instance()) { + n->set_base_script(drop_node->get_script_instance()->get_script()->get_path()); + } + } vnode = n; } + drop_path = String(); + drop_node = nullptr; if (p_category == String("action")) { if (p_text == "VisualScriptCondition") { diff --git a/modules/visual_script/visual_script_editor.h b/modules/visual_script/visual_script_editor.h index e3b6cad89d6b..8e15dce76d16 100644 --- a/modules/visual_script/visual_script_editor.h +++ b/modules/visual_script/visual_script_editor.h @@ -179,6 +179,9 @@ class VisualScriptEditor : public ScriptEditorBase { void _port_action_menu(int p_option, const StringName &p_func); + NodePath drop_path; + Node *drop_node = nullptr; + Vector2 drop_position; void connect_data(Ref vnode_old, Ref vnode, int new_id); void _selected_connect_node(const String &p_text, const String &p_category, const bool p_connecting = true); diff --git a/modules/visual_script/visual_script_func_nodes.cpp b/modules/visual_script/visual_script_func_nodes.cpp index ec0553551193..b42a89b35364 100644 --- a/modules/visual_script/visual_script_func_nodes.cpp +++ b/modules/visual_script/visual_script_func_nodes.cpp @@ -254,25 +254,31 @@ PropertyInfo VisualScriptFunctionCall::get_output_value_port_info(int p_idx) con } String VisualScriptFunctionCall::get_caption() const { - if (call_mode == CALL_MODE_SELF) { - return " " + String(function) + "()"; - } - if (call_mode == CALL_MODE_SINGLETON) { - return String(singleton) + ":" + String(function) + "()"; - } else if (call_mode == CALL_MODE_BASIC_TYPE) { - return Variant::get_type_name(basic_type) + "." + String(function) + "()"; - } else if (call_mode == CALL_MODE_NODE_PATH) { - return " [" + String(base_path.simplified()) + "]." + String(function) + "()"; - } else { - return " " + base_type + "." + String(function) + "()"; - } + return " " + String(function) + "()"; } String VisualScriptFunctionCall::get_text() const { + String text; + + if (call_mode == CALL_MODE_BASIC_TYPE) { + text = String("On ") + Variant::get_type_name(basic_type); + } else if (call_mode == CALL_MODE_INSTANCE) { + text = String("On ") + base_type; + } else if (call_mode == CALL_MODE_NODE_PATH) { + text = "[" + String(base_path.simplified()) + "]"; + } else if (call_mode == CALL_MODE_SELF) { + text = "On Self"; + } else if (call_mode == CALL_MODE_SINGLETON) { + text = String(singleton) + ":" + String(function) + "()"; + } + if (rpc_call_mode) { - return "RPC"; + text += " RPC"; + if (rpc_call_mode == RPC_UNRELIABLE || rpc_call_mode == RPC_UNRELIABLE_TO_ID) { + text += " UNREL"; + } } - return ""; + return text; } void VisualScriptFunctionCall::set_basic_type(Variant::Type p_type) { @@ -895,11 +901,11 @@ static Ref create_function_call_node(const String &p_name) { ////////////////////////////////////////// int VisualScriptPropertySet::get_output_sequence_port_count() const { - return call_mode != CALL_MODE_BASIC_TYPE ? 1 : 0; + return 1; } bool VisualScriptPropertySet::has_input_sequence_port() const { - return call_mode != CALL_MODE_BASIC_TYPE; + return 1; } Node *VisualScriptPropertySet::_get_base_node() const { @@ -993,21 +999,24 @@ PropertyInfo VisualScriptPropertySet::get_input_value_port_info(int p_idx) const ClassDB::get_property_list(_get_base_type(), &props, false); for (List::Element *E = props.front(); E; E = E->next()) { if (E->get().name == property) { - PropertyInfo pinfo = PropertyInfo(E->get().type, "value", PROPERTY_HINT_TYPE_STRING, E->get().hint_string); + String detail_prop_name = property; + if (index != StringName()) { + detail_prop_name += "." + String(index); + } + PropertyInfo pinfo = PropertyInfo(E->get().type, detail_prop_name, PROPERTY_HINT_TYPE_STRING, E->get().hint_string); _adjust_input_index(pinfo); return pinfo; } } PropertyInfo pinfo = type_cache; - pinfo.name = "value"; _adjust_input_index(pinfo); return pinfo; } PropertyInfo VisualScriptPropertySet::get_output_value_port_info(int p_idx) const { if (call_mode == CALL_MODE_BASIC_TYPE) { - return PropertyInfo(basic_type, "out"); + return PropertyInfo(basic_type, "pass"); } else if (call_mode == CALL_MODE_INSTANCE) { return PropertyInfo(Variant::OBJECT, "pass", PROPERTY_HINT_TYPE_STRING, get_base_type()); } else { @@ -1029,17 +1038,18 @@ String VisualScriptPropertySet::get_caption() const { } String VisualScriptPropertySet::get_text() const { + if (!has_input_sequence_port()) { + return ""; + } if (call_mode == CALL_MODE_BASIC_TYPE) { return String("On ") + Variant::get_type_name(basic_type); + } else if (call_mode == CALL_MODE_INSTANCE) { + return String("On ") + base_type; + } else if (call_mode == CALL_MODE_NODE_PATH) { + return " [" + String(base_path.simplified()) + "]"; + } else { + return "On Self"; } - - static const char *cname[3] = { - "Self", - "Scene Node", - "Instance" - }; - - return String("On ") + cname[call_mode]; } void VisualScriptPropertySet::_update_base_type() { @@ -1692,6 +1702,7 @@ int VisualScriptPropertyGet::get_input_value_port_count() const { return (call_mode == CALL_MODE_BASIC_TYPE || call_mode == CALL_MODE_INSTANCE) ? 1 : 0; } int VisualScriptPropertyGet::get_output_value_port_count() const { + // port 'pass' not backported to 3.x to keep script backwards compatibility return 1; } @@ -1712,33 +1723,41 @@ PropertyInfo VisualScriptPropertyGet::get_input_value_port_info(int p_idx) const } PropertyInfo VisualScriptPropertyGet::get_output_value_port_info(int p_idx) const { + // port 'pass' not backported to 3.x to keep script backwards compatibility List props; ClassDB::get_property_list(_get_base_type(), &props, false); for (List::Element *E = props.front(); E; E = E->next()) { if (E->get().name == property) { - return PropertyInfo(E->get().type, "value." + String(index)); + PropertyInfo pinfo = PropertyInfo(E->get().type, String(property) + "." + String(index), E->get().hint, E->get().hint_string); + _adjust_input_index(pinfo); + return pinfo; } } - return PropertyInfo(type_cache, "value"); + PropertyInfo pinfo = PropertyInfo(type_cache, "value"); + _adjust_input_index(pinfo); + return pinfo; } String VisualScriptPropertyGet::get_caption() const { - return String("Get ") + property; + String prop = String("Get ") + property; + if (index != StringName()) { + prop += "." + String(index); + } + + return prop; } String VisualScriptPropertyGet::get_text() const { if (call_mode == CALL_MODE_BASIC_TYPE) { return String("On ") + Variant::get_type_name(basic_type); + } else if (call_mode == CALL_MODE_INSTANCE) { + return String("On ") + base_type; + } else if (call_mode == CALL_MODE_NODE_PATH) { + return " [" + String(base_path.simplified()) + "]"; + } else { + return "On Self"; } - - static const char *cname[3] = { - "Self", - "Scene Node", - "Instance" - }; - - return String("On ") + cname[call_mode]; } void VisualScriptPropertyGet::set_base_type(const StringName &p_type) { @@ -1916,6 +1935,18 @@ Variant::Type VisualScriptPropertyGet::_get_type_cache() const { return type_cache; } +void VisualScriptPropertyGet::_adjust_input_index(PropertyInfo &pinfo) const { + if (index != StringName()) { + Variant v; + Variant::CallError ce; + v = Variant::construct(pinfo.type, nullptr, 0, ce); + Variant i = v.get(index); + pinfo.type = i.get_type(); + } else { + pinfo.name = String(property); + } +} + void VisualScriptPropertyGet::set_index(const StringName &p_type) { if (index == p_type) { return; @@ -2141,6 +2172,7 @@ class VisualScriptNodeInstancePropertyGet : public VisualScriptNodeInstance { bool valid; Variant v = *p_inputs[0]; + // port 'pass' not backported to 3.x to keep script backwards compatibility *p_outputs[0] = v.get(property, &valid); if (index != StringName()) { *p_outputs[0] = p_outputs[0]->get_named(index); diff --git a/modules/visual_script/visual_script_func_nodes.h b/modules/visual_script/visual_script_func_nodes.h index 6da044492641..372e903eae60 100644 --- a/modules/visual_script/visual_script_func_nodes.h +++ b/modules/visual_script/visual_script_func_nodes.h @@ -272,6 +272,8 @@ class VisualScriptPropertyGet : public VisualScriptNode { void _set_type_cache(Variant::Type p_type); Variant::Type _get_type_cache() const; + void _adjust_input_index(PropertyInfo &pinfo) const; + protected: virtual void _validate_property(PropertyInfo &property) const;