diff options
Diffstat (limited to 'editor/plugins/canvas_item_editor_plugin.cpp')
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 65 |
1 files changed, 40 insertions, 25 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 8d24e90cce..8a9118a03e 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -5860,13 +5860,34 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons } void CanvasItemEditorViewport::_perform_drop_data() { + ERR_FAIL_COND(selected_files.size() <= 0); + _remove_preview(); - // Without root dropping multiple files is not allowed - if (!target_node && selected_files.size() > 1) { - accept->set_text(TTR("Cannot instantiate multiple nodes without root.")); - accept->popup_centered(); - return; + if (!target_node) { + // Without root dropping multiple files is not allowed + if (selected_files.size() > 1) { + accept->set_text(TTR("Cannot instantiate multiple nodes without root.")); + accept->popup_centered(); + return; + } + + const String &path = selected_files[0]; + Ref<Resource> res = ResourceLoader::load(path); + if (res.is_null()) { + return; + } + + Ref<PackedScene> scene = res; + if (scene.is_valid()) { + // Without root node act the same as "Load Inherited Scene". + Error err = EditorNode::get_singleton()->load_scene(path, false, true); + if (err != OK) { + accept->set_text(vformat(TTR("Error instantiating scene from %s."), path.get_file())); + accept->popup_centered(); + } + return; + } } PackedStringArray error_files; @@ -5882,27 +5903,21 @@ void CanvasItemEditorViewport::_perform_drop_data() { if (res.is_null()) { continue; } - Ref<PackedScene> scene = Ref<PackedScene>(Object::cast_to<PackedScene>(*res)); - if (scene != nullptr && scene.is_valid()) { - if (!target_node) { - // Without root node act the same as "Load Inherited Scene" - Error err = EditorNode::get_singleton()->load_scene(path, false, true); - if (err != OK) { - error_files.push_back(path.get_file()); - } - } else { - bool success = _create_instance(target_node, path, drop_pos); - if (!success) { - error_files.push_back(path.get_file()); - } - } - } else { - Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); - if (texture != nullptr && texture.is_valid()) { - Node *child = Object::cast_to<Node>(ClassDB::instantiate(default_texture_node_type)); - _create_nodes(target_node, child, path, drop_pos); - undo_redo->add_do_method(editor_selection, "add_node", child); + + Ref<PackedScene> scene = res; + if (scene.is_valid()) { + bool success = _create_instance(target_node, path, drop_pos); + if (!success) { + error_files.push_back(path.get_file()); } + continue; + } + + Ref<Texture2D> texture = res; + if (texture.is_valid()) { + Node *child = Object::cast_to<Node>(ClassDB::instantiate(default_texture_node_type)); + _create_nodes(target_node, child, path, drop_pos); + undo_redo->add_do_method(editor_selection, "add_node", child); } } |