1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Make the loading scene open in the current scene tab if the current scene is empty

This commit is contained in:
风青山
2024-04-12 14:48:29 +08:00
parent 658e97c93a
commit b5157e0686
2 changed files with 61 additions and 38 deletions

View File

@@ -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);
}
}