editor_plugin.cpp 30 KB

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