mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +00:00
Relocate add_root_node
method to EditorInterface
from EditorScript
and deprecate old method
This commit is contained in:
parent
8b2739ee55
commit
11a4961081
5 changed files with 38 additions and 25 deletions
|
@ -19,6 +19,13 @@
|
||||||
<tutorials>
|
<tutorials>
|
||||||
</tutorials>
|
</tutorials>
|
||||||
<methods>
|
<methods>
|
||||||
|
<method name="add_root_node">
|
||||||
|
<return type="void" />
|
||||||
|
<param index="0" name="node" type="Node" />
|
||||||
|
<description>
|
||||||
|
Makes [param node] root of the currently opened scene. Only works if the scene is empty. If the [param node] is a scene instance, an inheriting scene will be created.
|
||||||
|
</description>
|
||||||
|
</method>
|
||||||
<method name="close_scene">
|
<method name="close_scene">
|
||||||
<return type="int" enum="Error" />
|
<return type="int" enum="Error" />
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -41,7 +41,7 @@
|
||||||
This method is executed by the Editor when [b]File > Run[/b] is used.
|
This method is executed by the Editor when [b]File > Run[/b] is used.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="add_root_node">
|
<method name="add_root_node" deprecated="Use [method EditorInterface.add_root_node] instead.">
|
||||||
<return type="void" />
|
<return type="void" />
|
||||||
<param index="0" name="node" type="Node" />
|
<param index="0" name="node" type="Node" />
|
||||||
<description>
|
<description>
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "editor_interface.compat.inc"
|
#include "editor_interface.compat.inc"
|
||||||
|
|
||||||
#include "core/config/project_settings.h"
|
#include "core/config/project_settings.h"
|
||||||
|
#include "core/io/resource_loader.h"
|
||||||
#include "editor/docks/filesystem_dock.h"
|
#include "editor/docks/filesystem_dock.h"
|
||||||
#include "editor/docks/inspector_dock.h"
|
#include "editor/docks/inspector_dock.h"
|
||||||
#include "editor/editor_main_screen.h"
|
#include "editor/editor_main_screen.h"
|
||||||
|
@ -58,6 +59,7 @@
|
||||||
#include "scene/gui/box_container.h"
|
#include "scene/gui/box_container.h"
|
||||||
#include "scene/gui/control.h"
|
#include "scene/gui/control.h"
|
||||||
#include "scene/main/window.h"
|
#include "scene/main/window.h"
|
||||||
|
#include "scene/resources/packed_scene.h"
|
||||||
#include "scene/resources/theme.h"
|
#include "scene/resources/theme.h"
|
||||||
|
|
||||||
EditorInterface *EditorInterface::singleton = nullptr;
|
EditorInterface *EditorInterface::singleton = nullptr;
|
||||||
|
@ -360,6 +362,28 @@ void EditorInterface::make_scene_preview(const String &p_path, Node *p_scene, in
|
||||||
EditorFileSystem::get_singleton()->emit_signal(SNAME("filesystem_changed"));
|
EditorFileSystem::get_singleton()->emit_signal(SNAME("filesystem_changed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditorInterface::add_root_node(Node *p_node) {
|
||||||
|
if (EditorNode::get_singleton()->get_edited_scene()) {
|
||||||
|
ERR_PRINT("EditorInterface::add_root_node: The current scene already has a root node.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const String &scene_path = p_node->get_scene_file_path();
|
||||||
|
if (!scene_path.is_empty()) {
|
||||||
|
Ref<PackedScene> scene = ResourceLoader::load(scene_path);
|
||||||
|
if (scene.is_valid()) {
|
||||||
|
memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache.
|
||||||
|
|
||||||
|
p_node->set_scene_inherited_state(scene->get_state());
|
||||||
|
p_node->set_scene_file_path(String());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EditorNode::get_singleton()->set_edited_scene(p_node);
|
||||||
|
EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id());
|
||||||
|
EditorSceneTabs::get_singleton()->update_scene_tabs();
|
||||||
|
}
|
||||||
|
|
||||||
void EditorInterface::set_plugin_enabled(const String &p_plugin, bool p_enabled) {
|
void EditorInterface::set_plugin_enabled(const String &p_plugin, bool p_enabled) {
|
||||||
EditorNode::get_singleton()->set_addon_plugin_enabled(p_plugin, p_enabled, true);
|
EditorNode::get_singleton()->set_addon_plugin_enabled(p_plugin, p_enabled, true);
|
||||||
}
|
}
|
||||||
|
@ -846,6 +870,8 @@ void EditorInterface::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("get_open_scene_roots"), &EditorInterface::get_open_scene_roots);
|
ClassDB::bind_method(D_METHOD("get_open_scene_roots"), &EditorInterface::get_open_scene_roots);
|
||||||
ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root);
|
ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorInterface::add_root_node);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene);
|
ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene);
|
||||||
ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true));
|
ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true));
|
||||||
ClassDB::bind_method(D_METHOD("save_all_scenes"), &EditorInterface::save_all_scenes);
|
ClassDB::bind_method(D_METHOD("save_all_scenes"), &EditorInterface::save_all_scenes);
|
||||||
|
|
|
@ -173,6 +173,8 @@ public:
|
||||||
TypedArray<Node> get_open_scene_roots() const;
|
TypedArray<Node> get_open_scene_roots() const;
|
||||||
Node *get_edited_scene_root() const;
|
Node *get_edited_scene_root() const;
|
||||||
|
|
||||||
|
void add_root_node(Node *p_node);
|
||||||
|
|
||||||
Error save_scene();
|
Error save_scene();
|
||||||
void save_scene_as(const String &p_scene, bool p_with_preview = true);
|
void save_scene_as(const String &p_scene, bool p_with_preview = true);
|
||||||
void mark_scene_as_unsaved();
|
void mark_scene_as_unsaved();
|
||||||
|
|
|
@ -38,30 +38,8 @@
|
||||||
#include "scene/resources/packed_scene.h"
|
#include "scene/resources/packed_scene.h"
|
||||||
|
|
||||||
void EditorScript::add_root_node(Node *p_node) {
|
void EditorScript::add_root_node(Node *p_node) {
|
||||||
if (!EditorNode::get_singleton()) {
|
WARN_DEPRECATED_MSG("EditorScript::add_root_node is deprecated. Use EditorInterface::add_root_node instead.");
|
||||||
EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("Write your logic in the _run() method."));
|
EditorInterface::get_singleton()->add_root_node(p_node);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EditorNode::get_singleton()->get_edited_scene()) {
|
|
||||||
EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("The current scene already has a root node."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const String &scene_path = p_node->get_scene_file_path();
|
|
||||||
if (!scene_path.is_empty()) {
|
|
||||||
Ref<PackedScene> scene = ResourceLoader::load(scene_path);
|
|
||||||
if (scene.is_valid()) {
|
|
||||||
memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache.
|
|
||||||
|
|
||||||
p_node->set_scene_inherited_state(scene->get_state());
|
|
||||||
p_node->set_scene_file_path(String());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
EditorNode::get_singleton()->set_edited_scene(p_node);
|
|
||||||
EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id());
|
|
||||||
EditorSceneTabs::get_singleton()->update_scene_tabs();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Node *EditorScript::get_scene() const {
|
Node *EditorScript::get_scene() const {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue