editor_node.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. /*************************************************************************/
  2. /* editor_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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. #ifndef EDITOR_NODE_H
  31. #define EDITOR_NODE_H
  32. #include "core/print_string.h"
  33. #include "editor/audio_stream_preview.h"
  34. #include "editor/connections_dialog.h"
  35. #include "editor/create_dialog.h"
  36. #include "editor/editor_about.h"
  37. #include "editor/editor_data.h"
  38. #include "editor/editor_export.h"
  39. #include "editor/editor_folding.h"
  40. #include "editor/editor_inspector.h"
  41. #include "editor/editor_log.h"
  42. #include "editor/editor_name_dialog.h"
  43. #include "editor/editor_plugin.h"
  44. #include "editor/editor_resource_preview.h"
  45. #include "editor/editor_run.h"
  46. #include "editor/editor_run_native.h"
  47. #include "editor/editor_run_script.h"
  48. #include "editor/editor_scale.h"
  49. #include "editor/editor_sub_scene.h"
  50. #include "editor/export_template_manager.h"
  51. #include "editor/fileserver/editor_file_server.h"
  52. #include "editor/filesystem_dock.h"
  53. #include "editor/groups_editor.h"
  54. #include "editor/import_dock.h"
  55. #include "editor/inspector_dock.h"
  56. #include "editor/node_dock.h"
  57. #include "editor/pane_drag.h"
  58. #include "editor/plugin_config_dialog.h"
  59. #include "editor/progress_dialog.h"
  60. #include "editor/project_export.h"
  61. #include "editor/project_settings_editor.h"
  62. #include "editor/property_editor.h"
  63. #include "editor/quick_open.h"
  64. #include "editor/reparent_dialog.h"
  65. #include "editor/run_settings_dialog.h"
  66. #include "editor/scene_tree_dock.h"
  67. #include "editor/scene_tree_editor.h"
  68. #include "editor/script_create_dialog.h"
  69. #include "editor/settings_config_dialog.h"
  70. #include "scene/gui/center_container.h"
  71. #include "scene/gui/control.h"
  72. #include "scene/gui/dialogs.h"
  73. #include "scene/gui/file_dialog.h"
  74. #include "scene/gui/menu_button.h"
  75. #include "scene/gui/panel.h"
  76. #include "scene/gui/panel_container.h"
  77. #include "scene/gui/separator.h"
  78. #include "scene/gui/split_container.h"
  79. #include "scene/gui/tab_container.h"
  80. #include "scene/gui/tabs.h"
  81. #include "scene/gui/texture_progress.h"
  82. #include "scene/gui/tool_button.h"
  83. #include "scene/gui/tree.h"
  84. #include "scene/gui/viewport_container.h"
  85. /**
  86. @author Juan Linietsky <reduzio@gmail.com>
  87. */
  88. typedef void (*EditorNodeInitCallback)();
  89. typedef void (*EditorPluginInitializeCallback)();
  90. typedef bool (*EditorBuildCallback)();
  91. class EditorPluginList;
  92. class EditorNode : public Node {
  93. GDCLASS(EditorNode, Node);
  94. public:
  95. enum DockSlot {
  96. DOCK_SLOT_LEFT_UL,
  97. DOCK_SLOT_LEFT_BL,
  98. DOCK_SLOT_LEFT_UR,
  99. DOCK_SLOT_LEFT_BR,
  100. DOCK_SLOT_RIGHT_UL,
  101. DOCK_SLOT_RIGHT_BL,
  102. DOCK_SLOT_RIGHT_UR,
  103. DOCK_SLOT_RIGHT_BR,
  104. DOCK_SLOT_MAX
  105. };
  106. private:
  107. enum {
  108. HISTORY_SIZE = 64
  109. };
  110. enum MenuOptions {
  111. FILE_NEW_SCENE,
  112. FILE_NEW_INHERITED_SCENE,
  113. FILE_OPEN_SCENE,
  114. FILE_SAVE_SCENE,
  115. FILE_SAVE_AS_SCENE,
  116. FILE_SAVE_ALL_SCENES,
  117. FILE_SAVE_BEFORE_RUN,
  118. FILE_SAVE_AND_RUN,
  119. FILE_SHOW_IN_FILESYSTEM,
  120. FILE_IMPORT_SUBSCENE,
  121. FILE_EXPORT_PROJECT,
  122. FILE_EXPORT_MESH_LIBRARY,
  123. FILE_EXPORT_TILESET,
  124. FILE_SAVE_OPTIMIZED,
  125. FILE_OPEN_RECENT,
  126. FILE_OPEN_OLD_SCENE,
  127. FILE_QUICK_OPEN_SCENE,
  128. FILE_QUICK_OPEN_SCRIPT,
  129. FILE_OPEN_PREV,
  130. FILE_CLOSE,
  131. FILE_CLOSE_ALL_AND_QUIT,
  132. FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER,
  133. FILE_QUIT,
  134. FILE_EXTERNAL_OPEN_SCENE,
  135. EDIT_UNDO,
  136. EDIT_REDO,
  137. EDIT_REVERT,
  138. TOOLS_ORPHAN_RESOURCES,
  139. TOOLS_CUSTOM,
  140. RESOURCE_SAVE,
  141. RESOURCE_SAVE_AS,
  142. RUN_PLAY,
  143. RUN_STOP,
  144. RUN_PLAY_SCENE,
  145. RUN_PLAY_NATIVE,
  146. RUN_PLAY_CUSTOM_SCENE,
  147. RUN_SCENE_SETTINGS,
  148. RUN_SETTINGS,
  149. RUN_PROJECT_DATA_FOLDER,
  150. RUN_PROJECT_MANAGER,
  151. RUN_FILE_SERVER,
  152. RUN_LIVE_DEBUG,
  153. RUN_DEBUG_COLLISONS,
  154. RUN_DEBUG_NAVIGATION,
  155. RUN_DEPLOY_REMOTE_DEBUG,
  156. RUN_RELOAD_SCRIPTS,
  157. SETTINGS_UPDATE_ALWAYS,
  158. SETTINGS_UPDATE_CHANGES,
  159. SETTINGS_UPDATE_SPINNER_HIDE,
  160. SETTINGS_PREFERENCES,
  161. SETTINGS_LAYOUT_SAVE,
  162. SETTINGS_LAYOUT_DELETE,
  163. SETTINGS_LAYOUT_DEFAULT,
  164. SETTINGS_EDITOR_DATA_FOLDER,
  165. SETTINGS_EDITOR_CONFIG_FOLDER,
  166. SETTINGS_MANAGE_EXPORT_TEMPLATES,
  167. SETTINGS_PICK_MAIN_SCENE,
  168. SETTINGS_TOGGLE_FULLSCREEN,
  169. SETTINGS_HELP,
  170. SCENE_TAB_CLOSE,
  171. HELP_SEARCH,
  172. HELP_DOCS,
  173. HELP_QA,
  174. HELP_ISSUES,
  175. HELP_COMMUNITY,
  176. HELP_ABOUT,
  177. SET_VIDEO_DRIVER_SAVE_AND_RESTART,
  178. IMPORT_PLUGIN_BASE = 100,
  179. TOOL_MENU_BASE = 1000
  180. };
  181. Viewport *scene_root; //root of the scene being edited
  182. PanelContainer *scene_root_parent;
  183. Control *theme_base;
  184. Control *gui_base;
  185. VBoxContainer *main_vbox;
  186. PanelContainer *play_button_panel;
  187. OptionButton *video_driver;
  188. ConfirmationDialog *video_restart_dialog;
  189. int video_driver_current;
  190. String video_driver_request;
  191. void _video_driver_selected(int);
  192. void _update_video_driver_color();
  193. // Split containers
  194. HSplitContainer *left_l_hsplit;
  195. VSplitContainer *left_l_vsplit;
  196. HSplitContainer *left_r_hsplit;
  197. VSplitContainer *left_r_vsplit;
  198. HSplitContainer *main_hsplit;
  199. HSplitContainer *right_hsplit;
  200. VSplitContainer *right_l_vsplit;
  201. VSplitContainer *right_r_vsplit;
  202. VSplitContainer *center_split;
  203. // To access those easily by index
  204. Vector<VSplitContainer *> vsplits;
  205. Vector<HSplitContainer *> hsplits;
  206. // Main tabs
  207. Tabs *scene_tabs;
  208. PopupMenu *scene_tabs_context_menu;
  209. Panel *tab_preview_panel;
  210. TextureRect *tab_preview;
  211. int tab_closing;
  212. bool exiting;
  213. int old_split_ofs;
  214. VSplitContainer *top_split;
  215. HBoxContainer *bottom_hb;
  216. Control *vp_base;
  217. PaneDrag *pd;
  218. HBoxContainer *menu_hb;
  219. Control *viewport;
  220. MenuButton *file_menu;
  221. MenuButton *project_menu;
  222. MenuButton *debug_menu;
  223. MenuButton *settings_menu;
  224. MenuButton *help_menu;
  225. PopupMenu *tool_menu;
  226. ToolButton *export_button;
  227. ToolButton *prev_scene;
  228. ToolButton *play_button;
  229. ToolButton *pause_button;
  230. ToolButton *stop_button;
  231. ToolButton *run_settings_button;
  232. ToolButton *play_scene_button;
  233. ToolButton *play_custom_scene_button;
  234. ToolButton *search_button;
  235. TextureProgress *audio_vu;
  236. PluginConfigDialog *plugin_config_dialog;
  237. RichTextLabel *load_errors;
  238. AcceptDialog *load_error_dialog;
  239. Ref<Theme> theme;
  240. PopupMenu *recent_scenes;
  241. SceneTreeDock *scene_tree_dock;
  242. InspectorDock *inspector_dock;
  243. NodeDock *node_dock;
  244. ImportDock *import_dock;
  245. FileSystemDock *filesystem_dock;
  246. EditorRunNative *run_native;
  247. ConfirmationDialog *confirmation;
  248. ConfirmationDialog *save_confirmation;
  249. ConfirmationDialog *import_confirmation;
  250. ConfirmationDialog *pick_main_scene;
  251. AcceptDialog *accept;
  252. EditorAbout *about;
  253. AcceptDialog *warning;
  254. int overridden_default_layout;
  255. Ref<ConfigFile> default_layout;
  256. PopupMenu *editor_layouts;
  257. EditorNameDialog *layout_dialog;
  258. EditorSettingsDialog *settings_config_dialog;
  259. RunSettingsDialog *run_settings_dialog;
  260. ProjectSettingsEditor *project_settings;
  261. EditorFileDialog *file;
  262. ExportTemplateManager *export_template_manager;
  263. EditorFileDialog *file_templates;
  264. EditorFileDialog *file_export;
  265. EditorFileDialog *file_export_lib;
  266. EditorFileDialog *file_script;
  267. CheckButton *file_export_lib_merge;
  268. LineEdit *file_export_password;
  269. String current_path;
  270. MenuButton *update_menu;
  271. String defer_load_scene;
  272. String defer_export;
  273. String defer_export_platform;
  274. bool defer_export_debug;
  275. Node *_last_instanced_scene;
  276. EditorLog *log;
  277. CenterContainer *tabs_center;
  278. EditorQuickOpen *quick_open;
  279. EditorQuickOpen *quick_run;
  280. HBoxContainer *main_editor_button_vb;
  281. Vector<ToolButton *> main_editor_buttons;
  282. Vector<EditorPlugin *> editor_table;
  283. AudioStreamPreviewGenerator *preview_gen;
  284. ProgressDialog *progress_dialog;
  285. BackgroundProgress *progress_hb;
  286. DependencyErrorDialog *dependency_error;
  287. DependencyEditor *dependency_fixer;
  288. OrphanResourcesDialog *orphan_resources;
  289. ConfirmationDialog *open_imported;
  290. Button *new_inherited_button;
  291. String open_import_request;
  292. TabContainer *dock_slot[DOCK_SLOT_MAX];
  293. Rect2 dock_select_rect[DOCK_SLOT_MAX];
  294. int dock_select_rect_over;
  295. PopupPanel *dock_select_popup;
  296. Control *dock_select;
  297. ToolButton *dock_tab_move_left;
  298. ToolButton *dock_tab_move_right;
  299. int dock_popup_selected;
  300. Timer *dock_drag_timer;
  301. bool docks_visible;
  302. HBoxContainer *tabbar_container;
  303. ToolButton *distraction_free;
  304. ToolButton *scene_tab_add;
  305. bool scene_distraction;
  306. bool script_distraction;
  307. String _tmp_import_path;
  308. EditorExport *editor_export;
  309. Object *current;
  310. Ref<Resource> saving_resource;
  311. bool _playing_edited;
  312. String run_custom_filename;
  313. bool reference_resource_mem;
  314. bool save_external_resources_mem;
  315. uint64_t saved_version;
  316. uint64_t last_checked_version;
  317. bool unsaved_cache;
  318. String open_navigate;
  319. bool changing_scene;
  320. bool waiting_for_first_scan;
  321. bool waiting_for_sources_changed;
  322. uint32_t circle_step_msec;
  323. uint64_t circle_step_frame;
  324. int circle_step;
  325. Vector<EditorPlugin *> editor_plugins;
  326. EditorPlugin *editor_plugin_screen;
  327. EditorPluginList *editor_plugins_over;
  328. EditorPluginList *editor_plugins_force_over;
  329. EditorPluginList *editor_plugins_force_input_forwarding;
  330. EditorHistory editor_history;
  331. EditorData editor_data;
  332. EditorRun editor_run;
  333. EditorSelection *editor_selection;
  334. ProjectExportDialog *project_export;
  335. EditorResourcePreview *resource_preview;
  336. EditorFolding editor_folding;
  337. EditorFileServer *file_server;
  338. struct BottomPanelItem {
  339. String name;
  340. Control *control;
  341. ToolButton *button;
  342. };
  343. Vector<BottomPanelItem> bottom_panel_items;
  344. PanelContainer *bottom_panel;
  345. HBoxContainer *bottom_panel_hb;
  346. HBoxContainer *bottom_panel_hb_editors;
  347. VBoxContainer *bottom_panel_vb;
  348. ToolButton *bottom_panel_raise;
  349. void _bottom_panel_raise_toggled(bool);
  350. EditorInterface *editor_interface;
  351. void _bottom_panel_switch(bool p_enable, int p_idx);
  352. String external_file;
  353. List<String> previous_scenes;
  354. bool opening_prev;
  355. void _dialog_action(String p_file);
  356. void _edit_current();
  357. void _dialog_display_save_error(String p_file, Error p_error);
  358. void _dialog_display_load_error(String p_file, Error p_error);
  359. int current_option;
  360. void _menu_option(int p_option);
  361. void _menu_confirm_current();
  362. void _menu_option_confirm(int p_option, bool p_confirmed);
  363. void _tool_menu_option(int p_idx);
  364. void _update_debug_options();
  365. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  366. void _fs_changed();
  367. void _resources_reimported(const Vector<String> &p_resources);
  368. void _sources_changed(bool p_exist);
  369. void _node_renamed();
  370. void _editor_select_next();
  371. void _editor_select_prev();
  372. void _editor_select(int p_which);
  373. void _set_scene_metadata(const String &p_file, int p_idx = -1);
  374. void _get_scene_metadata(const String &p_file);
  375. void _update_title();
  376. void _update_scene_tabs();
  377. void _close_messages();
  378. void _show_messages();
  379. void _vp_resized();
  380. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  381. void _save_scene(String p_file, int idx = -1);
  382. void _save_all_scenes();
  383. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  384. void _discard_changes(const String &p_str = String());
  385. void _instance_request(const Vector<String> &p_files);
  386. void _hide_top_editors();
  387. void _display_top_editors(bool p_display);
  388. void _set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over);
  389. void _set_editing_top_editors(Object *p_current_object);
  390. void _quick_opened();
  391. void _quick_run();
  392. void _run(bool p_current = false, const String &p_custom = "");
  393. void _save_optimized();
  394. void _import_action(const String &p_action);
  395. void _import(const String &p_file);
  396. void _add_to_recent_scenes(const String &p_scene);
  397. void _update_recent_scenes();
  398. void _open_recent_scene(int p_idx);
  399. void _dropped_files(const Vector<String> &p_files, int p_screen);
  400. String _recent_scene;
  401. bool convert_old;
  402. void _unhandled_input(const Ref<InputEvent> &p_event);
  403. static void _load_error_notify(void *p_ud, const String &p_text);
  404. bool has_main_screen() const { return true; }
  405. String import_reload_fn;
  406. Set<FileDialog *> file_dialogs;
  407. Set<EditorFileDialog *> editor_file_dialogs;
  408. Map<String, Ref<Texture> > icon_type_cache;
  409. void _build_icon_type_cache();
  410. bool _initializing_addons;
  411. Map<String, EditorPlugin *> plugin_addons;
  412. static Ref<Texture> _file_dialog_get_icon(const String &p_path);
  413. static void _file_dialog_register(FileDialog *p_dialog);
  414. static void _file_dialog_unregister(FileDialog *p_dialog);
  415. static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
  416. static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
  417. void _cleanup_scene();
  418. void _remove_edited_scene();
  419. void _remove_scene(int index);
  420. bool _find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags);
  421. bool _find_and_save_edited_subresources(Object *obj, Map<RES, bool> &processed, int32_t flags);
  422. void _save_edited_subresources(Node *scene, Map<RES, bool> &processed, int32_t flags);
  423. void _mark_unsaved_scenes();
  424. void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
  425. void _save_scene_with_preview(String p_file, int p_idx = -1);
  426. Map<String, Set<String> > dependency_errors;
  427. static void _dependency_error_report(void *ud, const String &p_path, const String &p_dep, const String &p_type) {
  428. EditorNode *en = (EditorNode *)ud;
  429. if (!en->dependency_errors.has(p_path))
  430. en->dependency_errors[p_path] = Set<String>();
  431. en->dependency_errors[p_path].insert(p_dep + "::" + p_type);
  432. }
  433. struct ExportDefer {
  434. String preset;
  435. String path;
  436. bool debug;
  437. String password;
  438. } export_defer;
  439. bool disable_progress_dialog;
  440. static EditorNode *singleton;
  441. static Vector<EditorNodeInitCallback> _init_callbacks;
  442. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  443. void _dock_select_input(const Ref<InputEvent> &p_input);
  444. void _dock_move_left();
  445. void _dock_move_right();
  446. void _dock_select_draw();
  447. void _dock_pre_popup(int p_which);
  448. void _dock_split_dragged(int ofs);
  449. void _dock_popup_exit();
  450. void _scene_tab_changed(int p_tab);
  451. void _scene_tab_closed(int p_tab);
  452. void _scene_tab_hover(int p_tab);
  453. void _scene_tab_exit();
  454. void _scene_tab_input(const Ref<InputEvent> &p_input);
  455. void _reposition_active_tab(int idx_to);
  456. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  457. void _scene_tab_script_edited(int p_tab);
  458. Dictionary _get_main_scene_state();
  459. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  460. int _get_current_main_editor();
  461. void _save_docks();
  462. void _load_docks();
  463. void _save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  464. void _load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  465. void _update_dock_slots_visibility();
  466. void _dock_tab_changed(int p_tab);
  467. bool restoring_scenes;
  468. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  469. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  470. void _update_layouts_menu();
  471. void _layout_menu_option(int p_id);
  472. void _clear_undo_history();
  473. void _update_addon_config();
  474. static void _file_access_close_error_notify(const String &p_str);
  475. void _toggle_distraction_free_mode();
  476. enum {
  477. MAX_INIT_CALLBACKS = 128,
  478. MAX_BUILD_CALLBACKS = 128
  479. };
  480. void _inherit_imported(const String &p_action);
  481. void _open_imported();
  482. static int plugin_init_callback_count;
  483. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  484. void _save_default_environment();
  485. static int build_callback_count;
  486. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  487. bool _dimming;
  488. float _dim_time;
  489. Timer *_dim_timer;
  490. void _start_dimming(bool p_dimming);
  491. void _dim_timeout();
  492. void _license_tree_selected();
  493. Vector<Ref<EditorResourceConversionPlugin> > resource_conversion_plugins;
  494. PrintHandlerList print_handler;
  495. static void _print_handler(void *p_this, const String &p_string, bool p_error);
  496. static void _resource_saved(RES p_resource, const String &p_path);
  497. static void _resource_loaded(RES p_resource, const String &p_path);
  498. void _resources_changed(const PoolVector<String> &p_resources);
  499. protected:
  500. void _notification(int p_what);
  501. static void _bind_methods();
  502. public:
  503. bool call_build();
  504. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  505. enum EditorTable {
  506. EDITOR_2D = 0,
  507. EDITOR_3D,
  508. EDITOR_SCRIPT,
  509. EDITOR_ASSETLIB
  510. };
  511. void set_visible_editor(EditorTable p_table) { _editor_select(p_table); }
  512. static EditorNode *get_singleton() { return singleton; }
  513. EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
  514. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  515. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  516. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  517. EditorInspector *get_inspector() { return inspector_dock->get_inspector(); }
  518. Container *get_inspector_dock_addon_area() { return inspector_dock->get_addon_area(); }
  519. ScriptCreateDialog *get_script_create_dialog() { return scene_tree_dock->get_script_create_dialog(); }
  520. ProjectSettingsEditor *get_project_settings() { return project_settings; }
  521. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  522. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  523. void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); }
  524. void set_docks_visible(bool p_show);
  525. bool get_docks_visible() const;
  526. void set_distraction_free_mode(bool p_enter);
  527. bool get_distraction_free_mode() const;
  528. void add_control_to_dock(DockSlot p_slot, Control *p_control);
  529. void remove_control_from_dock(Control *p_control);
  530. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  531. bool is_addon_plugin_enabled(const String &p_addon) const;
  532. void edit_node(Node *p_node);
  533. void edit_resource(const Ref<Resource> &p_resource) { inspector_dock->edit_resource(p_resource); };
  534. void open_resource(const String &p_type) { inspector_dock->open_resource(p_type); };
  535. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  536. void save_resource(const Ref<Resource> &p_resource);
  537. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  538. void merge_from_scene() { _menu_option_confirm(FILE_IMPORT_SUBSCENE, false); }
  539. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  540. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  541. static HBoxContainer *get_menu_hb() { return singleton->menu_hb; }
  542. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  543. void edit_item(Object *p_object);
  544. bool item_has_editor(Object *p_object);
  545. void open_request(const String &p_path);
  546. bool is_changing_scene() const;
  547. static EditorLog *get_log() { return singleton->log; }
  548. Control *get_viewport();
  549. void set_edited_scene(Node *p_scene);
  550. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  551. Viewport *get_scene_root() { return scene_root; } //root of the scene being edited
  552. void fix_dependencies(const String &p_for_file);
  553. void clear_scene() { _cleanup_scene(); }
  554. Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_clear_errors = true, bool p_force_open_imported = false);
  555. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  556. bool is_scene_open(const String &p_path);
  557. void set_current_version(uint64_t p_version);
  558. void set_current_scene(int p_idx);
  559. static EditorData &get_editor_data() { return singleton->editor_data; }
  560. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  561. EditorHistory *get_editor_history() { return &editor_history; }
  562. static VSplitContainer *get_top_split() { return singleton->top_split; }
  563. void request_instance_scene(const String &p_path);
  564. void request_instance_scenes(const Vector<String> &p_files);
  565. FileSystemDock *get_filesystem_dock();
  566. ImportDock *get_import_dock();
  567. SceneTreeDock *get_scene_tree_dock();
  568. InspectorDock *get_inspector_dock();
  569. static UndoRedo *get_undo_redo() { return &singleton->editor_data.get_undo_redo(); }
  570. EditorSelection *get_editor_selection() { return editor_selection; }
  571. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  572. void notify_child_process_exited();
  573. OS::ProcessID get_child_process_id() const { return editor_run.get_pid(); }
  574. void stop_child_process();
  575. Ref<Theme> get_editor_theme() const { return theme; }
  576. Ref<Texture> get_object_icon(const Object *p_object, const String &p_fallback = "Object") const;
  577. Ref<Texture> get_class_icon(const String &p_class, const String &p_fallback = "Object") const;
  578. void show_accept(const String &p_text, const String &p_title);
  579. void show_warning(const String &p_text, const String &p_title = "Warning!");
  580. Error export_preset(const String &p_preset, const String &p_path, bool p_debug, const String &p_password, bool p_quit_after = false);
  581. static void register_editor_types();
  582. static void unregister_editor_types();
  583. Control *get_gui_base() { return gui_base; }
  584. Control *get_theme_base() { return gui_base->get_parent_control(); }
  585. static void add_io_error(const String &p_error);
  586. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  587. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  588. static void progress_end_task(const String &p_task);
  589. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  590. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  591. static void progress_end_task_bg(const String &p_task);
  592. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  593. if (p_with_preview)
  594. _save_scene_with_preview(p_file);
  595. else
  596. _save_scene(p_file);
  597. }
  598. bool is_scene_in_use(const String &p_path);
  599. void scan_import_changes();
  600. void save_layout();
  601. void open_export_template_manager();
  602. void reload_scene(const String &p_path);
  603. bool is_exiting() const { return exiting; }
  604. ToolButton *get_pause_button() { return pause_button; }
  605. ToolButton *add_bottom_panel_item(String p_text, Control *p_item);
  606. bool are_bottom_panels_hidden() const;
  607. void make_bottom_panel_item_visible(Control *p_item);
  608. void raise_bottom_panel_item(Control *p_item);
  609. void hide_bottom_panel();
  610. void remove_bottom_panel_item(Control *p_item);
  611. Variant drag_resource(const Ref<Resource> &p_res, Control *p_from);
  612. Variant drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  613. void add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant());
  614. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  615. void remove_tool_menu_item(const String &p_name);
  616. void save_all_scenes_and_restart();
  617. void dim_editor(bool p_dimming);
  618. void edit_current() { _edit_current(); };
  619. void update_keying() const { inspector_dock->update_keying(); };
  620. bool has_scenes_in_session();
  621. EditorNode();
  622. ~EditorNode();
  623. void get_singleton(const char *arg1, bool arg2);
  624. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  625. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  626. Vector<Ref<EditorResourceConversionPlugin> > find_resource_conversion_plugin(const Ref<Resource> &p_for_resource);
  627. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  628. static void add_build_callback(EditorBuildCallback p_callback);
  629. };
  630. struct EditorProgress {
  631. String task;
  632. bool step(const String &p_state, int p_step = -1, bool p_force_refresh = true) { return EditorNode::progress_task_step(task, p_state, p_step, p_force_refresh); }
  633. EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false) {
  634. EditorNode::progress_add_task(p_task, p_label, p_amount, p_can_cancel);
  635. task = p_task;
  636. }
  637. ~EditorProgress() { EditorNode::progress_end_task(task); }
  638. };
  639. class EditorPluginList : public Object {
  640. private:
  641. Vector<EditorPlugin *> plugins_list;
  642. public:
  643. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  644. plugins_list = p_plugins_list;
  645. }
  646. Vector<EditorPlugin *> &get_plugins_list() {
  647. return plugins_list;
  648. }
  649. void make_visible(bool p_visible);
  650. void edit(Object *p_object);
  651. bool forward_gui_input(const Ref<InputEvent> &p_event);
  652. void forward_canvas_draw_over_viewport(Control *p_overlay);
  653. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  654. bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  655. void forward_spatial_draw_over_viewport(Control *p_overlay);
  656. void forward_spatial_force_draw_over_viewport(Control *p_overlay);
  657. void add_plugin(EditorPlugin *p_plugin);
  658. void clear();
  659. bool empty();
  660. EditorPluginList();
  661. ~EditorPluginList();
  662. };
  663. struct EditorProgressBG {
  664. String task;
  665. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  666. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  667. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  668. task = p_task;
  669. }
  670. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  671. };
  672. #endif // EDITOR_NODE_H