diff options
author | David Cambré <david.cambre@gmail.com> | 2021-07-18 14:52:55 +0200 |
---|---|---|
committer | David Cambré <david.cambre@gmail.com> | 2021-07-18 15:48:35 +0200 |
commit | aefde680a4a1df4e5b57c6cf31c0b38fcd52602f (patch) | |
tree | 43b8ff13d8f01e4c96e27da5343ebffa5fb76510 /modules | |
parent | 7537875d862837d43e50be2cc14de9d8db8f5fe3 (diff) |
VisualScript-Drop-Custom-Nodes
Allows to drop custom node scripts directly in VisualScript
Diffstat (limited to 'modules')
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 8712bfa06b..77bb7c469f 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -2172,6 +2172,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_CTRL); +#endif Vector2 pos = _get_pos_in_graph(p_point); Array files = d["files"]; @@ -2187,13 +2192,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.instantiate(); + vscn->set_script(drop_script); + + undo_redo->add_do_method(script.ptr(), "add_node", new_id, vscn, pos); + undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); + } else { + Ref<VisualScriptPreload> prnode; + prnode.instantiate(); + prnode->set_preload(res); - Ref<VisualScriptPreload> prnode; - prnode.instantiate(); - prnode->set_preload(res); - - undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos); - undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); + undo_redo->add_do_method(script.ptr(), "add_node", new_id, prnode, pos); + undo_redo->add_undo_method(script.ptr(), "remove_node", new_id); + } new_ids.push_back(new_id); new_id++; pos += Vector2(20, 20); |