From dd7145b778ea4884fd52f5efaf79dc55375c8465 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sat, 26 Aug 2017 10:32:15 -0300 Subject: -Split EditorPlugin into EditorPlugin and EditorInterface -Added EditorInterface to EditorScript -Added functions to save the scene to EditorInterface --- editor/editor_plugin.cpp | 210 +++++++++++++++++++++++++++-------------------- 1 file changed, 122 insertions(+), 88 deletions(-) (limited to 'editor/editor_plugin.cpp') diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 220b5fb2d..a6e28e045 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -37,6 +37,124 @@ #include "scene/3d/camera.h" #include "scene/gui/popup_menu.h" +Control *EditorInterface::get_editor_viewport() { + + return EditorNode::get_singleton()->get_viewport(); +} + +void EditorInterface::edit_resource(const Ref &p_resource) { + + EditorNode::get_singleton()->edit_resource(p_resource); +} + +void EditorInterface::open_scene_from_path(const String &scene_path) { + + if (EditorNode::get_singleton()->is_changing_scene()) { + return; + } + + EditorNode::get_singleton()->open_request(scene_path); +} + +void EditorInterface::reload_scene_from_path(const String &scene_path) { + + if (EditorNode::get_singleton()->is_changing_scene()) { + return; + } + + EditorNode::get_singleton()->reload_scene(scene_path); +} + +Node *EditorInterface::get_edited_scene_root() { + return EditorNode::get_singleton()->get_edited_scene(); +} + +Array EditorInterface::get_open_scenes() const { + + Array ret; + Vector scenes = EditorNode::get_singleton()->get_editor_data().get_edited_scenes(); + + int scns_amount = scenes.size(); + for (int idx_scn = 0; idx_scn < scns_amount; idx_scn++) { + if (scenes[idx_scn].root == NULL) + continue; + ret.push_back(scenes[idx_scn].root->get_filename()); + } + return ret; +} + +ScriptEditor *EditorInterface::get_script_editor() { + return ScriptEditor::get_singleton(); +} + +void EditorInterface::inspect_object(Object *p_obj, const String &p_for_property) { + + EditorNode::get_singleton()->push_item(p_obj, p_for_property); +} + +EditorFileSystem *EditorInterface::get_resource_file_system() { + return EditorFileSystem::get_singleton(); +} + +EditorSelection *EditorInterface::get_selection() { + return EditorNode::get_singleton()->get_editor_selection(); +} + +EditorSettings *EditorInterface::get_editor_settings() { + return EditorSettings::get_singleton(); +} + +EditorResourcePreview *EditorInterface::get_resource_previewer() { + return EditorResourcePreview::get_singleton(); +} + +Control *EditorInterface::get_base_control() { + + return EditorNode::get_singleton()->get_gui_base(); +} + +Error EditorInterface::save_scene() { + if (!get_edited_scene_root()) + return ERR_CANT_CREATE; + if (get_edited_scene_root()->get_filename() == String()) + return ERR_CANT_CREATE; + + save_scene_as(get_edited_scene_root()->get_filename()); + return OK; +} + +void EditorInterface::save_scene_as(const String &p_scene, bool p_with_preview) { + + EditorNode::get_singleton()->save_scene_to_path(p_scene, p_with_preview); +} + +EditorInterface *EditorInterface::singleton = NULL; + +void EditorInterface::_bind_methods() { + + ClassDB::bind_method(D_METHOD("inspect_object", "object", "for_property"), &EditorInterface::inspect_object, DEFVAL(String())); + ClassDB::bind_method(D_METHOD("get_selection"), &EditorInterface::get_selection); + ClassDB::bind_method(D_METHOD("get_editor_settings"), &EditorInterface::get_editor_settings); + ClassDB::bind_method(D_METHOD("get_script_editor"), &EditorInterface::get_script_editor); + ClassDB::bind_method(D_METHOD("get_base_control"), &EditorInterface::get_base_control); + ClassDB::bind_method(D_METHOD("edit_resource", "resource"), &EditorInterface::edit_resource); + ClassDB::bind_method(D_METHOD("open_scene_from_path", "scene_filepath"), &EditorInterface::open_scene_from_path); + ClassDB::bind_method(D_METHOD("reload_scene_from_path", "scene_filepath"), &EditorInterface::reload_scene_from_path); + ClassDB::bind_method(D_METHOD("get_open_scenes"), &EditorInterface::get_open_scenes); + ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &EditorInterface::get_edited_scene_root); + ClassDB::bind_method(D_METHOD("get_resource_previewer"), &EditorInterface::get_resource_previewer); + ClassDB::bind_method(D_METHOD("get_resource_filesystem"), &EditorInterface::get_resource_file_system); + ClassDB::bind_method(D_METHOD("get_editor_viewport"), &EditorInterface::get_editor_viewport); + + 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)); +} + +EditorInterface::EditorInterface() { + singleton = this; +} + +/////////////////////////////////////////// void EditorPlugin::add_custom_type(const String &p_type, const String &p_base, const Ref