|
32 | 32 | #include "editor_interface.compat.inc" |
33 | 33 |
|
34 | 34 | #include "core/config/project_settings.h" |
| 35 | +#include "core/io/resource_loader.h" |
35 | 36 | #include "editor/docks/filesystem_dock.h" |
36 | 37 | #include "editor/docks/inspector_dock.h" |
37 | 38 | #include "editor/editor_main_screen.h" |
|
58 | 59 | #include "scene/gui/box_container.h" |
59 | 60 | #include "scene/gui/control.h" |
60 | 61 | #include "scene/main/window.h" |
| 62 | +#include "scene/resources/packed_scene.h" |
61 | 63 | #include "scene/resources/theme.h" |
62 | 64 |
|
63 | 65 | EditorInterface *EditorInterface::singleton = nullptr; |
@@ -363,6 +365,28 @@ void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, in |
363 | 365 | EditorFileSystem::get_singleton()->emit_signal(SNAME("filesystem_changed")); |
364 | 366 | } |
365 | 367 |
|
| 368 | +void EditorInterface::add_root_node(Node *p_node) { |
| 369 | + if (EditorNode::get_singleton()->get_edited_scene()) { |
| 370 | + ERR_PRINT("EditorInterface::add_root_node: The current scene already has a root node."); |
| 371 | + return; |
| 372 | + } |
| 373 | + |
| 374 | + const String &scene_path = p_node->get_scene_file_path(); |
| 375 | + if (!scene_path.is_empty()) { |
| 376 | + Ref<PackedScene> scene = ResourceLoader::load(scene_path); |
| 377 | + if (scene.is_valid()) { |
| 378 | + memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache. |
| 379 | + |
| 380 | + p_node->set_scene_inherited_state(scene->get_state()); |
| 381 | + p_node->set_scene_file_path(String()); |
| 382 | + } |
| 383 | + } |
| 384 | + |
| 385 | + EditorNode::get_singleton()->set_edited_scene(p_node); |
| 386 | + EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id()); |
| 387 | + EditorSceneTabs::get_singleton()->update_scene_tabs(); |
| 388 | +} |
| 389 | + |
366 | 390 | void EditorInterface::set_plugin_enabled(const String &p_plugin, bool p_enabled) { |
367 | 391 | EditorNode::get_singleton()->set_addon_plugin_enabled(p_plugin, p_enabled, true); |
368 | 392 | } |
@@ -870,6 +894,8 @@ void EditorInterface::_bind_methods() { |
870 | 894 | ClassDB::bind_method(D_METHOD("get_open_scene_roots"), &EditorInterface::get_open_scene_roots); |
871 | 895 | ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root); |
872 | 896 |
|
| 897 | + ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorInterface::add_root_node); |
| 898 | + |
873 | 899 | ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene); |
874 | 900 | ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true)); |
875 | 901 | ClassDB::bind_method(D_METHOD("save_all_scenes"), &EditorInterface::save_all_scenes); |
|
0 commit comments