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