| 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 | |
| 33 | #include "editor/debugger/editor_debugger_node.h" |
| 34 | #include "editor/editor_file_system.h" |
| 35 | #include "editor/editor_inspector.h" |
| 36 | #include "editor/editor_interface.h" |
| 37 | #include "editor/editor_node.h" |
| 38 | #include "editor/editor_translation_parser.h" |
| 39 | #include "editor/editor_undo_redo_manager.h" |
| 40 | #include "editor/export/editor_export.h" |
| 41 | #include "editor/gui/editor_title_bar.h" |
| 42 | #include "editor/import/editor_import_plugin.h" |
| 43 | #include "editor/import/resource_importer_scene.h" |
| 44 | #include "editor/inspector_dock.h" |
| 45 | #include "editor/plugins/canvas_item_editor_plugin.h" |
| 46 | #include "editor/plugins/editor_debugger_plugin.h" |
| 47 | #include "editor/plugins/editor_resource_conversion_plugin.h" |
| 48 | #include "editor/plugins/node_3d_editor_plugin.h" |
| 49 | #include "editor/plugins/script_editor_plugin.h" |
| 50 | #include "editor/project_settings_editor.h" |
| 51 | #include "editor/scene_tree_dock.h" |
| 52 | #include "scene/3d/camera_3d.h" |
| 53 | #include "scene/gui/popup_menu.h" |
| 54 | #include "scene/resources/image_texture.h" |
| 55 | #include "servers/rendering_server.h" |
| 56 | |
| 57 | void EditorPlugin::add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon) { |
| 58 | EditorNode::get_editor_data().add_custom_type(p_type, p_base, p_script, p_icon); |
| 59 | } |
| 60 | |
| 61 | void EditorPlugin::remove_custom_type(const String &p_type) { |
| 62 | EditorNode::get_editor_data().remove_custom_type(p_type); |
| 63 | } |
| 64 | |
| 65 | void EditorPlugin::add_autoload_singleton(const String &p_name, const String &p_path) { |
| 66 | if (p_path.begins_with("res://" )) { |
| 67 | EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_add(p_name, p_path); |
| 68 | } else { |
| 69 | const Ref<Script> plugin_script = static_cast<Ref<Script>>(get_script()); |
| 70 | ERR_FAIL_COND(plugin_script.is_null()); |
| 71 | const String script_base_path = plugin_script->get_path().get_base_dir(); |
| 72 | EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_add(p_name, script_base_path.path_join(p_path)); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | void EditorPlugin::remove_autoload_singleton(const String &p_name) { |
| 77 | EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name); |
| 78 | } |
| 79 | |
| 80 | Button *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) { |
| 81 | ERR_FAIL_NULL_V(p_control, nullptr); |
| 82 | return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control); |
| 83 | } |
| 84 | |
| 85 | void EditorPlugin::add_control_to_dock(DockSlot p_slot, Control *p_control) { |
| 86 | ERR_FAIL_NULL(p_control); |
| 87 | EditorNode::get_singleton()->add_control_to_dock(EditorNode::DockSlot(p_slot), p_control); |
| 88 | } |
| 89 | |
| 90 | void EditorPlugin::remove_control_from_docks(Control *p_control) { |
| 91 | ERR_FAIL_NULL(p_control); |
| 92 | EditorNode::get_singleton()->remove_control_from_dock(p_control); |
| 93 | } |
| 94 | |
| 95 | void EditorPlugin::remove_control_from_bottom_panel(Control *p_control) { |
| 96 | ERR_FAIL_NULL(p_control); |
| 97 | EditorNode::get_singleton()->remove_bottom_panel_item(p_control); |
| 98 | } |
| 99 | |
| 100 | void EditorPlugin::add_control_to_container(CustomControlContainer p_location, Control *p_control) { |
| 101 | ERR_FAIL_NULL(p_control); |
| 102 | |
| 103 | switch (p_location) { |
| 104 | case CONTAINER_TOOLBAR: { |
| 105 | EditorNode::get_title_bar()->add_child(p_control); |
| 106 | } break; |
| 107 | |
| 108 | case CONTAINER_SPATIAL_EDITOR_MENU: { |
| 109 | Node3DEditor::get_singleton()->add_control_to_menu_panel(p_control); |
| 110 | |
| 111 | } break; |
| 112 | case CONTAINER_SPATIAL_EDITOR_SIDE_LEFT: { |
| 113 | Node3DEditor::get_singleton()->add_control_to_left_panel(p_control); |
| 114 | } break; |
| 115 | case CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT: { |
| 116 | Node3DEditor::get_singleton()->add_control_to_right_panel(p_control); |
| 117 | } break; |
| 118 | case CONTAINER_SPATIAL_EDITOR_BOTTOM: { |
| 119 | Node3DEditor::get_singleton()->get_shader_split()->add_child(p_control); |
| 120 | |
| 121 | } break; |
| 122 | case CONTAINER_CANVAS_EDITOR_MENU: { |
| 123 | CanvasItemEditor::get_singleton()->add_control_to_menu_panel(p_control); |
| 124 | |
| 125 | } break; |
| 126 | case CONTAINER_CANVAS_EDITOR_SIDE_LEFT: { |
| 127 | CanvasItemEditor::get_singleton()->add_control_to_left_panel(p_control); |
| 128 | } break; |
| 129 | case CONTAINER_CANVAS_EDITOR_SIDE_RIGHT: { |
| 130 | CanvasItemEditor::get_singleton()->add_control_to_right_panel(p_control); |
| 131 | } break; |
| 132 | case CONTAINER_CANVAS_EDITOR_BOTTOM: { |
| 133 | CanvasItemEditor::get_singleton()->get_bottom_split()->add_child(p_control); |
| 134 | |
| 135 | } break; |
| 136 | case CONTAINER_INSPECTOR_BOTTOM: { |
| 137 | InspectorDock::get_singleton()->get_addon_area()->add_child(p_control); |
| 138 | |
| 139 | } break; |
| 140 | case CONTAINER_PROJECT_SETTING_TAB_LEFT: { |
| 141 | ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(p_control); |
| 142 | ProjectSettingsEditor::get_singleton()->get_tabs()->move_child(p_control, 0); |
| 143 | |
| 144 | } break; |
| 145 | case CONTAINER_PROJECT_SETTING_TAB_RIGHT: { |
| 146 | ProjectSettingsEditor::get_singleton()->get_tabs()->add_child(p_control); |
| 147 | ProjectSettingsEditor::get_singleton()->get_tabs()->move_child(p_control, 1); |
| 148 | |
| 149 | } break; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | void EditorPlugin::remove_control_from_container(CustomControlContainer p_location, Control *p_control) { |
| 154 | ERR_FAIL_NULL(p_control); |
| 155 | |
| 156 | switch (p_location) { |
| 157 | case CONTAINER_TOOLBAR: { |
| 158 | EditorNode::get_title_bar()->remove_child(p_control); |
| 159 | } break; |
| 160 | |
| 161 | case CONTAINER_SPATIAL_EDITOR_MENU: { |
| 162 | Node3DEditor::get_singleton()->remove_control_from_menu_panel(p_control); |
| 163 | |
| 164 | } break; |
| 165 | case CONTAINER_SPATIAL_EDITOR_SIDE_LEFT: { |
| 166 | Node3DEditor::get_singleton()->remove_control_from_left_panel(p_control); |
| 167 | } break; |
| 168 | case CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT: { |
| 169 | Node3DEditor::get_singleton()->remove_control_from_right_panel(p_control); |
| 170 | } break; |
| 171 | case CONTAINER_SPATIAL_EDITOR_BOTTOM: { |
| 172 | Node3DEditor::get_singleton()->get_shader_split()->remove_child(p_control); |
| 173 | |
| 174 | } break; |
| 175 | case CONTAINER_CANVAS_EDITOR_MENU: { |
| 176 | CanvasItemEditor::get_singleton()->remove_control_from_menu_panel(p_control); |
| 177 | |
| 178 | } break; |
| 179 | case CONTAINER_CANVAS_EDITOR_SIDE_LEFT: { |
| 180 | CanvasItemEditor::get_singleton()->remove_control_from_left_panel(p_control); |
| 181 | } break; |
| 182 | case CONTAINER_CANVAS_EDITOR_SIDE_RIGHT: { |
| 183 | CanvasItemEditor::get_singleton()->remove_control_from_right_panel(p_control); |
| 184 | } break; |
| 185 | case CONTAINER_CANVAS_EDITOR_BOTTOM: { |
| 186 | CanvasItemEditor::get_singleton()->get_bottom_split()->remove_child(p_control); |
| 187 | |
| 188 | } break; |
| 189 | case CONTAINER_INSPECTOR_BOTTOM: { |
| 190 | InspectorDock::get_singleton()->get_addon_area()->remove_child(p_control); |
| 191 | |
| 192 | } break; |
| 193 | case CONTAINER_PROJECT_SETTING_TAB_LEFT: |
| 194 | case CONTAINER_PROJECT_SETTING_TAB_RIGHT: { |
| 195 | ProjectSettingsEditor::get_singleton()->get_tabs()->remove_child(p_control); |
| 196 | |
| 197 | } break; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | void EditorPlugin::(const String &p_name, const Callable &p_callable) { |
| 202 | EditorNode::get_singleton()->add_tool_menu_item(p_name, p_callable); |
| 203 | } |
| 204 | |
| 205 | void EditorPlugin::(const String &p_name, PopupMenu *) { |
| 206 | ERR_FAIL_NULL(p_submenu); |
| 207 | EditorNode::get_singleton()->add_tool_submenu_item(p_name, p_submenu); |
| 208 | } |
| 209 | |
| 210 | void EditorPlugin::(const String &p_name) { |
| 211 | EditorNode::get_singleton()->remove_tool_menu_item(p_name); |
| 212 | } |
| 213 | |
| 214 | PopupMenu *EditorPlugin::() { |
| 215 | return EditorNode::get_singleton()->get_export_as_menu(); |
| 216 | } |
| 217 | |
| 218 | void EditorPlugin::set_input_event_forwarding_always_enabled() { |
| 219 | input_event_forwarding_always_enabled = true; |
| 220 | EditorPluginList *always_input_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_input_forwarding(); |
| 221 | always_input_forwarding_list->add_plugin(this); |
| 222 | } |
| 223 | |
| 224 | void EditorPlugin::set_force_draw_over_forwarding_enabled() { |
| 225 | force_draw_over_forwarding_enabled = true; |
| 226 | EditorPluginList *always_draw_over_forwarding_list = EditorNode::get_singleton()->get_editor_plugins_force_over(); |
| 227 | always_draw_over_forwarding_list->add_plugin(this); |
| 228 | } |
| 229 | |
| 230 | void EditorPlugin::notify_scene_changed(const Node *scn_root) { |
| 231 | emit_signal(SNAME("scene_changed" ), scn_root); |
| 232 | } |
| 233 | |
| 234 | void EditorPlugin::notify_main_screen_changed(const String &screen_name) { |
| 235 | if (screen_name == last_main_screen_name) { |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | emit_signal(SNAME("main_screen_changed" ), screen_name); |
| 240 | last_main_screen_name = screen_name; |
| 241 | } |
| 242 | |
| 243 | void EditorPlugin::notify_scene_closed(const String &scene_filepath) { |
| 244 | emit_signal(SNAME("scene_closed" ), scene_filepath); |
| 245 | } |
| 246 | |
| 247 | void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) { |
| 248 | emit_signal(SNAME("resource_saved" ), p_resource); |
| 249 | } |
| 250 | |
| 251 | bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { |
| 252 | bool success = false; |
| 253 | GDVIRTUAL_CALL(_forward_canvas_gui_input, p_event, success); |
| 254 | return success; |
| 255 | } |
| 256 | |
| 257 | void EditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) { |
| 258 | GDVIRTUAL_CALL(_forward_canvas_draw_over_viewport, p_overlay); |
| 259 | } |
| 260 | |
| 261 | void EditorPlugin::forward_canvas_force_draw_over_viewport(Control *p_overlay) { |
| 262 | GDVIRTUAL_CALL(_forward_canvas_force_draw_over_viewport, p_overlay); |
| 263 | } |
| 264 | |
| 265 | // Updates the overlays of the 2D viewport or, if in 3D mode, of every 3D viewport. |
| 266 | int EditorPlugin::update_overlays() const { |
| 267 | if (Node3DEditor::get_singleton()->is_visible()) { |
| 268 | int count = 0; |
| 269 | for (uint32_t i = 0; i < Node3DEditor::VIEWPORTS_COUNT; i++) { |
| 270 | Node3DEditorViewport *vp = Node3DEditor::get_singleton()->get_editor_viewport(i); |
| 271 | if (vp->is_visible()) { |
| 272 | vp->update_surface(); |
| 273 | count++; |
| 274 | } |
| 275 | } |
| 276 | return count; |
| 277 | } else { |
| 278 | // This will update the normal viewport itself as well |
| 279 | CanvasItemEditor::get_singleton()->get_viewport_control()->queue_redraw(); |
| 280 | return 1; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | EditorPlugin::AfterGUIInput EditorPlugin::forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { |
| 285 | int success = EditorPlugin::AFTER_GUI_INPUT_PASS; |
| 286 | GDVIRTUAL_CALL(_forward_3d_gui_input, p_camera, p_event, success); |
| 287 | return static_cast<EditorPlugin::AfterGUIInput>(success); |
| 288 | } |
| 289 | |
| 290 | void EditorPlugin::forward_3d_draw_over_viewport(Control *p_overlay) { |
| 291 | GDVIRTUAL_CALL(_forward_3d_draw_over_viewport, p_overlay); |
| 292 | } |
| 293 | |
| 294 | void EditorPlugin::forward_3d_force_draw_over_viewport(Control *p_overlay) { |
| 295 | GDVIRTUAL_CALL(_forward_3d_force_draw_over_viewport, p_overlay); |
| 296 | } |
| 297 | |
| 298 | String EditorPlugin::get_name() const { |
| 299 | String name; |
| 300 | GDVIRTUAL_CALL(_get_plugin_name, name); |
| 301 | return name; |
| 302 | } |
| 303 | |
| 304 | const Ref<Texture2D> EditorPlugin::get_icon() const { |
| 305 | Ref<Texture2D> icon; |
| 306 | GDVIRTUAL_CALL(_get_plugin_icon, icon); |
| 307 | return icon; |
| 308 | } |
| 309 | |
| 310 | String EditorPlugin::get_plugin_version() const { |
| 311 | return plugin_version; |
| 312 | } |
| 313 | |
| 314 | void EditorPlugin::set_plugin_version(const String &p_version) { |
| 315 | plugin_version = p_version; |
| 316 | } |
| 317 | |
| 318 | bool EditorPlugin::has_main_screen() const { |
| 319 | bool success = false; |
| 320 | GDVIRTUAL_CALL(_has_main_screen, success); |
| 321 | return success; |
| 322 | } |
| 323 | |
| 324 | void EditorPlugin::make_visible(bool p_visible) { |
| 325 | GDVIRTUAL_CALL(_make_visible, p_visible); |
| 326 | } |
| 327 | |
| 328 | void EditorPlugin::edit(Object *p_object) { |
| 329 | GDVIRTUAL_CALL(_edit, p_object); |
| 330 | } |
| 331 | |
| 332 | bool EditorPlugin::handles(Object *p_object) const { |
| 333 | bool success = false; |
| 334 | GDVIRTUAL_CALL(_handles, p_object, success); |
| 335 | return success; |
| 336 | } |
| 337 | |
| 338 | Dictionary EditorPlugin::get_state() const { |
| 339 | Dictionary state; |
| 340 | GDVIRTUAL_CALL(_get_state, state); |
| 341 | return state; |
| 342 | } |
| 343 | |
| 344 | void EditorPlugin::set_state(const Dictionary &p_state) { |
| 345 | GDVIRTUAL_CALL(_set_state, p_state); |
| 346 | } |
| 347 | |
| 348 | void EditorPlugin::clear() { |
| 349 | GDVIRTUAL_CALL(_clear); |
| 350 | } |
| 351 | |
| 352 | String EditorPlugin::get_unsaved_status(const String &p_for_scene) const { |
| 353 | String ret; |
| 354 | GDVIRTUAL_CALL(_get_unsaved_status, p_for_scene, ret); |
| 355 | return ret; |
| 356 | } |
| 357 | |
| 358 | void EditorPlugin::save_external_data() { |
| 359 | GDVIRTUAL_CALL(_save_external_data); |
| 360 | } |
| 361 | |
| 362 | // if changes are pending in editor, apply them |
| 363 | void EditorPlugin::apply_changes() { |
| 364 | GDVIRTUAL_CALL(_apply_changes); |
| 365 | } |
| 366 | |
| 367 | void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { |
| 368 | PackedStringArray arr; |
| 369 | if (GDVIRTUAL_CALL(_get_breakpoints, arr)) { |
| 370 | for (int i = 0; i < arr.size(); i++) { |
| 371 | p_breakpoints->push_back(arr[i]); |
| 372 | } |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | bool EditorPlugin::get_remove_list(List<Node *> *p_list) { |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | void EditorPlugin::add_undo_redo_inspector_hook_callback(Callable p_callable) { |
| 381 | EditorNode::get_editor_data().add_undo_redo_inspector_hook_callback(p_callable); |
| 382 | } |
| 383 | |
| 384 | void EditorPlugin::remove_undo_redo_inspector_hook_callback(Callable p_callable) { |
| 385 | EditorNode::get_editor_data().remove_undo_redo_inspector_hook_callback(p_callable); |
| 386 | } |
| 387 | |
| 388 | void EditorPlugin::add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) { |
| 389 | ERR_FAIL_COND(!p_parser.is_valid()); |
| 390 | EditorTranslationParser::get_singleton()->add_parser(p_parser, EditorTranslationParser::CUSTOM); |
| 391 | } |
| 392 | |
| 393 | void EditorPlugin::remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) { |
| 394 | ERR_FAIL_COND(!p_parser.is_valid()); |
| 395 | EditorTranslationParser::get_singleton()->remove_parser(p_parser, EditorTranslationParser::CUSTOM); |
| 396 | } |
| 397 | |
| 398 | void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority) { |
| 399 | ERR_FAIL_COND(!p_importer.is_valid()); |
| 400 | ResourceFormatImporter::get_singleton()->add_importer(p_importer, p_first_priority); |
| 401 | EditorFileSystem::get_singleton()->call_deferred(SNAME("scan" )); |
| 402 | } |
| 403 | |
| 404 | void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) { |
| 405 | ERR_FAIL_COND(!p_importer.is_valid()); |
| 406 | ResourceFormatImporter::get_singleton()->remove_importer(p_importer); |
| 407 | EditorFileSystem::get_singleton()->call_deferred(SNAME("scan" )); |
| 408 | } |
| 409 | |
| 410 | void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin> &p_exporter) { |
| 411 | ERR_FAIL_COND(!p_exporter.is_valid()); |
| 412 | EditorExport::get_singleton()->add_export_plugin(p_exporter); |
| 413 | } |
| 414 | |
| 415 | void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter) { |
| 416 | ERR_FAIL_COND(!p_exporter.is_valid()); |
| 417 | EditorExport::get_singleton()->remove_export_plugin(p_exporter); |
| 418 | } |
| 419 | |
| 420 | void EditorPlugin::add_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) { |
| 421 | ERR_FAIL_COND(!p_gizmo_plugin.is_valid()); |
| 422 | Node3DEditor::get_singleton()->add_gizmo_plugin(p_gizmo_plugin); |
| 423 | } |
| 424 | |
| 425 | void EditorPlugin::remove_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) { |
| 426 | ERR_FAIL_COND(!p_gizmo_plugin.is_valid()); |
| 427 | Node3DEditor::get_singleton()->remove_gizmo_plugin(p_gizmo_plugin); |
| 428 | } |
| 429 | |
| 430 | void EditorPlugin::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { |
| 431 | ERR_FAIL_COND(!p_plugin.is_valid()); |
| 432 | EditorInspector::add_inspector_plugin(p_plugin); |
| 433 | } |
| 434 | |
| 435 | void EditorPlugin::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { |
| 436 | ERR_FAIL_COND(!p_plugin.is_valid()); |
| 437 | EditorInspector::remove_inspector_plugin(p_plugin); |
| 438 | } |
| 439 | |
| 440 | void EditorPlugin::add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer, bool p_first_priority) { |
| 441 | ERR_FAIL_COND(!p_importer.is_valid()); |
| 442 | ResourceImporterScene::add_importer(p_importer, p_first_priority); |
| 443 | } |
| 444 | |
| 445 | void EditorPlugin::remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer) { |
| 446 | ERR_FAIL_COND(!p_importer.is_valid()); |
| 447 | ResourceImporterScene::remove_importer(p_importer); |
| 448 | } |
| 449 | |
| 450 | void EditorPlugin::add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority) { |
| 451 | ResourceImporterScene::add_post_importer_plugin(p_plugin, p_first_priority); |
| 452 | } |
| 453 | |
| 454 | void EditorPlugin::remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin) { |
| 455 | ResourceImporterScene::remove_post_importer_plugin(p_plugin); |
| 456 | } |
| 457 | |
| 458 | int find(const PackedStringArray &a, const String &v) { |
| 459 | const String *r = a.ptr(); |
| 460 | for (int j = 0; j < a.size(); ++j) { |
| 461 | if (r[j] == v) { |
| 462 | return j; |
| 463 | } |
| 464 | } |
| 465 | return -1; |
| 466 | } |
| 467 | |
| 468 | void EditorPlugin::enable_plugin() { |
| 469 | // Called when the plugin gets enabled in project settings, after it's added to the tree. |
| 470 | // You can implement it to register autoloads. |
| 471 | GDVIRTUAL_CALL(_enable_plugin); |
| 472 | } |
| 473 | |
| 474 | void EditorPlugin::disable_plugin() { |
| 475 | // Last function called when the plugin gets disabled in project settings. |
| 476 | // Implement it to cleanup things from the project, such as unregister autoloads. |
| 477 | GDVIRTUAL_CALL(_disable_plugin); |
| 478 | } |
| 479 | |
| 480 | void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { |
| 481 | GDVIRTUAL_CALL(_set_window_layout, p_layout); |
| 482 | } |
| 483 | |
| 484 | void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { |
| 485 | GDVIRTUAL_CALL(_get_window_layout, p_layout); |
| 486 | } |
| 487 | |
| 488 | bool EditorPlugin::build() { |
| 489 | bool success = true; |
| 490 | GDVIRTUAL_CALL(_build, success); |
| 491 | return success; |
| 492 | } |
| 493 | |
| 494 | void EditorPlugin::queue_save_layout() { |
| 495 | EditorNode::get_singleton()->save_editor_layout_delayed(); |
| 496 | } |
| 497 | |
| 498 | void EditorPlugin::make_bottom_panel_item_visible(Control *p_item) { |
| 499 | EditorNode::get_singleton()->make_bottom_panel_item_visible(p_item); |
| 500 | } |
| 501 | |
| 502 | void EditorPlugin::hide_bottom_panel() { |
| 503 | EditorNode::get_singleton()->hide_bottom_panel(); |
| 504 | } |
| 505 | |
| 506 | EditorInterface *EditorPlugin::get_editor_interface() { |
| 507 | return EditorInterface::get_singleton(); |
| 508 | } |
| 509 | |
| 510 | ScriptCreateDialog *EditorPlugin::get_script_create_dialog() { |
| 511 | return SceneTreeDock::get_singleton()->get_script_create_dialog(); |
| 512 | } |
| 513 | |
| 514 | void EditorPlugin::add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) { |
| 515 | EditorDebuggerNode::get_singleton()->add_debugger_plugin(p_plugin); |
| 516 | } |
| 517 | |
| 518 | void EditorPlugin::remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) { |
| 519 | EditorDebuggerNode::get_singleton()->remove_debugger_plugin(p_plugin); |
| 520 | } |
| 521 | |
| 522 | void EditorPlugin::add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) { |
| 523 | EditorNode::get_singleton()->add_resource_conversion_plugin(p_plugin); |
| 524 | } |
| 525 | |
| 526 | void EditorPlugin::remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) { |
| 527 | EditorNode::get_singleton()->remove_resource_conversion_plugin(p_plugin); |
| 528 | } |
| 529 | |
| 530 | #ifndef DISABLE_DEPRECATED |
| 531 | void EditorPlugin::_editor_project_settings_changed() { |
| 532 | emit_signal(SNAME("project_settings_changed" )); |
| 533 | } |
| 534 | #endif |
| 535 | |
| 536 | void EditorPlugin::_notification(int p_what) { |
| 537 | #ifndef DISABLE_DEPRECATED |
| 538 | switch (p_what) { |
| 539 | case NOTIFICATION_ENTER_TREE: { |
| 540 | ProjectSettings::get_singleton()->connect("settings_changed" , callable_mp(this, &EditorPlugin::_editor_project_settings_changed)); |
| 541 | } break; |
| 542 | |
| 543 | case NOTIFICATION_EXIT_TREE: { |
| 544 | ProjectSettings::get_singleton()->disconnect("settings_changed" , callable_mp(this, &EditorPlugin::_editor_project_settings_changed)); |
| 545 | } break; |
| 546 | } |
| 547 | #endif |
| 548 | } |
| 549 | |
| 550 | void EditorPlugin::_bind_methods() { |
| 551 | ClassDB::bind_method(D_METHOD("add_control_to_container" , "container" , "control" ), &EditorPlugin::add_control_to_container); |
| 552 | ClassDB::bind_method(D_METHOD("add_control_to_bottom_panel" , "control" , "title" ), &EditorPlugin::add_control_to_bottom_panel); |
| 553 | ClassDB::bind_method(D_METHOD("add_control_to_dock" , "slot" , "control" ), &EditorPlugin::add_control_to_dock); |
| 554 | ClassDB::bind_method(D_METHOD("remove_control_from_docks" , "control" ), &EditorPlugin::remove_control_from_docks); |
| 555 | ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel" , "control" ), &EditorPlugin::remove_control_from_bottom_panel); |
| 556 | ClassDB::bind_method(D_METHOD("remove_control_from_container" , "container" , "control" ), &EditorPlugin::remove_control_from_container); |
| 557 | ClassDB::bind_method(D_METHOD("add_tool_menu_item" , "name" , "callable" ), &EditorPlugin::add_tool_menu_item); |
| 558 | ClassDB::bind_method(D_METHOD("add_tool_submenu_item" , "name" , "submenu" ), &EditorPlugin::add_tool_submenu_item); |
| 559 | ClassDB::bind_method(D_METHOD("remove_tool_menu_item" , "name" ), &EditorPlugin::remove_tool_menu_item); |
| 560 | ClassDB::bind_method(D_METHOD("get_export_as_menu" ), &EditorPlugin::get_export_as_menu); |
| 561 | ClassDB::bind_method(D_METHOD("add_custom_type" , "type" , "base" , "script" , "icon" ), &EditorPlugin::add_custom_type); |
| 562 | ClassDB::bind_method(D_METHOD("remove_custom_type" , "type" ), &EditorPlugin::remove_custom_type); |
| 563 | |
| 564 | ClassDB::bind_method(D_METHOD("add_autoload_singleton" , "name" , "path" ), &EditorPlugin::add_autoload_singleton); |
| 565 | ClassDB::bind_method(D_METHOD("remove_autoload_singleton" , "name" ), &EditorPlugin::remove_autoload_singleton); |
| 566 | |
| 567 | ClassDB::bind_method(D_METHOD("update_overlays" ), &EditorPlugin::update_overlays); |
| 568 | |
| 569 | ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible" , "item" ), &EditorPlugin::make_bottom_panel_item_visible); |
| 570 | ClassDB::bind_method(D_METHOD("hide_bottom_panel" ), &EditorPlugin::hide_bottom_panel); |
| 571 | |
| 572 | ClassDB::bind_method(D_METHOD("get_undo_redo" ), &EditorPlugin::get_undo_redo); |
| 573 | ClassDB::bind_method(D_METHOD("add_undo_redo_inspector_hook_callback" , "callable" ), &EditorPlugin::add_undo_redo_inspector_hook_callback); |
| 574 | ClassDB::bind_method(D_METHOD("remove_undo_redo_inspector_hook_callback" , "callable" ), &EditorPlugin::remove_undo_redo_inspector_hook_callback); |
| 575 | ClassDB::bind_method(D_METHOD("queue_save_layout" ), &EditorPlugin::queue_save_layout); |
| 576 | ClassDB::bind_method(D_METHOD("add_translation_parser_plugin" , "parser" ), &EditorPlugin::add_translation_parser_plugin); |
| 577 | ClassDB::bind_method(D_METHOD("remove_translation_parser_plugin" , "parser" ), &EditorPlugin::remove_translation_parser_plugin); |
| 578 | ClassDB::bind_method(D_METHOD("add_import_plugin" , "importer" , "first_priority" ), &EditorPlugin::add_import_plugin, DEFVAL(false)); |
| 579 | ClassDB::bind_method(D_METHOD("remove_import_plugin" , "importer" ), &EditorPlugin::remove_import_plugin); |
| 580 | ClassDB::bind_method(D_METHOD("add_scene_format_importer_plugin" , "scene_format_importer" , "first_priority" ), &EditorPlugin::add_scene_format_importer_plugin, DEFVAL(false)); |
| 581 | ClassDB::bind_method(D_METHOD("remove_scene_format_importer_plugin" , "scene_format_importer" ), &EditorPlugin::remove_scene_format_importer_plugin); |
| 582 | ClassDB::bind_method(D_METHOD("add_scene_post_import_plugin" , "scene_import_plugin" , "first_priority" ), &EditorPlugin::add_scene_post_import_plugin, DEFVAL(false)); |
| 583 | ClassDB::bind_method(D_METHOD("remove_scene_post_import_plugin" , "scene_import_plugin" ), &EditorPlugin::remove_scene_post_import_plugin); |
| 584 | ClassDB::bind_method(D_METHOD("add_export_plugin" , "plugin" ), &EditorPlugin::add_export_plugin); |
| 585 | ClassDB::bind_method(D_METHOD("remove_export_plugin" , "plugin" ), &EditorPlugin::remove_export_plugin); |
| 586 | ClassDB::bind_method(D_METHOD("add_node_3d_gizmo_plugin" , "plugin" ), &EditorPlugin::add_node_3d_gizmo_plugin); |
| 587 | ClassDB::bind_method(D_METHOD("remove_node_3d_gizmo_plugin" , "plugin" ), &EditorPlugin::remove_node_3d_gizmo_plugin); |
| 588 | ClassDB::bind_method(D_METHOD("add_inspector_plugin" , "plugin" ), &EditorPlugin::add_inspector_plugin); |
| 589 | ClassDB::bind_method(D_METHOD("remove_inspector_plugin" , "plugin" ), &EditorPlugin::remove_inspector_plugin); |
| 590 | ClassDB::bind_method(D_METHOD("add_resource_conversion_plugin" , "plugin" ), &EditorPlugin::add_resource_conversion_plugin); |
| 591 | ClassDB::bind_method(D_METHOD("remove_resource_conversion_plugin" , "plugin" ), &EditorPlugin::remove_resource_conversion_plugin); |
| 592 | ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled" ), &EditorPlugin::set_input_event_forwarding_always_enabled); |
| 593 | ClassDB::bind_method(D_METHOD("set_force_draw_over_forwarding_enabled" ), &EditorPlugin::set_force_draw_over_forwarding_enabled); |
| 594 | |
| 595 | ClassDB::bind_method(D_METHOD("get_editor_interface" ), &EditorPlugin::get_editor_interface); |
| 596 | ClassDB::bind_method(D_METHOD("get_script_create_dialog" ), &EditorPlugin::get_script_create_dialog); |
| 597 | ClassDB::bind_method(D_METHOD("add_debugger_plugin" , "script" ), &EditorPlugin::add_debugger_plugin); |
| 598 | ClassDB::bind_method(D_METHOD("remove_debugger_plugin" , "script" ), &EditorPlugin::remove_debugger_plugin); |
| 599 | ClassDB::bind_method(D_METHOD("get_plugin_version" ), &EditorPlugin::get_plugin_version); |
| 600 | |
| 601 | GDVIRTUAL_BIND(_forward_canvas_gui_input, "event" ); |
| 602 | GDVIRTUAL_BIND(_forward_canvas_draw_over_viewport, "viewport_control" ); |
| 603 | GDVIRTUAL_BIND(_forward_canvas_force_draw_over_viewport, "viewport_control" ); |
| 604 | GDVIRTUAL_BIND(_forward_3d_gui_input, "viewport_camera" , "event" ); |
| 605 | GDVIRTUAL_BIND(_forward_3d_draw_over_viewport, "viewport_control" ); |
| 606 | GDVIRTUAL_BIND(_forward_3d_force_draw_over_viewport, "viewport_control" ); |
| 607 | GDVIRTUAL_BIND(_get_plugin_name); |
| 608 | GDVIRTUAL_BIND(_get_plugin_icon); |
| 609 | GDVIRTUAL_BIND(_has_main_screen); |
| 610 | GDVIRTUAL_BIND(_make_visible, "visible" ); |
| 611 | GDVIRTUAL_BIND(_edit, "object" ); |
| 612 | GDVIRTUAL_BIND(_handles, "object" ); |
| 613 | GDVIRTUAL_BIND(_get_state); |
| 614 | GDVIRTUAL_BIND(_set_state, "state" ); |
| 615 | GDVIRTUAL_BIND(_clear); |
| 616 | GDVIRTUAL_BIND(_get_unsaved_status, "for_scene" ); |
| 617 | GDVIRTUAL_BIND(_save_external_data); |
| 618 | GDVIRTUAL_BIND(_apply_changes); |
| 619 | GDVIRTUAL_BIND(_get_breakpoints); |
| 620 | GDVIRTUAL_BIND(_set_window_layout, "configuration" ); |
| 621 | GDVIRTUAL_BIND(_get_window_layout, "configuration" ); |
| 622 | GDVIRTUAL_BIND(_build); |
| 623 | GDVIRTUAL_BIND(_enable_plugin); |
| 624 | GDVIRTUAL_BIND(_disable_plugin); |
| 625 | |
| 626 | ADD_SIGNAL(MethodInfo("scene_changed" , PropertyInfo(Variant::OBJECT, "scene_root" , PROPERTY_HINT_RESOURCE_TYPE, "Node" ))); |
| 627 | ADD_SIGNAL(MethodInfo("scene_closed" , PropertyInfo(Variant::STRING, "filepath" ))); |
| 628 | ADD_SIGNAL(MethodInfo("main_screen_changed" , PropertyInfo(Variant::STRING, "screen_name" ))); |
| 629 | ADD_SIGNAL(MethodInfo("resource_saved" , PropertyInfo(Variant::OBJECT, "resource" , PROPERTY_HINT_RESOURCE_TYPE, "Resource" ))); |
| 630 | ADD_SIGNAL(MethodInfo("project_settings_changed" )); |
| 631 | |
| 632 | BIND_ENUM_CONSTANT(CONTAINER_TOOLBAR); |
| 633 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_MENU); |
| 634 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE_LEFT); |
| 635 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT); |
| 636 | BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_BOTTOM); |
| 637 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_MENU); |
| 638 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE_LEFT); |
| 639 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE_RIGHT); |
| 640 | BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_BOTTOM); |
| 641 | BIND_ENUM_CONSTANT(CONTAINER_INSPECTOR_BOTTOM); |
| 642 | BIND_ENUM_CONSTANT(CONTAINER_PROJECT_SETTING_TAB_LEFT); |
| 643 | BIND_ENUM_CONSTANT(CONTAINER_PROJECT_SETTING_TAB_RIGHT); |
| 644 | |
| 645 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UL); |
| 646 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BL); |
| 647 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UR); |
| 648 | BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BR); |
| 649 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UL); |
| 650 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BL); |
| 651 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR); |
| 652 | BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR); |
| 653 | BIND_ENUM_CONSTANT(DOCK_SLOT_MAX); |
| 654 | |
| 655 | BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_PASS); |
| 656 | BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_STOP); |
| 657 | BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_CUSTOM); |
| 658 | } |
| 659 | |
| 660 | EditorUndoRedoManager *EditorPlugin::get_undo_redo() { |
| 661 | return EditorUndoRedoManager::get_singleton(); |
| 662 | } |
| 663 | |
| 664 | EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS]; |
| 665 | |
| 666 | int EditorPlugins::creation_func_count = 0; |
| 667 | |