| 1 | /**************************************************************************/ |
| 2 | /* editor_plugin.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "editor_plugin.h" |
| 32 | #include "editor_plugin.compat.inc" |
| 33 | |
| 34 | #include "editor/debugger/editor_debugger_node.h" |
| 35 | #include "editor/debugger/editor_debugger_plugin.h" |
| 36 | #include "editor/docks/editor_dock.h" |
| 37 | #include "editor/docks/editor_dock_manager.h" |
| 38 | #include "editor/docks/inspector_dock.h" |
| 39 | #include "editor/docks/scene_tree_dock.h" |
| 40 | #include "editor/editor_interface.h" |
| 41 | #include "editor/editor_node.h" |
| 42 | #include "editor/editor_undo_redo_manager.h" |
| 43 | #include "editor/export/editor_export.h" |
| 44 | #include "editor/export/editor_export_platform.h" |
| 45 | #include "editor/file_system/editor_file_system.h" |
| 46 | #include "editor/gui/editor_bottom_panel.h" |
| 47 | #include "editor/gui/editor_title_bar.h" |
| 48 | #include "editor/import/3d/resource_importer_scene.h" |
| 49 | #include "editor/import/editor_import_plugin.h" |
| 50 | #include "editor/inspector/editor_inspector.h" |
| 51 | #include "editor/plugins/editor_plugin_list.h" |
| 52 | #include "editor/plugins/editor_resource_conversion_plugin.h" |
| 53 | #include "editor/scene/3d/node_3d_editor_plugin.h" |
| 54 | #include "editor/scene/canvas_item_editor_plugin.h" |
| 55 | #include "editor/script/script_editor_plugin.h" |
| 56 | #include "editor/settings/project_settings_editor.h" |
| 57 | #include "editor/translations/editor_translation_parser.h" |
| 58 | #include "scene/3d/camera_3d.h" |
| 59 | #include "scene/gui/popup_menu.h" |
| 60 | |
| 61 | void EditorPlugin::add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon) { |
| 62 | EditorNode::get_editor_data().add_custom_type(p_type, p_base, p_script, p_icon); |
| 63 | } |
| 64 | |
| 65 | void EditorPlugin::remove_custom_type(const String &p_type) { |
| 66 | EditorNode::get_editor_data().remove_custom_type(p_type); |
| 67 | } |
| 68 | |
| 69 | void EditorPlugin::add_autoload_singleton(const String &p_name, const String &p_path) { |
| 70 | if (p_path.begins_with("res://")) { |
| 71 | EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_add(p_name, p_path); |
| 72 | } else { |
| 73 | const Ref<Script> plugin_script = static_cast<Ref<Script>>(get_script()); |
| 74 | ERR_FAIL_COND(plugin_script.is_null()); |
| 75 | const String script_base_path = plugin_script->get_path().get_base_dir(); |
| 76 | EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_add(p_name, script_base_path.path_join(p_path)); |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | void EditorPlugin::remove_autoload_singleton(const String &p_name) { |
| 81 | EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name); |
| 82 | } |
| 83 | |
| 84 | #ifndef DISABLE_DEPRECATED |
| 85 | Button *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title, const Ref<Shortcut> &p_shortcut) { |
| 86 | ERR_FAIL_NULL_V(p_control, nullptr); |
| 87 | return EditorNode::get_bottom_panel()->add_item(p_title, p_control, p_shortcut); |
| 88 | } |
| 89 | |
| 90 | void EditorPlugin::add_control_to_dock(DockSlot p_slot, Control *p_control, const Ref<Shortcut> &p_shortcut) { |
| 91 | ERR_FAIL_NULL(p_control); |
| 92 | ERR_FAIL_COND(legacy_docks.has(p_control)); |
| 93 | |
| 94 | EditorDock *dock = memnew(EditorDock); |
| 95 | dock->set_title(p_control->get_name()); |
| 96 | dock->set_dock_shortcut(p_shortcut); |
| 97 | dock->set_default_slot((EditorDock::DockSlot)p_slot); |
| 98 | dock->add_child(p_control); |
| 99 | legacy_docks[p_control] = dock; |
| 100 | |
| 101 | EditorDockManager::get_singleton()->add_dock(dock); |
| 102 | } |
| 103 | |
| 104 | void EditorPlugin::remove_control_from_docks(Control *p_control) { |
| 105 | ERR_FAIL_NULL(p_control); |
| 106 | ERR_FAIL_COND(!legacy_docks.has(p_control)); |
| 107 | |
| 108 | EditorDockManager::get_singleton()->remove_dock(legacy_docks[p_control]); |
| 109 | legacy_docks[p_control]->queue_free(); |
| 110 | legacy_docks.erase(p_control); |
| 111 | } |
| 112 | |
| 113 | void EditorPlugin::set_dock_tab_icon(Control *p_control, const Ref<Texture2D> &p_icon) { |
| 114 | ERR_FAIL_NULL(p_control); |
| 115 | ERR_FAIL_COND(!legacy_docks.has(p_control)); |
| 116 | legacy_docks[p_control]->set_dock_icon(p_icon); |
| 117 | } |
| 118 | |
| 119 | void EditorPlugin::remove_control_from_bottom_panel(Control *p_control) { |
| 120 | ERR_FAIL_NULL(p_control); |
| 121 | EditorNode::get_bottom_panel()->remove_item(p_control); |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | void EditorPlugin::add_dock(EditorDock *p_dock) { |
| 126 | EditorDockManager::get_singleton()->add_dock(p_dock); |
| 127 | } |
| 128 | |
| 129 | void EditorPlugin::remove_dock(EditorDock *p_dock) { |
| 130 | EditorDockManager::get_singleton()->remove_dock(p_dock); |
| 131 | } |
| 132 | |
| 133 | void EditorPlugin::add_control_to_container(CustomControlContainer p_location, Control *p_control) { |
| 134 | ERR_FAIL_NULL(p_control); |
| 135 | |
| 136 | switch (p_location) { |
| 137 | case CONTAINER_TOOLBAR: { |
| 138 | EditorNode::get_title_bar()->add_child(p_control); |
| 139 | } break; |
| 140 | |
| 141 | case CONTAINER_SPATIAL_EDITOR_MENU: { |
| 142 | Node3DEditor::get_singleton()->add_control_to_menu_panel(p_control); |
| 143 | |
| 144 | } break; |
| 145 | case CONTAINER_SPATIAL_EDITOR_SIDE_LEFT: { |
| 146 | Node3DEditor::get_singleton()->add_control_to_left_panel(p_control); |
| 147 | } break; |
| 148 | case CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT: { |
| 149 | Node3DEditor::get_singleton()->add_control_to_right_panel(p_control); |
| 150 | } break; |
| 151 | case CONTAINER_SPATIAL_EDITOR_BOTTOM: { |
| 152 | Node3DEditor::get_singleton()->get_shader_split()->add_child(p_control); |
| 153 | |
| 154 | } break; |
| 155 | case CONTAINER_CANVAS_EDITOR_MENU: { |
| 156 | CanvasItemEditor::get_singleton()->add_control_to_menu_panel(p_control); |
| 157 | |
| 158 | } break; |
| 159 | case CONTAINER_CANVAS_EDITOR_SIDE_LEFT: { |
| 160 | CanvasItemEditor::get_singleton()->add_control_to_left_panel(p_control); |
| 161 | } break; |
| 162 | case CONTAINER_CANVAS_EDITOR_SIDE_RIGHT: { |
| 163 | CanvasItemEditor::get_singleton()->add_control_to_right_panel(p_control); |
| 164 | } break; |
| 165 | case CONTAINER_CANVAS_EDITOR_BOTTOM: { |
| 166 | CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control); |
| 167 | |
| 168 | } break; |
| 169 | case CONTAINER_INSPECTOR_BOTTOM: { |
| 170 | InspectorDock::get_singleton()->get_addon_area()->add_child(p_control); |
| 171 | |
| 172 | } break; |
| 173 | case CONTAINER_PROJECT_SETTING_TAB_LEFT: { |
| 174 | ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(p_control); |
| 175 | ProjectSettingsEditor::get_singleton()->get_tabs()->move_child(p_control, 0); |
| 176 | |
| 177 | } break; |
| 178 | case CONTAINER_PROJECT_SETTING_TAB_RIGHT: { |
| 179 | ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(p_control); |
| 180 | |
| 181 | } break; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void EditorPlugin::remove_control_from_container(CustomControlContainer p_location, Control *p_control) { |
| 186 | ERR_FAIL_NULL(p_control); |
| 187 | |
| 188 | switch (p_location) { |
| 189 | case CONTAINER_TOOLBAR: { |
| 190 | EditorNode::get_title_bar()->remove_child(p_control); |
| 191 | } break; |
| 192 | |
| 193 | case CONTAINER_SPATIAL_EDITOR_MENU: { |
| 194 | Node3DEditor::get_singleton()->remove_control_from_menu_panel(p_control); |
| 195 | |
| 196 | } break; |
| 197 | case CONTAINER_SPATIAL_EDITOR_SIDE_LEFT: { |
| 198 | Node3DEditor::get_singleton()->remove_control_from_left_panel(p_control); |
| 199 | } break; |
| 200 | case CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT: { |
| 201 | Node3DEditor::get_singleton()->remove_control_from_right_panel(p_control); |
| 202 | } break; |
| 203 | case CONTAINER_SPATIAL_EDITOR_BOTTOM: { |
| 204 | Node3DEditor::get_singleton()->get_shader_split()->remove_child(p_control); |
| 205 | |
| 206 | } break; |
| 207 | case CONTAINER_CANVAS_EDITOR_MENU: { |
| 208 | CanvasItemEditor::get_singleton()->remove_control_from_menu_panel(p_control); |
| 209 | |
| 210 | } break; |
| 211 | case CONTAINER_CANVAS_EDITOR_SIDE_LEFT: { |
| 212 | CanvasItemEditor::get_singleton()->remove_control_from_left_panel(p_control); |
| 213 | } break; |
| 214 | case CONTAINER_CANVAS_EDITOR_SIDE_RIGHT: { |
| 215 | CanvasItemEditor::get_singleton()->remove_control_from_right_panel(p_control); |
| 216 | } break; |
| 217 | case CONTAINER_CANVAS_EDITOR_BOTTOM: { |
| 218 | CanvasItemEditor::get_singleton()->get_bottom_split()->remove_child(p_control); |
| 219 | |
| 220 | } break; |
| 221 | case CONTAINER_INSPECTOR_BOTTOM: { |
| 222 | InspectorDock::get_singleton()->get_addon_area()->remove_child(p_control); |
| 223 | |
| 224 | } break; |
| 225 | case CONTAINER_PROJECT_SETTING_TAB_LEFT: |
| 226 | case CONTAINER_PROJECT_SETTING_TAB_RIGHT: { |
| 227 | ProjectSettingsEditor::get_singleton()->get_tabs()->remove_child(p_control); |
| 228 | |
| 229 | } break; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | void EditorPlugin::add_tool_menu_item(const String &p_name, const Callable &p_callable) { |
| 234 | EditorNode::get_singleton()->add_tool_menu_item(p_name, p_callable); |
| 235 | } |
| 236 | |
| 237 | void EditorPlugin::add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu) { |
| 238 | ERR_FAIL_NULL(p_submenu); |
| 239 | EditorNode::get_singleton()->add_tool_submenu_item(p_name, p_submenu); |
| 240 | } |
| 241 | |
| 242 | void EditorPlugin::remove_tool_menu_item(const String &p_name) { |
| 243 | EditorNode::get_singleton()->remove_tool_menu_item(p_name); |
| 244 | } |
| 245 | |
| 246 | PopupMenu *EditorPlugin::get_export_as_menu() { |
| 247 | return EditorNode::get_singleton()->get_export_as_menu(); |
| 248 | } |
| 249 | |
| 250 | void EditorPlugin::set_input_event_forwarding_always_enabled() { |
| 251 | input_event_forwarding_always_enabled = true; |
| 252 | EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding()->add_plugin(this); |
| 253 | } |
| 254 | |
| 255 | void EditorPlugin::set_force_draw_over_forwarding_enabled() { |
| 256 | force_draw_over_forwarding_enabled = true; |
| 257 | EditorNode::get_singleton()->get_editor_plugins_force_over()->add_plugin(this); |
| 258 | } |
| 259 | |
| 260 | void EditorPlugin::notify_scene_changed(const Node *scn_root) { |
| 261 | emit_signal(SNAME("scene_changed"), scn_root); |
| 262 | } |
| 263 | |
| 264 | void EditorPlugin::notify_main_screen_changed(const String &screen_name) { |
| 265 | if (screen_name == last_main_screen_name) { |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | emit_signal(SNAME("main_screen_changed"), screen_name); |
| 270 | last_main_screen_name = screen_name; |
| 271 | } |
| 272 | |
| 273 | void EditorPlugin::notify_scene_closed(const String &scene_filepath) { |
| 274 | emit_signal(SNAME("scene_closed"), scene_filepath); |
| 275 | } |
| 276 | |
| 277 | void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) { |
| 278 | emit_signal(SNAME("resource_saved"), p_resource); |
| 279 | } |
| 280 | |
| 281 | void EditorPlugin::notify_scene_saved(const String &p_scene_filepath) { |
| 282 | emit_signal(SNAME("scene_saved"), p_scene_filepath); |
| 283 | } |
| 284 | |
| 285 | bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { |
| 286 | bool success = false; |
| 287 | GDVIRTUAL_CALL(_forward_canvas_gui_input, p_event, success); |
| 288 | return success; |
| 289 | } |
| 290 | |
| 291 | void EditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) { |
| 292 | GDVIRTUAL_CALL(_forward_canvas_draw_over_viewport, p_overlay); |
| 293 | } |
| 294 | |
| 295 | void EditorPlugin::forward_canvas_force_draw_over_viewport(Control *p_overlay) { |
| 296 | GDVIRTUAL_CALL(_forward_canvas_force_draw_over_viewport, p_overlay); |
| 297 | } |
| 298 | |
| 299 | // Updates the overlays of the 2D viewport or, if in 3D mode, of every 3D viewport. |
| 300 | int EditorPlugin::update_overlays() const { |
| 301 | if (Node3DEditor::get_singleton()->is_visible()) { |
| 302 | int count = 0; |
| 303 | for (uint32_t i = 0; i < Node3DEditor::VIEWPORTS_COUNT; i++) { |
| 304 | Node3DEditorViewport *vp = Node3DEditor::get_singleton()->get_editor_viewport(i); |
| 305 | if (vp->is_visible()) { |
| 306 | vp->update_surface(); |
| 307 | count++; |
| 308 | } |
| 309 | } |
| 310 | return count; |
| 311 | } else { |
| 312 | // This will update the normal viewport itself as well |
| 313 | CanvasItemEditor::get_singleton()->get_viewport_control()->queue_redraw(); |
| 314 | return 1; |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | EditorPlugin::AfterGUIInput EditorPlugin::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { |
| 319 | int success = EditorPlugin::AFTER_GUI_INPUT_PASS; |
| 320 | GDVIRTUAL_CALL(_forward_3d_gui_input, p_camera, p_event, success); |
| 321 | return static_cast<EditorPlugin::AfterGUIInput>(success); |
| 322 | } |
| 323 | |
| 324 | void EditorPlugin::forward_3d_draw_over_viewport(Control *p_overlay) { |
| 325 | GDVIRTUAL_CALL(_forward_3d_draw_over_viewport, p_overlay); |
| 326 | } |
| 327 | |
| 328 | void EditorPlugin::forward_3d_force_draw_over_viewport(Control *p_overlay) { |
| 329 | GDVIRTUAL_CALL(_forward_3d_force_draw_over_viewport, p_overlay); |
| 330 | } |
| 331 | |
| 332 | String EditorPlugin::get_plugin_name() const { |
| 333 | String name; |
| 334 | GDVIRTUAL_CALL(_get_plugin_name, name); |
| 335 | return name; |
| 336 | } |
| 337 | |
| 338 | const Ref<Texture2D> EditorPlugin::get_plugin_icon() const { |
| 339 | Ref<Texture2D> icon; |
| 340 | GDVIRTUAL_CALL(_get_plugin_icon, icon); |
| 341 | return icon; |
| 342 | } |
| 343 | |
| 344 | String EditorPlugin::get_plugin_version() const { |
| 345 | return plugin_version; |
| 346 | } |
| 347 | |
| 348 | void EditorPlugin::set_plugin_version(const String &p_version) { |
| 349 | plugin_version = p_version; |
| 350 | } |
| 351 | |
| 352 | bool EditorPlugin::has_main_screen() const { |
| 353 | bool success = false; |
| 354 | GDVIRTUAL_CALL(_has_main_screen, success); |
| 355 | return success; |
| 356 | } |
| 357 | |
| 358 | void EditorPlugin::make_visible(bool p_visible) { |
| 359 | GDVIRTUAL_CALL(_make_visible, p_visible); |
| 360 | } |
| 361 | |
| 362 | void EditorPlugin::edit(Object *p_object) { |
| 363 | GDVIRTUAL_CALL(_edit, p_object); |
| 364 | } |
| 365 | |
| 366 | bool EditorPlugin::handles(Object *p_object) const { |
| 367 | bool success = false; |
| 368 | GDVIRTUAL_CALL(_handles, p_object, success); |
| 369 | return success; |
| 370 | } |
| 371 | |
| 372 | bool EditorPlugin::can_auto_hide() const { |
| 373 | return true; |
| 374 | } |
| 375 | |
| 376 | Dictionary EditorPlugin::get_state() const { |
| 377 | Dictionary state; |
| 378 | GDVIRTUAL_CALL(_get_state, state); |
| 379 | return state; |
| 380 | } |
| 381 | |
| 382 | void EditorPlugin::set_state(const Dictionary &p_state) { |
| 383 | GDVIRTUAL_CALL(_set_state, p_state); |
| 384 | } |
| 385 | |
| 386 | void EditorPlugin::clear() { |
| 387 | GDVIRTUAL_CALL(_clear); |
| 388 | } |
| 389 | |
| 390 | String EditorPlugin::get_unsaved_status(const String &p_for_scene) const { |
| 391 | String ret; |
| 392 | GDVIRTUAL_CALL(_get_unsaved_status, p_for_scene, ret); |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | void EditorPlugin::save_external_data() { |
| 397 | GDVIRTUAL_CALL(_save_external_data); |
| 398 | } |
| 399 | |
| 400 | // if changes are pending in editor, apply them |
| 401 | void EditorPlugin::apply_changes() { |
| 402 | GDVIRTUAL_CALL(_apply_changes); |
| 403 | } |
| 404 | |
| 405 | void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { |
| 406 | PackedStringArray arr; |
| 407 | if (GDVIRTUAL_CALL(_get_breakpoints, arr)) { |
| 408 | for (int i = 0; i < arr.size(); i++) { |
| 409 | p_breakpoints->push_back(arr[i]); |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | bool EditorPlugin::get_remove_list(List<Node *> *p_list) { |
| 415 | return false; |
| 416 | } |
| 417 | |
| 418 | void EditorPlugin::add_undo_redo_inspector_hook_callback(Callable p_callable) { |
| 419 | EditorNode::get_editor_data().add_undo_redo_inspector_hook_callback(p_callable); |
| 420 | } |
| 421 | |
| 422 | void EditorPlugin::remove_undo_redo_inspector_hook_callback(Callable p_callable) { |
| 423 | EditorNode::get_editor_data().remove_undo_redo_inspector_hook_callback(p_callable); |
| 424 | } |
| 425 | |
| 426 | void EditorPlugin::add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) { |
| 427 | ERR_FAIL_COND(p_parser.is_null()); |
| 428 | EditorTranslationParser::get_singleton()->add_parser(p_parser, EditorTranslationParser::CUSTOM); |
| 429 | } |
| 430 | |
| 431 | void EditorPlugin::remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) { |
| 432 | ERR_FAIL_COND(p_parser.is_null()); |
| 433 | EditorTranslationParser::get_singleton()->remove_parser(p_parser, EditorTranslationParser::CUSTOM); |
| 434 | } |
| 435 | |
| 436 | void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority) { |
| 437 | ERR_FAIL_COND(p_importer.is_null()); |
| 438 | ResourceFormatImporter::get_singleton()->add_importer(p_importer, p_first_priority); |
| 439 | // Plugins are now loaded during the first scan. It's important not to start another scan, |
| 440 | // even a deferred one, as it would cause a scan during a scan at the next main thread iteration. |
| 441 | if (!EditorFileSystem::get_singleton()->doing_first_scan()) { |
| 442 | callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan).call_deferred(); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) { |
| 447 | ERR_FAIL_COND(p_importer.is_null()); |
| 448 | ResourceFormatImporter::get_singleton()->remove_importer(p_importer); |
| 449 | // Plugins are now loaded during the first scan. It's important not to start another scan, |
| 450 | // even a deferred one, as it would cause a scan during a scan at the next main thread iteration. |
| 451 | if (!EditorNode::get_singleton()->is_exiting() && !EditorFileSystem::get_singleton()->doing_first_scan()) { |
| 452 | callable_mp(EditorFileSystem::get_singleton(), &EditorFileSystem::scan).call_deferred(); |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin> &p_exporter) { |
| 457 | ERR_FAIL_COND(p_exporter.is_null()); |
| 458 | EditorExport::get_singleton()->add_export_plugin(p_exporter); |
| 459 | } |
| 460 | |
| 461 | void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter) { |
| 462 | ERR_FAIL_COND(p_exporter.is_null()); |
| 463 | EditorExport::get_singleton()->remove_export_plugin(p_exporter); |
| 464 | } |
| 465 | |
| 466 | void EditorPlugin::add_export_platform(const Ref<EditorExportPlatform> &p_platform) { |
| 467 | ERR_FAIL_COND(p_platform.is_null()); |
| 468 | EditorExport::get_singleton()->add_export_platform(p_platform); |
| 469 | } |
| 470 | |
| 471 | void EditorPlugin::remove_export_platform(const Ref<EditorExportPlatform> &p_platform) { |
| 472 | ERR_FAIL_COND(p_platform.is_null()); |
| 473 | EditorExport::get_singleton()->remove_export_platform(p_platform); |
| 474 | } |
| 475 | |
| 476 | void EditorPlugin::add_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) { |
| 477 | ERR_FAIL_COND(p_gizmo_plugin.is_null()); |
| 478 | Node3DEditor::get_singleton()->add_gizmo_plugin(p_gizmo_plugin); |
| 479 | } |
| 480 | |
| 481 | void EditorPlugin::remove_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) { |
| 482 | ERR_FAIL_COND(p_gizmo_plugin.is_null()); |
| 483 | Node3DEditor::get_singleton()->remove_gizmo_plugin(p_gizmo_plugin); |
| 484 | } |
| 485 | |
| 486 | void EditorPlugin::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { |
| 487 | ERR_FAIL_COND(p_plugin.is_null()); |
| 488 | EditorInspector::add_inspector_plugin(p_plugin); |
| 489 | } |
| 490 | |
| 491 | void EditorPlugin::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { |
| 492 | ERR_FAIL_COND(p_plugin.is_null()); |
| 493 | EditorInspector::remove_inspector_plugin(p_plugin); |
| 494 | } |
| 495 | |
| 496 | void EditorPlugin::add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer, bool p_first_priority) { |
| 497 | ERR_FAIL_COND(p_importer.is_null()); |
| 498 | ResourceImporterScene::add_scene_importer(p_importer, p_first_priority); |
| 499 | } |
| 500 | |
| 501 | void EditorPlugin::remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer) { |
| 502 | ERR_FAIL_COND(p_importer.is_null()); |
| 503 | ResourceImporterScene::remove_scene_importer(p_importer); |
| 504 | } |
| 505 | |
| 506 | void EditorPlugin::add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority) { |
| 507 | ResourceImporterScene::add_post_importer_plugin(p_plugin, p_first_priority); |
| 508 | } |
| 509 | |
| 510 | void EditorPlugin::remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin) { |
| 511 | ResourceImporterScene::remove_post_importer_plugin(p_plugin); |
| 512 | } |
| 513 | |
| 514 | void EditorPlugin::add_context_menu_plugin(EditorContextMenuPlugin::ContextMenuSlot p_slot, const Ref<EditorContextMenuPlugin> &p_plugin) { |
| 515 | EditorContextMenuPluginManager::get_singleton()->add_plugin(p_slot, p_plugin); |
| 516 | } |
| 517 | |
| 518 | void EditorPlugin::remove_context_menu_plugin(const Ref<EditorContextMenuPlugin> &p_plugin) { |
| 519 | EditorContextMenuPluginManager::get_singleton()->remove_plugin(p_plugin); |
| 520 | } |
| 521 | |
| 522 | int find(const PackedStringArray &a, const String &v) { |
| 523 | const String *r = a.ptr(); |
| 524 | for (int j = 0; j < a.size(); ++j) { |
| 525 | if (r[j] == v) { |
| 526 | return j; |
| 527 | } |
| 528 | } |
| 529 | return -1; |
| 530 | } |
| 531 | |
| 532 | void EditorPlugin::enable_plugin() { |
| 533 | // Called when the plugin gets enabled in project settings, after it's added to the tree. |
| 534 | // You can implement it to register autoloads. |
| 535 | GDVIRTUAL_CALL(_enable_plugin); |
| 536 | } |
| 537 | |
| 538 | void EditorPlugin::disable_plugin() { |
| 539 | // Last function called when the plugin gets disabled in project settings. |
| 540 | // Implement it to cleanup things from the project, such as unregister autoloads. |
| 541 | GDVIRTUAL_CALL(_disable_plugin); |
| 542 | } |
| 543 | |
| 544 | void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { |
| 545 | GDVIRTUAL_CALL(_set_window_layout, p_layout); |
| 546 | } |
| 547 | |
| 548 | void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { |
| 549 | GDVIRTUAL_CALL(_get_window_layout, p_layout); |
| 550 | } |
| 551 | |
| 552 | bool EditorPlugin::build() { |
| 553 | bool success = true; |
| 554 | GDVIRTUAL_CALL(_build, success); |
| 555 | return success; |
| 556 | } |
| 557 | |
| 558 | void EditorPlugin::run_scene(const String &p_scene, Vector<String> &r_args) { |
| 559 | Vector<String> new_args; |
| 560 | if (GDVIRTUAL_CALL(_run_scene, p_scene, r_args, new_args)) { |
| 561 | r_args = new_args; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | void EditorPlugin::queue_save_layout() { |
| 566 | EditorNode::get_singleton()->save_editor_layout_delayed(); |
| 567 | } |
| 568 | |
| 569 | void EditorPlugin::make_bottom_panel_item_visible(Control *p_item) { |
| 570 | EditorNode::get_bottom_panel()->make_item_visible(p_item); |
| 571 | } |
| 572 | |
| 573 | void EditorPlugin::hide_bottom_panel() { |
| 574 | EditorNode::get_bottom_panel()->hide_bottom_panel(); |
| 575 | } |
| 576 | |
| 577 | EditorInterface *EditorPlugin::get_editor_interface() { |
| 578 | return EditorInterface::get_singleton(); |
| 579 | } |
| 580 | |
| 581 | ScriptCreateDialog *EditorPlugin::get_script_create_dialog() { |
| 582 | return SceneTreeDock::get_singleton()->get_script_create_dialog(); |
| 583 | } |
| 584 | |
| 585 | void EditorPlugin::add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) { |
| 586 | EditorDebuggerNode::get_singleton()->add_debugger_plugin(p_plugin); |
| 587 | } |
| 588 | |
| 589 | void EditorPlugin::remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) { |
| 590 | EditorDebuggerNode::get_singleton()->remove_debugger_plugin(p_plugin); |
| 591 | } |
| 592 | |
| 593 | void EditorPlugin::add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) { |
| 594 | EditorNode::get_singleton()->add_resource_conversion_plugin(p_plugin); |
| 595 | } |
| 596 | |
| 597 | void EditorPlugin::remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) { |
| 598 | EditorNode::get_singleton()->remove_resource_conversion_plugin(p_plugin); |
| 599 | } |
| 600 | |
| 601 | #ifndef DISABLE_DEPRECATED |
| 602 | void EditorPlugin::_editor_project_settings_changed() { |
| 603 | emit_signal(SNAME("project_settings_changed")); |
| 604 | } |
| 605 | #endif |
| 606 | |
| 607 | void EditorPlugin::_notification(int p_what) { |
| 608 | #ifndef DISABLE_DEPRECATED |
| 609 | switch (p_what) { |
| 610 | case NOTIFICATION_ENTER_TREE: { |
| 611 | ProjectSettings::get_singleton()->connect("settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed)); |
| 612 | } break; |
| 613 | |
| 614 | case NOTIFICATION_EXIT_TREE: { |
| 615 | ProjectSettings::get_singleton()->disconnect("settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed)); |
| 616 | } break; |
| 617 | } |
| 618 | #endif |
| 619 | } |
| 620 | |
| 621 | void EditorPlugin::_bind_methods() { |
| 622 | ClassDB::bind_method(D_METHOD("add_dock", "dock"), &EditorPlugin::add_dock); |
| 623 | ClassDB::bind_method(D_METHOD("remove_dock", "dock"), &EditorPlugin::remove_dock); |
| 624 | ClassDB::bind_method(D_METHOD("add_control_to_container", "container", "control"), &EditorPlugin::add_control_to_container); |
| 625 | ClassDB::bind_method(D_METHOD("remove_control_from_container", "container", "control"), &EditorPlugin::remove_control_from_container); |
| 626 | ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "callable"), &EditorPlugin::add_tool_menu_item); |
| 627 | ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item); |
| 628 | ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"), &EditorPlugin::remove_tool_menu_item); |
| 629 | ClassDB::bind_method(D_METHOD("get_export_as_menu"), &EditorPlugin::get_export_as_menu); |
| 630 | ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type); |
| 631 | ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type); |
| 632 | |
| 633 | #ifndef DISABLE_DEPRECATED |
| 634 | ClassDB::bind_method(D_METHOD("add_control_to_dock", "slot", "control", "shortcut"), &EditorPlugin::add_control_to_dock, DEFVAL(Ref<Shortcut>())); |
| 635 | ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks); |
| 636 | ClassDB::bind_method(D_METHOD("set_dock_tab_icon", "control", "icon"), &EditorPlugin::set_dock_tab_icon); |
| 637 | ClassDB::bind_method(D_METHOD("add_control_to_bottom_panel", "control", "title", "shortcut"), &EditorPlugin::add_control_to_bottom_panel, DEFVAL(Ref<Shortcut>())); |
| 638 | ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel); |
| 639 | #endif |
| 640 | |
| 641 | ClassDB::bind_method(D_METHOD("add_autoload_singleton", "name", "path"), &EditorPlugin::add_autoload_singleton); |
| 642 | ClassDB::bind_method(D_METHOD("remove_autoload_singleton", "name"), &EditorPlugin::remove_autoload_singleton); |
| 643 | |
| 644 | ClassDB::bind_method(D_METHOD("update_overlays"), &EditorPlugin::update_overlays); |
| 645 | |
| 646 | ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible", "item"), &EditorPlugin::make_bottom_panel_item_visible); |
| 647 | ClassDB::bind_method(D_METHOD("hide_bottom_panel"), &EditorPlugin::hide_bottom_panel); |
| 648 | |
| 649 | ClassDB::bind_method(D_METHOD("get_undo_redo"), &EditorPlugin::get_undo_redo); |
| 650 | ClassDB::bind_method(D_METHOD("add_undo_redo_inspector_hook_callback", "callable"), &EditorPlugin::add_undo_redo_inspector_hook_callback); |
| 651 | ClassDB::bind_method(D_METHOD("remove_undo_redo_inspector_hook_callback", "callable"), &EditorPlugin::remove_undo_redo_inspector_hook_callback); |
| 652 | ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout); |
| 653 | ClassDB::bind_method(D_METHOD("add_translation_parser_plugin", "parser"), &EditorPlugin::add_translation_parser_plugin); |
| 654 | ClassDB::bind_method(D_METHOD("remove_translation_parser_plugin", "parser"), &EditorPlugin::remove_translation_parser_plugin); |
| 655 | ClassDB::bind_method(D_METHOD("add_import_plugin", "importer", "first_priority"), &EditorPlugin::add_import_plugin, DEFVAL(false)); |
| 656 | ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin); |
| 657 | ClassDB::bind_method(D_METHOD("add_scene_format_importer_plugin", "scene_format_importer", "first_priority"), &EditorPlugin::add_scene_format_importer_plugin, DEFVAL(false)); |
| 658 | ClassDB::bind_method(D_METHOD("remove_scene_format_importer_plugin", "scene_format_importer"), &EditorPlugin::remove_scene_format_importer_plugin); |
| 659 | ClassDB::bind_method(D_METHOD("add_scene_post_import_plugin", "scene_import_plugin", "first_priority"), &EditorPlugin::add_scene_post_import_plugin, DEFVAL(false)); |
| 660 | ClassDB::bind_method(D_METHOD("remove_scene_post_import_plugin", "scene_import_plugin"), &EditorPlugin::remove_scene_post_import_plugin); |
| 661 | ClassDB::bind_method(D_METHOD("add_export_plugin", "plugin"), &EditorPlugin::add_export_plugin); |
| 662 | ClassDB::bind_method(D_METHOD("remove_export_plugin", "plugin"), &EditorPlugin::remove_export_plugin); |
| 663 | ClassDB::bind_method(D_METHOD("add_export_platform", "platform"), &EditorPlugin::add_export_platform); |
| 664 | ClassDB::bind_method(D_METHOD("remove_export_platform", "platform"), &EditorPlugin::remove_export_platform); |
| 665 | ClassDB::bind_method(D_METHOD("add_node_3d_gizmo_plugin", "plugin"), &EditorPlugin::add_node_3d_gizmo_plugin); |
| 666 | ClassDB::bind_method(D_METHOD("remove_node_3d_gizmo_plugin", "plugin"), &EditorPlugin::remove_node_3d_gizmo_plugin); |
| 667 | ClassDB::bind_method(D_METHOD("add_inspector_plugin", "plugin"), &EditorPlugin::add_inspector_plugin); |
| 668 | ClassDB::bind_method(D_METHOD("remove_inspector_plugin", "plugin"), &EditorPlugin::remove_inspector_plugin); |
| 669 | ClassDB::bind_method(D_METHOD("add_resource_conversion_plugin", "plugin"), &EditorPlugin::add_resource_conversion_plugin); |
| 670 | ClassDB::bind_method(D_METHOD("remove_resource_conversion_plugin", "plugin"), &EditorPlugin::remove_resource_conversion_plugin); |
| 671 | ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled); |
| 672 | ClassDB::bind_method(D_METHOD("set_force_draw_over_forwarding_enabled"), &EditorPlugin::set_force_draw_over_forwarding_enabled); |
| 673 | ClassDB::bind_method(D_METHOD("add_context_menu_plugin", "slot", "plugin"), &EditorPlugin::add_context_menu_plugin); |
| 674 | ClassDB::bind_method(D_METHOD("remove_context_menu_plugin", "plugin"), &EditorPlugin::remove_context_menu_plugin); |
| 675 | |
| 676 | ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface); |
| 677 | ClassDB::bind_method(D_METHOD("get_script_create_dialog"), &EditorPlugin::get_script_create_dialog); |
| 678 | ClassDB::bind_method(D_METHOD("add_debugger_plugin", "script"), &EditorPlugin::add_debugger_plugin); |
| 679 | ClassDB::bind_method(D_METHOD("remove_debugger_plugin", "script"), &EditorPlugin::remove_debugger_plugin); |
| 680 | ClassDB::bind_method(D_METHOD("get_plugin_version"), &EditorPlugin::get_plugin_version); |
| 681 | |
| 682 | GDVIRTUAL_BIND(_forward_canvas_gui_input, "event"); |
| 683 | GDVIRTUAL_BIND(_forward_canvas_draw_over_viewport, "viewport_control"); |
| 684 | GDVIRTUAL_BIND(_forward_canvas_force_draw_over_viewport, "viewport_control"); |
| 685 | GDVIRTUAL_BIND(_forward_3d_gui_input, "viewport_camera", "event"); |
| 686 | GDVIRTUAL_BIND(_forward_3d_draw_over_viewport, "viewport_control"); |
| 687 | GDVIRTUAL_BIND(_forward_3d_force_draw_over_viewport, "viewport_control"); |
| 688 | GDVIRTUAL_BIND(_get_plugin_name); |
| 689 | GDVIRTUAL_BIND(_get_plugin_icon); |
| 690 | GDVIRTUAL_BIND(_has_main_screen); |
| 691 | GDVIRTUAL_BIND(_make_visible, "visible"); |
| 692 | GDVIRTUAL_BIND(_edit, "object"); |
| 693 | GDVIRTUAL_BIND(_handles, "object"); |
| 694 | GDVIRTUAL_BIND(_get_state); |
| 695 | GDVIRTUAL_BIND(_set_state, "state"); |
| 696 | GDVIRTUAL_BIND(_clear); |
| 697 | GDVIRTUAL_BIND(_get_unsaved_status, "for_scene"); |
| 698 | GDVIRTUAL_BIND(_save_external_data); |
| 699 | GDVIRTUAL_BIND(_apply_changes); |
| 700 | GDVIRTUAL_BIND(_get_breakpoints); |
| 701 | GDVIRTUAL_BIND(_set_window_layout, "configuration"); |
| 702 | GDVIRTUAL_BIND(_get_window_layout, "configuration"); |
| 703 | GDVIRTUAL_BIND(_build); |
| 704 | GDVIRTUAL_BIND(_run_scene, "scene", "args"); |
| 705 | GDVIRTUAL_BIND(_enable_plugin); |
| 706 | GDVIRTUAL_BIND(_disable_plugin); |
| 707 | |
| 708 | ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); |
| 709 | ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath"))); |
| 710 | ADD_SIGNAL(MethodInfo("main_screen_changed", PropertyInfo(Variant::STRING, "screen_name"))); |
| 711 | ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"))); |
| 712 | ADD_SIGNAL(MethodInfo("scene_saved", PropertyInfo(Variant::STRING, "filepath"))); |
| 713 | ADD_SIGNAL(MethodInfo("project_settings_changed")); |
| 714 | |
| 715 | BIND_ENUM_CONSTANT(CONTAINER_TOOLBAR); |
| 716 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_MENU); |
| 717 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE_LEFT); |
| 718 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT); |
| 719 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_BOTTOM); |
| 720 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_MENU); |
| 721 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE_LEFT); |
| 722 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE_RIGHT); |
| 723 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_BOTTOM); |
| 724 | BIND_ENUM_CONSTANT(CONTAINER_INSPECTOR_BOTTOM); |
| 725 | BIND_ENUM_CONSTANT(CONTAINER_PROJECT_SETTING_TAB_LEFT); |
| 726 | BIND_ENUM_CONSTANT(CONTAINER_PROJECT_SETTING_TAB_RIGHT); |
| 727 | |
| 728 | BIND_ENUM_CONSTANT(DOCK_SLOT_NONE); |
| 729 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UL); |
| 730 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BL); |
| 731 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UR); |
| 732 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BR); |
| 733 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UL); |
| 734 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BL); |
| 735 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR); |
| 736 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR); |
| 737 | BIND_ENUM_CONSTANT(DOCK_SLOT_BOTTOM); |
| 738 | BIND_ENUM_CONSTANT(DOCK_SLOT_MAX); |
| 739 | |
| 740 | BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_PASS); |
| 741 | BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_STOP); |
| 742 | BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_CUSTOM); |
| 743 | } |
| 744 | |
| 745 | EditorUndoRedoManager *EditorPlugin::get_undo_redo() { |
| 746 | return EditorUndoRedoManager::get_singleton(); |
| 747 | } |
| 748 | |
| 749 | EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS]; |
| 750 | |
| 751 | int EditorPlugins::creation_func_count = 0; |