Merge pull request #50696 from DavidCambre/Allow-dropping-custom-node-scripts-in-VisualScript-editor

[3.x] Allow dropping custom node scripts in VisualScript editor
This commit is contained in:
Rémi Verschelde 2021-07-22 12:42:06 +02:00 committed by GitHub
commit 5ca46ee1fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2180,6 +2180,11 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
}
if (String(d["type"]) == "files") {
#ifdef OSX_ENABLED
bool use_preload = Input::get_singleton()->is_key_pressed(KEY_META);
#else
bool use_preload = Input::get_singleton()->is_key_pressed(KEY_CONTROL);
#endif
Vector2 pos = _get_pos_in_graph(p_point);
Array files = d["files"];
@ -2195,13 +2200,22 @@ void VisualScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da
if (!res.is_valid()) {
continue;
}
Ref<Script> drop_script = ResourceLoader::load(files[i]);
if (drop_script.is_valid() && drop_script->is_tool() && drop_script->get_instance_base_type() == "VisualScriptCustomNode" && !use_preload) {
Ref<VisualScriptCustomNode> vscn;
vscn.instance();
vscn->set_script(drop_script.get_ref_ptr());
Ref<VisualScriptPreload> prnode;
prnode.instance();
prnode->set_preload(res);
undo_redo->add_do_method(script.ptr(), "add_node", default_func, new_id, vscn, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", default_func, new_id);
} else {
Ref<VisualScriptPreload> prnode;
prnode.instance();
prnode->set_preload(res);
undo_redo->add_do_method(script.ptr(), "add_node", default_func, new_id, prnode, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", default_func, new_id);
undo_redo->add_do_method(script.ptr(), "add_node", default_func, new_id, prnode, pos);
undo_redo->add_undo_method(script.ptr(), "remove_node", default_func, new_id);
}
new_ids.push_back(new_id);
new_id++;
pos += Vector2(20, 20);