editor_node.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. /*************************************************************************/
  2. /* editor_node.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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/templates/safe_refcount.h"
  33. #include "editor/editor_data.h"
  34. #include "editor/editor_export.h"
  35. #include "editor/editor_folding.h"
  36. #include "editor/editor_native_shader_source_visualizer.h"
  37. #include "editor/editor_run.h"
  38. #include "editor/editor_toaster.h"
  39. #include "editor/inspector_dock.h"
  40. #include "editor/property_editor.h"
  41. #include "editor/scene_tree_dock.h"
  42. #include "scene/gui/link_button.h"
  43. typedef void (*EditorNodeInitCallback)();
  44. typedef void (*EditorPluginInitializeCallback)();
  45. typedef bool (*EditorBuildCallback)();
  46. class AcceptDialog;
  47. class AudioStreamPreviewGenerator;
  48. class BackgroundProgress;
  49. class CenterContainer;
  50. class ConfirmationDialog;
  51. class Control;
  52. class DependencyEditor;
  53. class DependencyErrorDialog;
  54. class EditorAbout;
  55. class EditorCommandPalette;
  56. class EditorExport;
  57. class EditorFeatureProfileManager;
  58. class EditorFileServer;
  59. class EditorInspector;
  60. class EditorLayoutsDialog;
  61. class EditorLog;
  62. class EditorPlugin;
  63. class EditorPluginList;
  64. class EditorQuickOpen;
  65. class EditorResourcePreview;
  66. class EditorRunNative;
  67. class EditorSettingsDialog;
  68. class ExportTemplateManager;
  69. class FileSystemDock;
  70. class HSplitContainer;
  71. class ImportDock;
  72. class MenuButton;
  73. class NodeDock;
  74. class OrphanResourcesDialog;
  75. class Panel;
  76. class PanelContainer;
  77. class PluginConfigDialog;
  78. class ProgressDialog;
  79. class ProjectExportDialog;
  80. class ProjectSettingsEditor;
  81. class RunSettingsDialog;
  82. class ScriptCreateDialog;
  83. class TabContainer;
  84. class TabBar;
  85. class TextureProgressBar;
  86. class Button;
  87. class VSplitContainer;
  88. class Window;
  89. class SubViewport;
  90. class SceneImportSettings;
  91. class EditorExtensionManager;
  92. class DynamicFontImportSettings;
  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 = 0;
  114. SafeFlag 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_AND_RUN,
  128. FILE_SHOW_IN_FILESYSTEM,
  129. FILE_EXPORT_PROJECT,
  130. FILE_EXPORT_MESH_LIBRARY,
  131. FILE_INSTALL_ANDROID_SOURCE,
  132. FILE_EXPLORE_ANDROID_BUILD_TEMPLATES,
  133. FILE_SAVE_OPTIMIZED,
  134. FILE_OPEN_RECENT,
  135. FILE_OPEN_OLD_SCENE,
  136. FILE_QUICK_OPEN,
  137. FILE_QUICK_OPEN_SCENE,
  138. FILE_QUICK_OPEN_SCRIPT,
  139. FILE_OPEN_PREV,
  140. FILE_CLOSE,
  141. FILE_CLOSE_OTHERS,
  142. FILE_CLOSE_RIGHT,
  143. FILE_CLOSE_ALL,
  144. FILE_CLOSE_ALL_AND_QUIT,
  145. FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER,
  146. FILE_QUIT,
  147. FILE_EXTERNAL_OPEN_SCENE,
  148. EDIT_UNDO,
  149. EDIT_REDO,
  150. EDIT_RELOAD_SAVED_SCENE,
  151. TOOLS_ORPHAN_RESOURCES,
  152. TOOLS_CUSTOM,
  153. RESOURCE_SAVE,
  154. RESOURCE_SAVE_AS,
  155. RUN_PLAY,
  156. RUN_STOP,
  157. RUN_PLAY_SCENE,
  158. RUN_PLAY_CUSTOM_SCENE,
  159. RUN_SETTINGS,
  160. RUN_PROJECT_DATA_FOLDER,
  161. RUN_RELOAD_CURRENT_PROJECT,
  162. RUN_PROJECT_MANAGER,
  163. RUN_VCS_SETTINGS,
  164. RUN_VCS_SHUT_DOWN,
  165. SETTINGS_UPDATE_CONTINUOUSLY,
  166. SETTINGS_UPDATE_WHEN_CHANGED,
  167. SETTINGS_UPDATE_ALWAYS,
  168. SETTINGS_UPDATE_CHANGES,
  169. SETTINGS_UPDATE_SPINNER_HIDE,
  170. SETTINGS_PREFERENCES,
  171. SETTINGS_LAYOUT_SAVE,
  172. SETTINGS_LAYOUT_DELETE,
  173. SETTINGS_LAYOUT_DEFAULT,
  174. SETTINGS_EDITOR_DATA_FOLDER,
  175. SETTINGS_EDITOR_CONFIG_FOLDER,
  176. SETTINGS_MANAGE_EXPORT_TEMPLATES,
  177. SETTINGS_MANAGE_FEATURE_PROFILES,
  178. SETTINGS_INSTALL_ANDROID_BUILD_TEMPLATE,
  179. SETTINGS_PICK_MAIN_SCENE,
  180. SETTINGS_TOGGLE_CONSOLE,
  181. SETTINGS_TOGGLE_FULLSCREEN,
  182. SETTINGS_HELP,
  183. SCENE_TAB_CLOSE,
  184. EDITOR_SCREENSHOT,
  185. EDITOR_OPEN_SCREENSHOT,
  186. HELP_SEARCH,
  187. HELP_COMMAND_PALETTE,
  188. HELP_DOCS,
  189. HELP_QA,
  190. HELP_REPORT_A_BUG,
  191. HELP_SUGGEST_A_FEATURE,
  192. HELP_SEND_DOCS_FEEDBACK,
  193. HELP_COMMUNITY,
  194. HELP_ABOUT,
  195. HELP_SUPPORT_GODOT_DEVELOPMENT,
  196. SET_RENDERING_DRIVER_SAVE_AND_RESTART,
  197. GLOBAL_NEW_WINDOW,
  198. GLOBAL_SCENE,
  199. IMPORT_PLUGIN_BASE = 100,
  200. TOOL_MENU_BASE = 1000
  201. };
  202. SubViewport *scene_root; // root of the scene being edited
  203. PanelContainer *scene_root_parent;
  204. Control *theme_base;
  205. Control *gui_base;
  206. VBoxContainer *main_vbox;
  207. OptionButton *rendering_driver;
  208. ConfirmationDialog *video_restart_dialog;
  209. int rendering_driver_current;
  210. String rendering_driver_request;
  211. void _rendering_driver_selected(int);
  212. void _update_rendering_driver_color();
  213. // Split containers
  214. HSplitContainer *left_l_hsplit;
  215. VSplitContainer *left_l_vsplit;
  216. HSplitContainer *left_r_hsplit;
  217. VSplitContainer *left_r_vsplit;
  218. HSplitContainer *main_hsplit;
  219. HSplitContainer *right_hsplit;
  220. VSplitContainer *right_l_vsplit;
  221. VSplitContainer *right_r_vsplit;
  222. VSplitContainer *center_split;
  223. // To access those easily by index
  224. Vector<VSplitContainer *> vsplits;
  225. Vector<HSplitContainer *> hsplits;
  226. // Main tabs
  227. TabBar *scene_tabs;
  228. PopupMenu *scene_tabs_context_menu;
  229. Panel *tab_preview_panel;
  230. TextureRect *tab_preview;
  231. int tab_closing;
  232. bool exiting;
  233. bool dimmed;
  234. int old_split_ofs;
  235. VSplitContainer *top_split;
  236. HBoxContainer *bottom_hb;
  237. Control *vp_base;
  238. HBoxContainer *menu_hb;
  239. Control *main_control;
  240. MenuButton *file_menu;
  241. MenuButton *project_menu;
  242. MenuButton *debug_menu;
  243. MenuButton *settings_menu;
  244. MenuButton *help_menu;
  245. PopupMenu *tool_menu;
  246. Button *export_button;
  247. Button *prev_scene;
  248. Button *play_button;
  249. Button *pause_button;
  250. Button *stop_button;
  251. Button *run_settings_button;
  252. Button *play_scene_button;
  253. Button *play_custom_scene_button;
  254. Button *search_button;
  255. TextureProgressBar *audio_vu;
  256. Timer *screenshot_timer;
  257. PluginConfigDialog *plugin_config_dialog;
  258. RichTextLabel *load_errors;
  259. AcceptDialog *load_error_dialog;
  260. RichTextLabel *execute_outputs;
  261. AcceptDialog *execute_output_dialog;
  262. Ref<Theme> theme;
  263. PopupMenu *recent_scenes;
  264. SceneTreeDock *scene_tree_dock;
  265. InspectorDock *inspector_dock;
  266. NodeDock *node_dock;
  267. ImportDock *import_dock;
  268. FileSystemDock *filesystem_dock;
  269. EditorRunNative *run_native;
  270. ConfirmationDialog *confirmation;
  271. ConfirmationDialog *save_confirmation;
  272. ConfirmationDialog *import_confirmation;
  273. ConfirmationDialog *pick_main_scene;
  274. Button *select_current_scene_button;
  275. AcceptDialog *accept;
  276. AcceptDialog *save_accept;
  277. EditorAbout *about;
  278. AcceptDialog *warning;
  279. int overridden_default_layout;
  280. Ref<ConfigFile> default_layout;
  281. PopupMenu *editor_layouts;
  282. EditorLayoutsDialog *layout_dialog;
  283. ConfirmationDialog *custom_build_manage_templates;
  284. ConfirmationDialog *install_android_build_template;
  285. ConfirmationDialog *remove_android_build_template;
  286. EditorSettingsDialog *settings_config_dialog;
  287. ProjectSettingsEditor *project_settings;
  288. bool settings_changed = true; // make it update settings on first frame
  289. void _update_from_settings();
  290. PopupMenu *vcs_actions_menu;
  291. EditorFileDialog *file;
  292. ExportTemplateManager *export_template_manager;
  293. EditorFeatureProfileManager *feature_profile_manager;
  294. EditorFileDialog *file_templates;
  295. EditorFileDialog *file_export_lib;
  296. EditorFileDialog *file_script;
  297. EditorFileDialog *file_android_build_source;
  298. CheckBox *file_export_lib_merge;
  299. CheckBox *file_export_lib_apply_xforms;
  300. String current_path;
  301. MenuButton *update_spinner;
  302. EditorNativeShaderSourceVisualizer *native_shader_source_visualizer;
  303. String defer_load_scene;
  304. Node *_last_instantiated_scene;
  305. EditorLog *log;
  306. CenterContainer *tabs_center;
  307. EditorQuickOpen *quick_open;
  308. EditorQuickOpen *quick_run;
  309. EditorCommandPalette *command_palette;
  310. HBoxContainer *main_editor_button_vb;
  311. Vector<Button *> main_editor_buttons;
  312. Vector<EditorPlugin *> editor_table;
  313. AudioStreamPreviewGenerator *preview_gen;
  314. ProgressDialog *progress_dialog;
  315. BackgroundProgress *progress_hb;
  316. DependencyErrorDialog *dependency_error;
  317. DependencyEditor *dependency_fixer;
  318. OrphanResourcesDialog *orphan_resources;
  319. ConfirmationDialog *open_imported;
  320. Button *new_inherited_button;
  321. String open_import_request;
  322. Vector<Control *> floating_docks;
  323. TabContainer *dock_slot[DOCK_SLOT_MAX];
  324. Rect2 dock_select_rect[DOCK_SLOT_MAX];
  325. int dock_select_rect_over;
  326. PopupPanel *dock_select_popup;
  327. Control *dock_select;
  328. Button *dock_float;
  329. Button *dock_tab_move_left;
  330. Button *dock_tab_move_right;
  331. int dock_popup_selected;
  332. Timer *dock_drag_timer;
  333. bool docks_visible;
  334. HBoxContainer *tabbar_container;
  335. Button *distraction_free;
  336. Button *scene_tab_add;
  337. bool scene_distraction;
  338. bool script_distraction;
  339. String _tmp_import_path;
  340. EditorExport *editor_export;
  341. Object *current;
  342. Ref<Resource> saving_resource;
  343. bool _playing_edited;
  344. String run_custom_filename;
  345. bool reference_resource_mem;
  346. bool save_external_resources_mem;
  347. uint64_t saved_version;
  348. uint64_t last_checked_version;
  349. bool unsaved_cache;
  350. String open_navigate;
  351. bool changing_scene;
  352. bool waiting_for_first_scan;
  353. bool waiting_for_sources_changed;
  354. uint64_t update_spinner_step_msec;
  355. uint64_t update_spinner_step_frame;
  356. int update_spinner_step;
  357. Vector<EditorPlugin *> editor_plugins;
  358. EditorPlugin *editor_plugin_screen;
  359. EditorPluginList *editor_plugins_over;
  360. EditorPluginList *editor_plugins_force_over;
  361. EditorPluginList *editor_plugins_force_input_forwarding;
  362. EditorHistory editor_history;
  363. EditorData editor_data;
  364. EditorRun editor_run;
  365. EditorSelection *editor_selection;
  366. ProjectExportDialog *project_export;
  367. EditorResourcePreview *resource_preview;
  368. EditorFolding editor_folding;
  369. DynamicFontImportSettings *fontdata_import_settings;
  370. SceneImportSettings *scene_import_settings;
  371. struct BottomPanelItem {
  372. String name;
  373. Control *control = nullptr;
  374. Button *button = nullptr;
  375. };
  376. Vector<BottomPanelItem> bottom_panel_items;
  377. PanelContainer *bottom_panel;
  378. HBoxContainer *bottom_panel_hb;
  379. HBoxContainer *bottom_panel_hb_editors;
  380. VBoxContainer *bottom_panel_vb;
  381. EditorToaster *editor_toaster;
  382. LinkButton *version_btn;
  383. Button *bottom_panel_raise;
  384. Tree *disk_changed_list;
  385. ConfirmationDialog *disk_changed;
  386. void _bottom_panel_raise_toggled(bool);
  387. EditorInterface *editor_interface;
  388. void _bottom_panel_switch(bool p_enable, int p_idx);
  389. String external_file;
  390. List<String> previous_scenes;
  391. bool opening_prev;
  392. void _dialog_action(String p_file);
  393. void _edit_current();
  394. void _dialog_display_save_error(String p_file, Error p_error);
  395. void _dialog_display_load_error(String p_file, Error p_error);
  396. int current_option;
  397. void _menu_option(int p_option);
  398. void _menu_confirm_current();
  399. void _menu_option_confirm(int p_option, bool p_confirmed);
  400. void _android_build_source_selected(const String &p_file);
  401. void _request_screenshot();
  402. void _screenshot(bool p_use_utc = false);
  403. void _save_screenshot(NodePath p_path);
  404. void _tool_menu_option(int p_idx);
  405. void _update_file_menu_opened();
  406. void _update_file_menu_closed();
  407. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  408. void _remove_plugin_from_enabled(const String &p_name);
  409. void _fs_changed();
  410. void _resources_reimported(const Vector<String> &p_resources);
  411. void _sources_changed(bool p_exist);
  412. void _node_renamed();
  413. void _editor_select_next();
  414. void _editor_select_prev();
  415. void _editor_select(int p_which);
  416. void _set_scene_metadata(const String &p_file, int p_idx = -1);
  417. void _get_scene_metadata(const String &p_file);
  418. void _update_title();
  419. void _update_scene_tabs();
  420. void _version_control_menu_option(int p_idx);
  421. void _close_messages();
  422. void _show_messages();
  423. void _vp_resized();
  424. void _version_button_pressed();
  425. int _save_external_resources();
  426. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  427. void _save_scene(String p_file, int idx = -1);
  428. void _save_all_scenes();
  429. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  430. void _discard_changes(const String &p_str = String());
  431. void _inherit_request(String p_file);
  432. void _instantiate_request(const Vector<String> &p_files);
  433. void _display_top_editors(bool p_display);
  434. void _set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over);
  435. void _set_editing_top_editors(Object *p_current_object);
  436. void _quick_opened();
  437. void _quick_run();
  438. void _open_command_palette();
  439. void _run(bool p_current = false, const String &p_custom = "");
  440. void _run_native(const Ref<EditorExportPreset> &p_preset);
  441. void _add_to_recent_scenes(const String &p_scene);
  442. void _update_recent_scenes();
  443. void _open_recent_scene(int p_idx);
  444. void _global_menu_scene(const Variant &p_tag);
  445. void _global_menu_new_window(const Variant &p_tag);
  446. void _dropped_files(const Vector<String> &p_files, int p_screen);
  447. void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
  448. String _recent_scene;
  449. void _exit_editor();
  450. bool convert_old;
  451. virtual void unhandled_input(const Ref<InputEvent> &p_event) override;
  452. static void _load_error_notify(void *p_ud, const String &p_text);
  453. bool has_main_screen() const { return true; }
  454. String import_reload_fn;
  455. Set<String> textfile_extensions;
  456. Set<FileDialog *> file_dialogs;
  457. Set<EditorFileDialog *> editor_file_dialogs;
  458. Map<String, Ref<Texture2D>> icon_type_cache;
  459. void _build_icon_type_cache();
  460. bool _initializing_addons;
  461. Map<String, EditorPlugin *> plugin_addons;
  462. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  463. static void _file_dialog_register(FileDialog *p_dialog);
  464. static void _file_dialog_unregister(FileDialog *p_dialog);
  465. static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
  466. static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
  467. void _remove_edited_scene(bool p_change_tab = true);
  468. void _remove_scene(int index, bool p_change_tab = true);
  469. bool _find_and_save_resource(RES p_res, Map<RES, bool> &processed, int32_t flags);
  470. bool _find_and_save_edited_subresources(Object *obj, Map<RES, bool> &processed, int32_t flags);
  471. void _save_edited_subresources(Node *scene, Map<RES, bool> &processed, int32_t flags);
  472. void _mark_unsaved_scenes();
  473. void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
  474. void _save_scene_with_preview(String p_file, int p_idx = -1);
  475. Map<String, Set<String>> dependency_errors;
  476. static void _dependency_error_report(void *ud, const String &p_path, const String &p_dep, const String &p_type) {
  477. EditorNode *en = (EditorNode *)ud;
  478. if (!en->dependency_errors.has(p_path)) {
  479. en->dependency_errors[p_path] = Set<String>();
  480. }
  481. en->dependency_errors[p_path].insert(p_dep + "::" + p_type);
  482. }
  483. struct ExportDefer {
  484. String preset;
  485. String path;
  486. bool debug = false;
  487. bool pack_only = false;
  488. } export_defer;
  489. bool cmdline_export_mode;
  490. static EditorNode *singleton;
  491. static Vector<EditorNodeInitCallback> _init_callbacks;
  492. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  493. void _update_dock_containers();
  494. void _dock_select_input(const Ref<InputEvent> &p_input);
  495. void _dock_move_left();
  496. void _dock_move_right();
  497. void _dock_select_draw();
  498. void _dock_pre_popup(int p_which);
  499. void _dock_split_dragged(int ofs);
  500. void _dock_popup_exit();
  501. void _dock_floating_close_request(Control *p_control);
  502. void _dock_make_float();
  503. void _scene_tab_changed(int p_tab);
  504. void _scene_tab_closed(int p_tab, int option = SCENE_TAB_CLOSE);
  505. void _scene_tab_hovered(int p_tab);
  506. void _scene_tab_exit();
  507. void _scene_tab_input(const Ref<InputEvent> &p_input);
  508. void _reposition_active_tab(int idx_to);
  509. void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata);
  510. void _scene_tab_script_edited(int p_tab);
  511. Dictionary _get_main_scene_state();
  512. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  513. int _get_current_main_editor();
  514. void _save_docks();
  515. void _load_docks();
  516. void _save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  517. void _load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  518. void _update_dock_slots_visibility();
  519. void _dock_tab_changed(int p_tab);
  520. bool restoring_scenes;
  521. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  522. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  523. void _update_layouts_menu();
  524. void _layout_menu_option(int p_id);
  525. void _clear_undo_history();
  526. void _update_addon_config();
  527. static void _file_access_close_error_notify(const String &p_str);
  528. void _toggle_distraction_free_mode();
  529. enum {
  530. MAX_INIT_CALLBACKS = 128,
  531. MAX_BUILD_CALLBACKS = 128
  532. };
  533. void _inherit_imported(const String &p_action);
  534. void _open_imported();
  535. static int plugin_init_callback_count;
  536. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  537. void _save_default_environment();
  538. static int build_callback_count;
  539. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  540. void _update_update_spinner();
  541. Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
  542. PrintHandlerList print_handler;
  543. static void _print_handler(void *p_this, const String &p_string, bool p_error);
  544. static void _resource_saved(RES p_resource, const String &p_path);
  545. static void _resource_loaded(RES p_resource, const String &p_path);
  546. void _resources_changed(const Vector<String> &p_resources);
  547. void _scan_external_changes();
  548. void _reload_modified_scenes();
  549. void _reload_project_settings();
  550. void _resave_scenes(String p_str);
  551. void _feature_profile_changed();
  552. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  553. Ref<ImageTexture> _load_custom_class_icon(const String &p_path) const;
  554. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  555. bool immediate_dialog_confirmed = false;
  556. void _immediate_dialog_confirmed();
  557. void _select_default_main_screen_plugin();
  558. protected:
  559. void _notification(int p_what);
  560. static void _bind_methods();
  561. protected:
  562. friend class FileSystemDock;
  563. int get_current_tab();
  564. void set_current_tab(int p_tab);
  565. public:
  566. bool call_build();
  567. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  568. enum EditorTable {
  569. EDITOR_2D = 0,
  570. EDITOR_3D,
  571. EDITOR_SCRIPT,
  572. EDITOR_ASSETLIB
  573. };
  574. void set_visible_editor(EditorTable p_table) { _editor_select(p_table); }
  575. static EditorNode *get_singleton() { return singleton; }
  576. EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
  577. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  578. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  579. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  580. EditorInspector *get_inspector() { return inspector_dock->get_inspector(); }
  581. Container *get_inspector_dock_addon_area() { return inspector_dock->get_addon_area(); }
  582. ScriptCreateDialog *get_script_create_dialog() { return scene_tree_dock->get_script_create_dialog(); }
  583. ProjectSettingsEditor *get_project_settings() { return project_settings; }
  584. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  585. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  586. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  587. void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); }
  588. void set_docks_visible(bool p_show);
  589. bool get_docks_visible() const;
  590. void set_distraction_free_mode(bool p_enter);
  591. bool is_distraction_free_mode_enabled() const;
  592. void add_control_to_dock(DockSlot p_slot, Control *p_control);
  593. void remove_control_from_dock(Control *p_control);
  594. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  595. bool is_addon_plugin_enabled(const String &p_addon) const;
  596. void edit_node(Node *p_node);
  597. void edit_resource(const Ref<Resource> &p_resource) { inspector_dock->edit_resource(p_resource); };
  598. void open_resource(const String &p_type) { inspector_dock->open_resource(p_type); };
  599. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  600. void save_resource(const Ref<Resource> &p_resource);
  601. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  602. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  603. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  604. static HBoxContainer *get_menu_hb() { return singleton->menu_hb; }
  605. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  606. void edit_item(Object *p_object);
  607. void edit_item_resource(RES p_resource);
  608. bool item_has_editor(Object *p_object);
  609. void hide_top_editors();
  610. void select_editor_by_name(const String &p_name);
  611. void open_request(const String &p_path);
  612. bool is_changing_scene() const;
  613. static EditorLog *get_log() { return singleton->log; }
  614. Control *get_main_control();
  615. void set_edited_scene(Node *p_scene);
  616. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  617. SubViewport *get_scene_root() { return scene_root; } // root of the scene being edited
  618. void fix_dependencies(const String &p_for_file);
  619. int new_scene();
  620. 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, bool p_silent_change_tab = false);
  621. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  622. bool is_scene_open(const String &p_path);
  623. void set_current_version(uint64_t p_version);
  624. void set_current_scene(int p_idx);
  625. static EditorData &get_editor_data() { return singleton->editor_data; }
  626. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  627. EditorHistory *get_editor_history() { return &editor_history; }
  628. static VSplitContainer *get_top_split() { return singleton->top_split; }
  629. void request_instance_scene(const String &p_path);
  630. void request_instantiate_scenes(const Vector<String> &p_files);
  631. FileSystemDock *get_filesystem_dock();
  632. ImportDock *get_import_dock();
  633. SceneTreeDock *get_scene_tree_dock();
  634. InspectorDock *get_inspector_dock();
  635. static UndoRedo *get_undo_redo() { return &singleton->editor_data.get_undo_redo(); }
  636. EditorSelection *get_editor_selection() { return editor_selection; }
  637. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  638. void notify_all_debug_sessions_exited();
  639. OS::ProcessID has_child_process(OS::ProcessID p_pid) const { return editor_run.has_child_process(p_pid); }
  640. void stop_child_process(OS::ProcessID p_pid);
  641. Ref<Theme> get_editor_theme() const { return theme; }
  642. Ref<Script> get_object_custom_type_base(const Object *p_object) const;
  643. StringName get_object_custom_type_name(const Object *p_object) const;
  644. Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object") const;
  645. Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "Object") const;
  646. void show_accept(const String &p_text, const String &p_title);
  647. void show_save_accept(const String &p_text, const String &p_title);
  648. void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
  649. void _copy_warning(const String &p_str);
  650. Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only);
  651. static void register_editor_types();
  652. static void unregister_editor_types();
  653. Control *get_gui_base() { return gui_base; }
  654. Control *get_theme_base() { return gui_base->get_parent_control(); }
  655. static void add_io_error(const String &p_error);
  656. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  657. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  658. static void progress_end_task(const String &p_task);
  659. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  660. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  661. static void progress_end_task_bg(const String &p_task);
  662. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  663. if (p_with_preview) {
  664. _save_scene_with_preview(p_file);
  665. } else {
  666. _save_scene(p_file);
  667. }
  668. }
  669. bool is_scene_in_use(const String &p_path);
  670. void save_layout();
  671. void open_export_template_manager();
  672. void reload_scene(const String &p_path);
  673. bool is_exiting() const { return exiting; }
  674. Button *get_pause_button() { return pause_button; }
  675. Button *add_bottom_panel_item(String p_text, Control *p_item);
  676. void make_bottom_panel_item_visible(Control *p_item);
  677. void raise_bottom_panel_item(Control *p_item);
  678. void hide_bottom_panel();
  679. void remove_bottom_panel_item(Control *p_item);
  680. Variant drag_resource(const Ref<Resource> &p_res, Control *p_from);
  681. Variant drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  682. void add_tool_menu_item(const String &p_name, const Callable &p_callback);
  683. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  684. void remove_tool_menu_item(const String &p_name);
  685. void save_all_scenes();
  686. void save_scene_list(Vector<String> p_scene_filenames);
  687. void restart_editor();
  688. void notify_settings_changed();
  689. void dim_editor(bool p_dimming);
  690. bool is_editor_dimmed() const;
  691. void edit_current() { _edit_current(); };
  692. void update_keying() const { inspector_dock->update_keying(); };
  693. bool has_scenes_in_session();
  694. 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);
  695. EditorNode();
  696. ~EditorNode();
  697. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  698. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  699. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin(const Ref<Resource> &p_for_resource);
  700. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  701. static void add_build_callback(EditorBuildCallback p_callback);
  702. bool ensure_main_scene(bool p_from_native);
  703. Error run_play_native(int p_idx, int p_platform);
  704. void run_play();
  705. void run_play_current();
  706. void run_play_custom(const String &p_custom);
  707. void run_stop();
  708. bool is_run_playing() const;
  709. String get_run_playing_scene() const;
  710. static bool immediate_confirmation_dialog(const String &p_text, const String &p_ok_text = TTR("Ok"), const String &p_cancel_text = TTR("Cancel"));
  711. };
  712. struct EditorProgress {
  713. String task;
  714. 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); }
  715. EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false) {
  716. EditorNode::progress_add_task(p_task, p_label, p_amount, p_can_cancel);
  717. task = p_task;
  718. }
  719. ~EditorProgress() { EditorNode::progress_end_task(task); }
  720. };
  721. class EditorPluginList : public Object {
  722. private:
  723. Vector<EditorPlugin *> plugins_list;
  724. public:
  725. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  726. plugins_list = p_plugins_list;
  727. }
  728. Vector<EditorPlugin *> &get_plugins_list() {
  729. return plugins_list;
  730. }
  731. void make_visible(bool p_visible);
  732. void edit(Object *p_object);
  733. bool forward_gui_input(const Ref<InputEvent> &p_event);
  734. void forward_canvas_draw_over_viewport(Control *p_overlay);
  735. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  736. EditorPlugin::AfterGUIInput forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  737. void forward_spatial_draw_over_viewport(Control *p_overlay);
  738. void forward_spatial_force_draw_over_viewport(Control *p_overlay);
  739. void add_plugin(EditorPlugin *p_plugin);
  740. void remove_plugin(EditorPlugin *p_plugin);
  741. void clear();
  742. bool is_empty();
  743. EditorPluginList();
  744. ~EditorPluginList();
  745. };
  746. struct EditorProgressBG {
  747. String task;
  748. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  749. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  750. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  751. task = p_task;
  752. }
  753. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  754. };
  755. #endif // EDITOR_NODE_H