editor_plugin.cpp 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. bool EditorPlugin::has_main_screen() const {
  261. bool success = false;
  262. GDVIRTUAL_CALL(_has_main_screen, success);
  263. return success;
  264. }
  265. void EditorPlugin::make_visible(bool p_visible) {
  266. GDVIRTUAL_CALL(_make_visible, p_visible);
  267. }
  268. void EditorPlugin::edit(Object *p_object) {
  269. GDVIRTUAL_CALL(_edit, p_object);
  270. }
  271. bool EditorPlugin::handles(Object *p_object) const {
  272. bool success = false;
  273. GDVIRTUAL_CALL(_handles, p_object, success);
  274. return success;
  275. }
  276. Dictionary EditorPlugin::get_state() const {
  277. Dictionary state;
  278. GDVIRTUAL_CALL(_get_state, state);
  279. return state;
  280. }
  281. void EditorPlugin::set_state(const Dictionary &p_state) {
  282. GDVIRTUAL_CALL(_set_state, p_state);
  283. }
  284. void EditorPlugin::clear() {
  285. GDVIRTUAL_CALL(_clear);
  286. }
  287. // if editor references external resources/scenes, save them
  288. void EditorPlugin::save_external_data() {
  289. GDVIRTUAL_CALL(_save_external_data);
  290. }
  291. // if changes are pending in editor, apply them
  292. void EditorPlugin::apply_changes() {
  293. GDVIRTUAL_CALL(_apply_changes);
  294. }
  295. void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) {
  296. PackedStringArray arr;
  297. if (GDVIRTUAL_CALL(_get_breakpoints, arr)) {
  298. for (int i = 0; i < arr.size(); i++) {
  299. p_breakpoints->push_back(arr[i]);
  300. }
  301. }
  302. }
  303. bool EditorPlugin::get_remove_list(List<Node *> *p_list) {
  304. return false;
  305. }
  306. void EditorPlugin::add_undo_redo_inspector_hook_callback(Callable p_callable) {
  307. EditorNode::get_singleton()->get_editor_data().add_undo_redo_inspector_hook_callback(p_callable);
  308. }
  309. void EditorPlugin::remove_undo_redo_inspector_hook_callback(Callable p_callable) {
  310. EditorNode::get_singleton()->get_editor_data().remove_undo_redo_inspector_hook_callback(p_callable);
  311. }
  312. void EditorPlugin::add_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) {
  313. ERR_FAIL_COND(!p_parser.is_valid());
  314. EditorTranslationParser::get_singleton()->add_parser(p_parser, EditorTranslationParser::CUSTOM);
  315. }
  316. void EditorPlugin::remove_translation_parser_plugin(const Ref<EditorTranslationParserPlugin> &p_parser) {
  317. ERR_FAIL_COND(!p_parser.is_valid());
  318. EditorTranslationParser::get_singleton()->remove_parser(p_parser, EditorTranslationParser::CUSTOM);
  319. }
  320. void EditorPlugin::add_import_plugin(const Ref<EditorImportPlugin> &p_importer, bool p_first_priority) {
  321. ERR_FAIL_COND(!p_importer.is_valid());
  322. ResourceFormatImporter::get_singleton()->add_importer(p_importer, p_first_priority);
  323. EditorFileSystem::get_singleton()->call_deferred(SNAME("scan"));
  324. }
  325. void EditorPlugin::remove_import_plugin(const Ref<EditorImportPlugin> &p_importer) {
  326. ERR_FAIL_COND(!p_importer.is_valid());
  327. ResourceFormatImporter::get_singleton()->remove_importer(p_importer);
  328. EditorFileSystem::get_singleton()->call_deferred(SNAME("scan"));
  329. }
  330. void EditorPlugin::add_export_plugin(const Ref<EditorExportPlugin> &p_exporter) {
  331. ERR_FAIL_COND(!p_exporter.is_valid());
  332. EditorExport::get_singleton()->add_export_plugin(p_exporter);
  333. }
  334. void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter) {
  335. ERR_FAIL_COND(!p_exporter.is_valid());
  336. EditorExport::get_singleton()->remove_export_plugin(p_exporter);
  337. }
  338. void EditorPlugin::add_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) {
  339. ERR_FAIL_COND(!p_gizmo_plugin.is_valid());
  340. Node3DEditor::get_singleton()->add_gizmo_plugin(p_gizmo_plugin);
  341. }
  342. void EditorPlugin::remove_node_3d_gizmo_plugin(const Ref<EditorNode3DGizmoPlugin> &p_gizmo_plugin) {
  343. ERR_FAIL_COND(!p_gizmo_plugin.is_valid());
  344. Node3DEditor::get_singleton()->remove_gizmo_plugin(p_gizmo_plugin);
  345. }
  346. void EditorPlugin::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
  347. ERR_FAIL_COND(!p_plugin.is_valid());
  348. EditorInspector::add_inspector_plugin(p_plugin);
  349. }
  350. void EditorPlugin::remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
  351. ERR_FAIL_COND(!p_plugin.is_valid());
  352. EditorInspector::remove_inspector_plugin(p_plugin);
  353. }
  354. void EditorPlugin::add_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer, bool p_first_priority) {
  355. ERR_FAIL_COND(!p_importer.is_valid());
  356. ResourceImporterScene::add_importer(p_importer, p_first_priority);
  357. }
  358. void EditorPlugin::remove_scene_format_importer_plugin(const Ref<EditorSceneFormatImporter> &p_importer) {
  359. ERR_FAIL_COND(!p_importer.is_valid());
  360. ResourceImporterScene::remove_importer(p_importer);
  361. }
  362. void EditorPlugin::add_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin, bool p_first_priority) {
  363. ResourceImporterScene::add_post_importer_plugin(p_plugin, p_first_priority);
  364. }
  365. void EditorPlugin::remove_scene_post_import_plugin(const Ref<EditorScenePostImportPlugin> &p_plugin) {
  366. ResourceImporterScene::remove_post_importer_plugin(p_plugin);
  367. }
  368. int find(const PackedStringArray &a, const String &v) {
  369. const String *r = a.ptr();
  370. for (int j = 0; j < a.size(); ++j) {
  371. if (r[j] == v) {
  372. return j;
  373. }
  374. }
  375. return -1;
  376. }
  377. void EditorPlugin::enable_plugin() {
  378. // Called when the plugin gets enabled in project settings, after it's added to the tree.
  379. // You can implement it to register autoloads.
  380. GDVIRTUAL_CALL(_enable_plugin);
  381. }
  382. void EditorPlugin::disable_plugin() {
  383. // Last function called when the plugin gets disabled in project settings.
  384. // Implement it to cleanup things from the project, such as unregister autoloads.
  385. GDVIRTUAL_CALL(_disable_plugin);
  386. }
  387. void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) {
  388. GDVIRTUAL_CALL(_set_window_layout, p_layout);
  389. }
  390. void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) {
  391. GDVIRTUAL_CALL(_get_window_layout, p_layout);
  392. }
  393. bool EditorPlugin::build() {
  394. bool success = true;
  395. GDVIRTUAL_CALL(_build, success);
  396. return success;
  397. }
  398. void EditorPlugin::queue_save_layout() {
  399. EditorNode::get_singleton()->save_editor_layout_delayed();
  400. }
  401. void EditorPlugin::make_bottom_panel_item_visible(Control *p_item) {
  402. EditorNode::get_singleton()->make_bottom_panel_item_visible(p_item);
  403. }
  404. void EditorPlugin::hide_bottom_panel() {
  405. EditorNode::get_singleton()->hide_bottom_panel();
  406. }
  407. EditorInterface *EditorPlugin::get_editor_interface() {
  408. return EditorInterface::get_singleton();
  409. }
  410. ScriptCreateDialog *EditorPlugin::get_script_create_dialog() {
  411. return SceneTreeDock::get_singleton()->get_script_create_dialog();
  412. }
  413. void EditorPlugin::add_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) {
  414. EditorDebuggerNode::get_singleton()->add_debugger_plugin(p_plugin);
  415. }
  416. void EditorPlugin::remove_debugger_plugin(const Ref<EditorDebuggerPlugin> &p_plugin) {
  417. EditorDebuggerNode::get_singleton()->remove_debugger_plugin(p_plugin);
  418. }
  419. void EditorPlugin::add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) {
  420. EditorNode::get_singleton()->add_resource_conversion_plugin(p_plugin);
  421. }
  422. void EditorPlugin::remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin) {
  423. EditorNode::get_singleton()->remove_resource_conversion_plugin(p_plugin);
  424. }
  425. void EditorPlugin::_editor_project_settings_changed() {
  426. emit_signal(SNAME("project_settings_changed"));
  427. }
  428. void EditorPlugin::_notification(int p_what) {
  429. switch (p_what) {
  430. case NOTIFICATION_ENTER_TREE: {
  431. EditorNode::get_singleton()->connect("project_settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed));
  432. } break;
  433. case NOTIFICATION_EXIT_TREE: {
  434. EditorNode::get_singleton()->disconnect("project_settings_changed", callable_mp(this, &EditorPlugin::_editor_project_settings_changed));
  435. } break;
  436. }
  437. }
  438. void EditorPlugin::_bind_methods() {
  439. ClassDB::bind_method(D_METHOD("add_control_to_container", "container", "control"), &EditorPlugin::add_control_to_container);
  440. ClassDB::bind_method(D_METHOD("add_control_to_bottom_panel", "control", "title"), &EditorPlugin::add_control_to_bottom_panel);
  441. ClassDB::bind_method(D_METHOD("add_control_to_dock", "slot", "control"), &EditorPlugin::add_control_to_dock);
  442. ClassDB::bind_method(D_METHOD("remove_control_from_docks", "control"), &EditorPlugin::remove_control_from_docks);
  443. ClassDB::bind_method(D_METHOD("remove_control_from_bottom_panel", "control"), &EditorPlugin::remove_control_from_bottom_panel);
  444. ClassDB::bind_method(D_METHOD("remove_control_from_container", "container", "control"), &EditorPlugin::remove_control_from_container);
  445. ClassDB::bind_method(D_METHOD("add_tool_menu_item", "name", "callable"), &EditorPlugin::add_tool_menu_item);
  446. ClassDB::bind_method(D_METHOD("add_tool_submenu_item", "name", "submenu"), &EditorPlugin::add_tool_submenu_item);
  447. ClassDB::bind_method(D_METHOD("remove_tool_menu_item", "name"), &EditorPlugin::remove_tool_menu_item);
  448. ClassDB::bind_method(D_METHOD("get_export_as_menu"), &EditorPlugin::get_export_as_menu);
  449. ClassDB::bind_method(D_METHOD("add_custom_type", "type", "base", "script", "icon"), &EditorPlugin::add_custom_type);
  450. ClassDB::bind_method(D_METHOD("remove_custom_type", "type"), &EditorPlugin::remove_custom_type);
  451. ClassDB::bind_method(D_METHOD("add_autoload_singleton", "name", "path"), &EditorPlugin::add_autoload_singleton);
  452. ClassDB::bind_method(D_METHOD("remove_autoload_singleton", "name"), &EditorPlugin::remove_autoload_singleton);
  453. ClassDB::bind_method(D_METHOD("update_overlays"), &EditorPlugin::update_overlays);
  454. ClassDB::bind_method(D_METHOD("make_bottom_panel_item_visible", "item"), &EditorPlugin::make_bottom_panel_item_visible);
  455. ClassDB::bind_method(D_METHOD("hide_bottom_panel"), &EditorPlugin::hide_bottom_panel);
  456. ClassDB::bind_method(D_METHOD("get_undo_redo"), &EditorPlugin::get_undo_redo);
  457. ClassDB::bind_method(D_METHOD("add_undo_redo_inspector_hook_callback", "callable"), &EditorPlugin::add_undo_redo_inspector_hook_callback);
  458. ClassDB::bind_method(D_METHOD("remove_undo_redo_inspector_hook_callback", "callable"), &EditorPlugin::remove_undo_redo_inspector_hook_callback);
  459. ClassDB::bind_method(D_METHOD("queue_save_layout"), &EditorPlugin::queue_save_layout);
  460. ClassDB::bind_method(D_METHOD("add_translation_parser_plugin", "parser"), &EditorPlugin::add_translation_parser_plugin);
  461. ClassDB::bind_method(D_METHOD("remove_translation_parser_plugin", "parser"), &EditorPlugin::remove_translation_parser_plugin);
  462. ClassDB::bind_method(D_METHOD("add_import_plugin", "importer", "first_priority"), &EditorPlugin::add_import_plugin, DEFVAL(false));
  463. ClassDB::bind_method(D_METHOD("remove_import_plugin", "importer"), &EditorPlugin::remove_import_plugin);
  464. ClassDB::bind_method(D_METHOD("add_scene_format_importer_plugin", "scene_format_importer", "first_priority"), &EditorPlugin::add_scene_format_importer_plugin, DEFVAL(false));
  465. ClassDB::bind_method(D_METHOD("remove_scene_format_importer_plugin", "scene_format_importer"), &EditorPlugin::remove_scene_format_importer_plugin);
  466. ClassDB::bind_method(D_METHOD("add_scene_post_import_plugin", "scene_import_plugin", "first_priority"), &EditorPlugin::add_scene_post_import_plugin, DEFVAL(false));
  467. ClassDB::bind_method(D_METHOD("remove_scene_post_import_plugin", "scene_import_plugin"), &EditorPlugin::remove_scene_post_import_plugin);
  468. ClassDB::bind_method(D_METHOD("add_export_plugin", "plugin"), &EditorPlugin::add_export_plugin);
  469. ClassDB::bind_method(D_METHOD("remove_export_plugin", "plugin"), &EditorPlugin::remove_export_plugin);
  470. ClassDB::bind_method(D_METHOD("add_node_3d_gizmo_plugin", "plugin"), &EditorPlugin::add_node_3d_gizmo_plugin);
  471. ClassDB::bind_method(D_METHOD("remove_node_3d_gizmo_plugin", "plugin"), &EditorPlugin::remove_node_3d_gizmo_plugin);
  472. ClassDB::bind_method(D_METHOD("add_inspector_plugin", "plugin"), &EditorPlugin::add_inspector_plugin);
  473. ClassDB::bind_method(D_METHOD("remove_inspector_plugin", "plugin"), &EditorPlugin::remove_inspector_plugin);
  474. ClassDB::bind_method(D_METHOD("add_resource_conversion_plugin", "plugin"), &EditorPlugin::add_resource_conversion_plugin);
  475. ClassDB::bind_method(D_METHOD("remove_resource_conversion_plugin", "plugin"), &EditorPlugin::remove_resource_conversion_plugin);
  476. ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);
  477. ClassDB::bind_method(D_METHOD("set_force_draw_over_forwarding_enabled"), &EditorPlugin::set_force_draw_over_forwarding_enabled);
  478. ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorPlugin::get_editor_interface);
  479. ClassDB::bind_method(D_METHOD("get_script_create_dialog"), &EditorPlugin::get_script_create_dialog);
  480. ClassDB::bind_method(D_METHOD("add_debugger_plugin", "script"), &EditorPlugin::add_debugger_plugin);
  481. ClassDB::bind_method(D_METHOD("remove_debugger_plugin", "script"), &EditorPlugin::remove_debugger_plugin);
  482. GDVIRTUAL_BIND(_forward_canvas_gui_input, "event");
  483. GDVIRTUAL_BIND(_forward_canvas_draw_over_viewport, "viewport_control");
  484. GDVIRTUAL_BIND(_forward_canvas_force_draw_over_viewport, "viewport_control");
  485. GDVIRTUAL_BIND(_forward_3d_gui_input, "viewport_camera", "event");
  486. GDVIRTUAL_BIND(_forward_3d_draw_over_viewport, "viewport_control");
  487. GDVIRTUAL_BIND(_forward_3d_force_draw_over_viewport, "viewport_control");
  488. GDVIRTUAL_BIND(_get_plugin_name);
  489. GDVIRTUAL_BIND(_get_plugin_icon);
  490. GDVIRTUAL_BIND(_has_main_screen);
  491. GDVIRTUAL_BIND(_make_visible, "visible");
  492. GDVIRTUAL_BIND(_edit, "object");
  493. GDVIRTUAL_BIND(_handles, "object");
  494. GDVIRTUAL_BIND(_get_state);
  495. GDVIRTUAL_BIND(_set_state, "state");
  496. GDVIRTUAL_BIND(_clear);
  497. GDVIRTUAL_BIND(_save_external_data);
  498. GDVIRTUAL_BIND(_apply_changes);
  499. GDVIRTUAL_BIND(_get_breakpoints);
  500. GDVIRTUAL_BIND(_set_window_layout, "configuration");
  501. GDVIRTUAL_BIND(_get_window_layout, "configuration");
  502. GDVIRTUAL_BIND(_build);
  503. GDVIRTUAL_BIND(_enable_plugin);
  504. GDVIRTUAL_BIND(_disable_plugin);
  505. ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
  506. ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath")));
  507. ADD_SIGNAL(MethodInfo("main_screen_changed", PropertyInfo(Variant::STRING, "screen_name")));
  508. ADD_SIGNAL(MethodInfo("resource_saved", PropertyInfo(Variant::OBJECT, "resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource")));
  509. ADD_SIGNAL(MethodInfo("project_settings_changed"));
  510. BIND_ENUM_CONSTANT(CONTAINER_TOOLBAR);
  511. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_MENU);
  512. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE_LEFT);
  513. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_SIDE_RIGHT);
  514. BIND_ENUM_CONSTANT(CONTAINER_SPATIAL_EDITOR_BOTTOM);
  515. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_MENU);
  516. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE_LEFT);
  517. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_SIDE_RIGHT);
  518. BIND_ENUM_CONSTANT(CONTAINER_CANVAS_EDITOR_BOTTOM);
  519. BIND_ENUM_CONSTANT(CONTAINER_INSPECTOR_BOTTOM);
  520. BIND_ENUM_CONSTANT(CONTAINER_PROJECT_SETTING_TAB_LEFT);
  521. BIND_ENUM_CONSTANT(CONTAINER_PROJECT_SETTING_TAB_RIGHT);
  522. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UL);
  523. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BL);
  524. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_UR);
  525. BIND_ENUM_CONSTANT(DOCK_SLOT_LEFT_BR);
  526. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UL);
  527. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BL);
  528. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_UR);
  529. BIND_ENUM_CONSTANT(DOCK_SLOT_RIGHT_BR);
  530. BIND_ENUM_CONSTANT(DOCK_SLOT_MAX);
  531. BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_PASS);
  532. BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_STOP);
  533. BIND_ENUM_CONSTANT(AFTER_GUI_INPUT_CUSTOM);
  534. }
  535. EditorUndoRedoManager *EditorPlugin::get_undo_redo() {
  536. return EditorUndoRedoManager::get_singleton();
  537. }
  538. EditorPluginCreateFunc EditorPlugins::creation_funcs[MAX_CREATE_FUNCS];
  539. int EditorPlugins::creation_func_count = 0;