2
0

editor_plugin.cpp 31 KB

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