editor_plugin.cpp 28 KB

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