|
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; |
@@ -360,6 +362,28 @@ void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, in |
360 | 362 | EditorFileSystem::get_singleton()->emit_signal(SNAME("filesystem_changed")); |
361 | 363 | } |
362 | 364 |
|
| 365 | +void EditorInterface::add_root_node(Node *p_node) { |
| 366 | + if (EditorNode::get_singleton()->get_edited_scene()) { |
| 367 | + ERR_PRINT("EditorInterface::add_root_node: The current scene already has a root node."); |
| 368 | + return; |
| 369 | + } |
| 370 | + |
| 371 | + const String &scene_path = p_node->get_scene_file_path(); |
| 372 | + if (!scene_path.is_empty()) { |
| 373 | + Ref<PackedScene> scene = ResourceLoader::load(scene_path); |
| 374 | + if (scene.is_valid()) { |
| 375 | + memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache. |
| 376 | + |
| 377 | + p_node->set_scene_inherited_state(scene->get_state()); |
| 378 | + p_node->set_scene_file_path(String()); |
| 379 | + } |
| 380 | + } |
| 381 | + |
| 382 | + EditorNode::get_singleton()->set_edited_scene(p_node); |
| 383 | + EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id()); |
| 384 | + EditorSceneTabs::get_singleton()->update_scene_tabs(); |
| 385 | +} |
| 386 | + |
363 | 387 | void EditorInterface::set_plugin_enabled(const String &p_plugin, bool p_enabled) { |
364 | 388 | EditorNode::get_singleton()->set_addon_plugin_enabled(p_plugin, p_enabled, true); |
365 | 389 | } |
@@ -846,6 +870,8 @@ void EditorInterface::_bind_methods() { |
846 | 870 | ClassDB::bind_method(D_METHOD("get_open_scene_roots"), &EditorInterface::get_open_scene_roots); |
847 | 871 | ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root); |
848 | 872 |
|
| 873 | + ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorInterface::add_root_node); |
| 874 | + |
849 | 875 | ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene); |
850 | 876 | ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true)); |
851 | 877 | ClassDB::bind_method(D_METHOD("save_all_scenes"), &EditorInterface::save_all_scenes); |
|
0 commit comments