2
0

editor_plugin.cpp 27 KB

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