editor_node.h 28 KB

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