editor_node.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951
  1. /**************************************************************************/
  2. /* editor_node.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_NODE_H
  31. #define EDITOR_NODE_H
  32. #include "core/safe_refcount.h"
  33. #include "editor/editor_data.h"
  34. #include "editor/editor_folding.h"
  35. #include "editor/editor_run.h"
  36. #include "editor/inspector_dock.h"
  37. #include "editor/property_editor.h"
  38. #include "editor/scene_tree_dock.h"
  39. #include "scene/gui/link_button.h"
  40. typedef void (*EditorNodeInitCallback)();
  41. typedef void (*EditorPluginInitializeCallback)();
  42. typedef bool (*EditorBuildCallback)();
  43. class AcceptDialog;
  44. class AudioStreamPreviewGenerator;
  45. class BackgroundProgress;
  46. class CenterContainer;
  47. class ConfirmationDialog;
  48. class Control;
  49. class DependencyEditor;
  50. class DependencyErrorDialog;
  51. class EditorAbout;
  52. class EditorExport;
  53. class EditorFeatureProfileManager;
  54. class EditorFileServer;
  55. class EditorInspector;
  56. class EditorLayoutsDialog;
  57. class EditorLog;
  58. class EditorPlugin;
  59. class EditorPluginList;
  60. class EditorQuickOpen;
  61. class EditorResourcePreview;
  62. class EditorRunNative;
  63. class EditorSettingsDialog;
  64. class ExportTemplateManager;
  65. class FileSystemDock;
  66. class HSplitContainer;
  67. class ImportDock;
  68. class MenuButton;
  69. class NodeDock;
  70. class OrphanResourcesDialog;
  71. class PaneDrag;
  72. class Panel;
  73. class PanelContainer;
  74. class PluginConfigDialog;
  75. class ProgressDialog;
  76. class ProjectExportDialog;
  77. class ProjectSettingsEditor;
  78. class RunSettingsDialog;
  79. class ScriptCreateDialog;
  80. class TabContainer;
  81. class Tabs;
  82. class TextureProgress;
  83. class ToolButton;
  84. class VSplitContainer;
  85. class EditorNode : public Node {
  86. GDCLASS(EditorNode, Node);
  87. public:
  88. enum DockSlot {
  89. DOCK_SLOT_LEFT_UL,
  90. DOCK_SLOT_LEFT_BL,
  91. DOCK_SLOT_LEFT_UR,
  92. DOCK_SLOT_LEFT_BR,
  93. DOCK_SLOT_RIGHT_UL,
  94. DOCK_SLOT_RIGHT_BL,
  95. DOCK_SLOT_RIGHT_UR,
  96. DOCK_SLOT_RIGHT_BR,
  97. DOCK_SLOT_MAX
  98. };
  99. struct ExecuteThreadArgs {
  100. String path;
  101. List<String> args;
  102. String output;
  103. Thread execute_output_thread;
  104. Mutex execute_output_mutex;
  105. int exitcode;
  106. SafeFlag done;
  107. };
  108. private:
  109. enum {
  110. HISTORY_SIZE = 64
  111. };
  112. enum MenuOptions {
  113. FILE_NEW_SCENE,
  114. FILE_NEW_INHERITED_SCENE,
  115. FILE_OPEN_SCENE,
  116. FILE_SAVE_SCENE,
  117. FILE_SAVE_AS_SCENE,
  118. FILE_SAVE_ALL_SCENES,
  119. FILE_SAVE_AND_RUN,
  120. FILE_SHOW_IN_FILESYSTEM,
  121. FILE_IMPORT_SUBSCENE,
  122. FILE_EXPORT_PROJECT,
  123. FILE_EXPORT_MESH_LIBRARY,
  124. FILE_INSTALL_ANDROID_SOURCE,
  125. FILE_EXPLORE_ANDROID_BUILD_TEMPLATES,
  126. FILE_EXPORT_TILESET,
  127. FILE_SAVE_OPTIMIZED,
  128. FILE_OPEN_RECENT,
  129. FILE_OPEN_OLD_SCENE,
  130. FILE_QUICK_OPEN,
  131. FILE_QUICK_OPEN_SCENE,
  132. FILE_QUICK_OPEN_SCRIPT,
  133. FILE_OPEN_PREV,
  134. FILE_CLOSE,
  135. FILE_CLOSE_OTHERS,
  136. FILE_CLOSE_RIGHT,
  137. FILE_CLOSE_ALL,
  138. FILE_CLOSE_ALL_AND_QUIT,
  139. FILE_CLOSE_ALL_AND_RUN_PROJECT_MANAGER,
  140. FILE_CLOSE_ALL_AND_RELOAD_CURRENT_PROJECT,
  141. FILE_QUIT,
  142. FILE_EXTERNAL_OPEN_SCENE,
  143. EDIT_UNDO,
  144. EDIT_REDO,
  145. EDIT_RELOAD_SAVED_SCENE,
  146. TOOLS_ORPHAN_RESOURCES,
  147. TOOLS_CUSTOM,
  148. RESOURCE_SAVE,
  149. RESOURCE_SAVE_AS,
  150. RUN_PLAY,
  151. RUN_STOP,
  152. RUN_PLAY_SCENE,
  153. RUN_PLAY_NATIVE,
  154. RUN_PLAY_CUSTOM_SCENE,
  155. RUN_SCENE_SETTINGS,
  156. RUN_SETTINGS,
  157. RUN_USER_DATA_FOLDER,
  158. RELOAD_CURRENT_PROJECT,
  159. RUN_PROJECT_MANAGER,
  160. RUN_FILE_SERVER,
  161. RUN_LIVE_DEBUG,
  162. RUN_DEBUG_COLLISONS,
  163. RUN_DEBUG_NAVIGATION,
  164. RUN_DEBUG_SHADER_FALLBACKS,
  165. RUN_DEPLOY_REMOTE_DEBUG,
  166. RUN_RELOAD_SCRIPTS,
  167. RUN_VCS_SETTINGS,
  168. RUN_VCS_SHUT_DOWN,
  169. SETTINGS_UPDATE_CONTINUOUSLY,
  170. SETTINGS_UPDATE_VITAL_ONLY,
  171. SETTINGS_UPDATE_WHEN_CHANGED,
  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_INSTALL_ANDROID_BUILD_TEMPLATE,
  184. SETTINGS_PICK_MAIN_SCENE,
  185. SETTINGS_TOGGLE_FULLSCREEN,
  186. SETTINGS_HELP,
  187. SCENE_TAB_CLOSE,
  188. EDITOR_SCREENSHOT,
  189. EDITOR_OPEN_SCREENSHOT,
  190. HELP_SEARCH,
  191. HELP_DOCS,
  192. HELP_QA,
  193. HELP_REPORT_A_BUG,
  194. HELP_SUGGEST_A_FEATURE,
  195. HELP_SEND_DOCS_FEEDBACK,
  196. HELP_COMMUNITY,
  197. HELP_ABOUT,
  198. HELP_SUPPORT_GODOT_DEVELOPMENT,
  199. SET_VIDEO_DRIVER_SAVE_AND_RESTART,
  200. GLOBAL_NEW_WINDOW,
  201. GLOBAL_SCENE,
  202. IMPORT_PLUGIN_BASE = 100,
  203. TOOL_MENU_BASE = 1000
  204. };
  205. enum ScriptNameCasing {
  206. SCENE_NAME_CASING_AUTO,
  207. SCENE_NAME_CASING_PASCAL_CASE,
  208. SCENE_NAME_CASING_SNAKE_CASE
  209. };
  210. Viewport *scene_root; //root of the scene being edited
  211. PanelContainer *scene_root_parent;
  212. Control *theme_base;
  213. Control *gui_base;
  214. VBoxContainer *main_vbox;
  215. OptionButton *video_driver;
  216. ConfirmationDialog *video_restart_dialog;
  217. int video_driver_current;
  218. String video_driver_request;
  219. void _video_driver_selected(int);
  220. void _update_video_driver_color();
  221. // Split containers
  222. HSplitContainer *left_l_hsplit;
  223. VSplitContainer *left_l_vsplit;
  224. HSplitContainer *left_r_hsplit;
  225. VSplitContainer *left_r_vsplit;
  226. HSplitContainer *main_hsplit;
  227. HSplitContainer *right_hsplit;
  228. VSplitContainer *right_l_vsplit;
  229. VSplitContainer *right_r_vsplit;
  230. VSplitContainer *center_split;
  231. // To access those easily by index
  232. Vector<VSplitContainer *> vsplits;
  233. Vector<HSplitContainer *> hsplits;
  234. // Main tabs
  235. Tabs *scene_tabs;
  236. PopupMenu *scene_tabs_context_menu;
  237. Panel *tab_preview_panel;
  238. TextureRect *tab_preview;
  239. int tab_closing;
  240. bool exiting;
  241. bool dimmed;
  242. int old_split_ofs;
  243. VSplitContainer *top_split;
  244. HBoxContainer *bottom_hb;
  245. Control *vp_base;
  246. PaneDrag *pd;
  247. HBoxContainer *menu_hb;
  248. Control *viewport;
  249. MenuButton *file_menu;
  250. MenuButton *project_menu;
  251. MenuButton *debug_menu;
  252. MenuButton *settings_menu;
  253. MenuButton *help_menu;
  254. PopupMenu *tool_menu;
  255. ToolButton *export_button;
  256. ToolButton *prev_scene;
  257. ToolButton *play_button;
  258. ToolButton *pause_button;
  259. ToolButton *stop_button;
  260. ToolButton *run_settings_button;
  261. ToolButton *play_scene_button;
  262. ToolButton *play_custom_scene_button;
  263. ToolButton *search_button;
  264. TextureProgress *audio_vu;
  265. Timer *screenshot_timer;
  266. PluginConfigDialog *plugin_config_dialog;
  267. RichTextLabel *load_errors;
  268. AcceptDialog *load_error_dialog;
  269. RichTextLabel *execute_outputs;
  270. AcceptDialog *execute_output_dialog;
  271. Ref<Theme> theme;
  272. PopupMenu *recent_scenes;
  273. SceneTreeDock *scene_tree_dock;
  274. InspectorDock *inspector_dock;
  275. NodeDock *node_dock;
  276. ImportDock *import_dock;
  277. FileSystemDock *filesystem_dock;
  278. EditorRunNative *run_native;
  279. ConfirmationDialog *confirmation;
  280. ConfirmationDialog *save_confirmation;
  281. ConfirmationDialog *import_confirmation;
  282. ConfirmationDialog *pick_main_scene;
  283. Button *select_current_scene_button;
  284. AcceptDialog *accept;
  285. AcceptDialog *save_accept;
  286. EditorAbout *about;
  287. AcceptDialog *warning;
  288. int overridden_default_layout;
  289. Ref<ConfigFile> default_layout;
  290. PopupMenu *editor_layouts;
  291. EditorLayoutsDialog *layout_dialog;
  292. ConfirmationDialog *custom_build_manage_templates;
  293. ConfirmationDialog *install_android_build_template;
  294. ConfirmationDialog *remove_android_build_template;
  295. EditorSettingsDialog *settings_config_dialog;
  296. RunSettingsDialog *run_settings_dialog;
  297. ProjectSettingsEditor *project_settings;
  298. PopupMenu *vcs_actions_menu;
  299. EditorFileDialog *file;
  300. ExportTemplateManager *export_template_manager;
  301. EditorFeatureProfileManager *feature_profile_manager;
  302. EditorFileDialog *file_templates;
  303. EditorFileDialog *file_export_lib;
  304. EditorFileDialog *file_script;
  305. EditorFileDialog *file_android_build_source;
  306. CheckBox *file_export_lib_merge;
  307. CheckBox *file_export_lib_apply_xforms;
  308. String current_path;
  309. MenuButton *update_spinner;
  310. String defer_load_scene;
  311. Node *_last_instanced_scene;
  312. EditorLog *log;
  313. CenterContainer *tabs_center;
  314. EditorQuickOpen *quick_open;
  315. EditorQuickOpen *quick_run;
  316. HBoxContainer *main_editor_button_vb;
  317. Vector<ToolButton *> main_editor_buttons;
  318. Vector<EditorPlugin *> editor_table;
  319. AudioStreamPreviewGenerator *preview_gen;
  320. ProgressDialog *progress_dialog;
  321. BackgroundProgress *progress_hb;
  322. DependencyErrorDialog *dependency_error;
  323. DependencyEditor *dependency_fixer;
  324. OrphanResourcesDialog *orphan_resources;
  325. ConfirmationDialog *open_imported;
  326. Button *new_inherited_button;
  327. String open_import_request;
  328. TabContainer *dock_slot[DOCK_SLOT_MAX];
  329. Rect2 dock_select_rect[DOCK_SLOT_MAX];
  330. int dock_select_rect_over;
  331. PopupPanel *dock_select_popup;
  332. Control *dock_select;
  333. ToolButton *dock_tab_move_left;
  334. ToolButton *dock_tab_move_right;
  335. int dock_popup_selected;
  336. Timer *dock_drag_timer;
  337. bool docks_visible;
  338. HBoxContainer *tabbar_container;
  339. ToolButton *distraction_free;
  340. ToolButton *scene_tab_add;
  341. bool scene_distraction;
  342. bool script_distraction;
  343. String _tmp_import_path;
  344. EditorExport *editor_export;
  345. Object *current;
  346. Ref<Resource> saving_resource;
  347. bool _playing_edited;
  348. String run_custom_filename;
  349. bool reference_resource_mem;
  350. bool save_external_resources_mem;
  351. uint64_t saved_version;
  352. uint64_t last_checked_version;
  353. bool unsaved_cache;
  354. String open_navigate;
  355. bool changing_scene;
  356. bool waiting_for_first_scan;
  357. bool waiting_for_sources_changed;
  358. uint64_t update_spinner_step_msec;
  359. uint64_t update_spinner_step_frame;
  360. int update_spinner_step;
  361. Vector<EditorPlugin *> editor_plugins;
  362. EditorPlugin *editor_plugin_screen;
  363. EditorPluginList *editor_plugins_over;
  364. EditorPluginList *editor_plugins_force_over;
  365. EditorPluginList *editor_plugins_force_input_forwarding;
  366. EditorHistory editor_history;
  367. EditorData editor_data;
  368. EditorRun editor_run;
  369. EditorSelection *editor_selection;
  370. ProjectExportDialog *project_export;
  371. EditorResourcePreview *resource_preview;
  372. EditorFolding editor_folding;
  373. EditorFileServer *file_server;
  374. struct BottomPanelItem {
  375. String name;
  376. Control *control;
  377. ToolButton *button;
  378. };
  379. Vector<BottomPanelItem> bottom_panel_items;
  380. PanelContainer *bottom_panel;
  381. HBoxContainer *bottom_panel_hb;
  382. HBoxContainer *bottom_panel_hb_editors;
  383. VBoxContainer *bottom_panel_vb;
  384. LinkButton *version_btn;
  385. ToolButton *bottom_panel_raise;
  386. Tree *disk_changed_list;
  387. ConfirmationDialog *disk_changed;
  388. void _bottom_panel_raise_toggled(bool);
  389. EditorInterface *editor_interface;
  390. void _bottom_panel_switch(bool p_enable, int p_idx);
  391. String external_file;
  392. List<String> previous_scenes;
  393. bool opening_prev;
  394. void _dialog_action(String p_file);
  395. void _edit_current(bool p_skip_foreign = false);
  396. void _dialog_display_save_error(String p_file, Error p_error);
  397. void _dialog_display_load_error(String p_file, Error p_error);
  398. int current_option;
  399. void _menu_option(int p_option);
  400. void _menu_confirm_current();
  401. void _menu_option_confirm(int p_option, bool p_confirmed);
  402. void _android_build_source_selected(const String &p_file);
  403. void _request_screenshot();
  404. void _screenshot(bool p_use_utc = false);
  405. void _save_screenshot(NodePath p_path);
  406. void _tool_menu_option(int p_idx);
  407. void _update_debug_options();
  408. void _update_file_menu_opened();
  409. void _update_file_menu_closed();
  410. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  411. void _remove_plugin_from_enabled(const String &p_name);
  412. void _fs_changed();
  413. void _resources_reimported(const Vector<String> &p_resources);
  414. void _sources_changed(bool p_exist);
  415. void _node_renamed();
  416. void _editor_select_next();
  417. void _editor_select_prev();
  418. void _editor_select(int p_which);
  419. void _set_scene_metadata(const String &p_file, int p_idx = -1);
  420. void _get_scene_metadata(const String &p_file);
  421. void _update_title();
  422. void _update_scene_tabs();
  423. void _version_control_menu_option(int p_idx);
  424. void _close_messages();
  425. void _show_messages();
  426. void _vp_resized();
  427. void _version_button_pressed();
  428. int _save_external_resources();
  429. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  430. void _save_scene(String p_file, int idx = -1);
  431. void _save_all_scenes();
  432. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  433. void _discard_changes(const String &p_str = String());
  434. void _inherit_request(String p_file);
  435. void _instance_request(const Vector<String> &p_files);
  436. void _display_top_editors(bool p_display);
  437. void _set_top_editors(Vector<EditorPlugin *> p_editor_plugins_over);
  438. void _set_editing_top_editors(Object *p_current_object);
  439. void _quick_opened();
  440. void _quick_run();
  441. void _run(bool p_current = false, const String &p_custom = "");
  442. void _add_to_recent_scenes(const String &p_scene);
  443. void _update_recent_scenes();
  444. void _open_recent_scene(int p_idx);
  445. void _global_menu_action(const Variant &p_id, const Variant &p_meta);
  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. void _unhandled_input(const Ref<InputEvent> &p_event);
  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<FileDialog *> file_dialogs;
  456. Set<EditorFileDialog *> editor_file_dialogs;
  457. Map<String, Ref<Texture>> icon_type_cache;
  458. Map<Ref<Script>, Ref<Texture>> script_icon_cache;
  459. void _build_icon_type_cache();
  460. bool _initializing_addons;
  461. Map<String, EditorPlugin *> plugin_addons;
  462. static Ref<Texture> _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;
  487. bool pack_only;
  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 _dock_select_input(const Ref<InputEvent> &p_input);
  494. void _dock_move_left();
  495. void _dock_move_right();
  496. void _dock_select_draw();
  497. void _dock_pre_popup(int p_which);
  498. void _dock_split_dragged(int ofs);
  499. void _dock_popup_exit();
  500. void _scene_tab_changed(int p_tab);
  501. void _scene_tab_closed(int p_tab, int option = SCENE_TAB_CLOSE);
  502. void _scene_tab_hover(int p_tab);
  503. void _scene_tab_exit();
  504. void _scene_tab_input(const Ref<InputEvent> &p_input);
  505. void _reposition_active_tab(int idx_to);
  506. void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata);
  507. void _scene_tab_script_edited(int p_tab);
  508. Dictionary _get_main_scene_state();
  509. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  510. int _get_current_main_editor();
  511. void _save_docks();
  512. void _load_docks();
  513. void _save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  514. void _load_docks_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  515. void _update_dock_slots_visibility(bool p_keep_selected_tabs = false);
  516. void _dock_tab_changed(int p_tab);
  517. bool restoring_scenes;
  518. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  519. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout, const String &p_section);
  520. void _update_layouts_menu();
  521. void _layout_menu_option(int p_id);
  522. void _clear_undo_history();
  523. void _update_addon_config();
  524. static void _file_access_close_error_notify(const String &p_str);
  525. void _toggle_distraction_free_mode();
  526. enum {
  527. MAX_INIT_CALLBACKS = 128,
  528. MAX_BUILD_CALLBACKS = 128
  529. };
  530. void _inherit_imported(const String &p_action);
  531. void _open_imported();
  532. static int plugin_init_callback_count;
  533. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  534. void _save_default_environment();
  535. static int build_callback_count;
  536. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  537. void _update_update_spinner();
  538. Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
  539. PrintHandlerList print_handler;
  540. static void _print_handler(void *p_this, const String &p_string, bool p_error);
  541. static void _resource_saved(RES p_resource, const String &p_path);
  542. static void _resource_loaded(RES p_resource, const String &p_path);
  543. void _resources_changed(const PoolVector<String> &p_resources);
  544. void _scan_external_changes();
  545. void _reload_modified_scenes();
  546. void _reload_project_settings();
  547. void _resave_scenes(String p_str);
  548. void _project_settings_changed();
  549. void _feature_profile_changed();
  550. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  551. Ref<ImageTexture> _load_custom_class_icon(const String &p_path) const;
  552. static String _to_absolute_plugin_path(const String &p_path);
  553. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  554. protected:
  555. void _notification(int p_what);
  556. static void _bind_methods();
  557. protected:
  558. friend class FileSystemDock;
  559. int get_current_tab();
  560. void set_current_tab(int p_tab);
  561. public:
  562. bool call_build();
  563. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  564. enum EditorTable {
  565. EDITOR_2D = 0,
  566. EDITOR_3D,
  567. EDITOR_SCRIPT,
  568. EDITOR_ASSETLIB
  569. };
  570. void set_visible_editor(EditorTable p_table) { _editor_select(p_table); }
  571. static EditorNode *get_singleton() { return singleton; }
  572. EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
  573. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  574. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  575. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  576. EditorInspector *get_inspector() { return inspector_dock->get_inspector(); }
  577. Container *get_inspector_dock_addon_area() { return inspector_dock->get_addon_area(); }
  578. ScriptCreateDialog *get_script_create_dialog() { return scene_tree_dock->get_script_create_dialog(); }
  579. ProjectSettingsEditor *get_project_settings() { return project_settings; }
  580. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  581. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  582. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  583. void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); }
  584. void set_docks_visible(bool p_show);
  585. bool get_docks_visible() const;
  586. void set_distraction_free_mode(bool p_enter);
  587. bool is_distraction_free_mode_enabled() const;
  588. void add_control_to_dock(DockSlot p_slot, Control *p_control);
  589. void remove_control_from_dock(Control *p_control);
  590. void set_addon_plugin_enabled(String p_addon, bool p_enabled, bool p_config_changed = false);
  591. bool is_addon_plugin_enabled(const String &p_addon) const;
  592. void edit_node(Node *p_node);
  593. void edit_resource(const Ref<Resource> &p_resource) { inspector_dock->edit_resource(p_resource); };
  594. void open_resource(const String &p_type) { inspector_dock->open_resource(p_type); };
  595. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  596. void save_resource(const Ref<Resource> &p_resource);
  597. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  598. void merge_from_scene() { _menu_option_confirm(FILE_IMPORT_SUBSCENE, false); }
  599. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  600. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  601. static HBoxContainer *get_menu_hb() { return singleton->menu_hb; }
  602. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  603. void edit_item(Object *p_object);
  604. void edit_item_resource(RES p_resource);
  605. bool item_has_editor(Object *p_object);
  606. void hide_top_editors();
  607. void select_editor_by_name(const String &p_name);
  608. void open_request(const String &p_path);
  609. bool is_changing_scene() const;
  610. static EditorLog *get_log() { return singleton->log; }
  611. Control *get_viewport();
  612. void set_edited_scene(Node *p_scene);
  613. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  614. Viewport *get_scene_root() { return scene_root; } //root of the scene being edited
  615. void fix_dependencies(const String &p_for_file);
  616. int new_scene();
  617. 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);
  618. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  619. bool is_scene_open(const String &p_path);
  620. void set_current_version(uint64_t p_version);
  621. void set_current_scene(int p_idx);
  622. static EditorData &get_editor_data() { return singleton->editor_data; }
  623. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  624. EditorHistory *get_editor_history() { return &editor_history; }
  625. static VSplitContainer *get_top_split() { return singleton->top_split; }
  626. void request_instance_scene(const String &p_path);
  627. void request_instance_scenes(const Vector<String> &p_files);
  628. FileSystemDock *get_filesystem_dock();
  629. ImportDock *get_import_dock();
  630. SceneTreeDock *get_scene_tree_dock();
  631. InspectorDock *get_inspector_dock();
  632. static UndoRedo *get_undo_redo() { return &singleton->editor_data.get_undo_redo(); }
  633. EditorSelection *get_editor_selection() { return editor_selection; }
  634. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  635. void notify_child_process_exited();
  636. OS::ProcessID get_child_process_id() const { return editor_run.get_pid(); }
  637. void stop_child_process();
  638. Ref<Theme> get_editor_theme() const { return theme; }
  639. Ref<Script> get_object_custom_type_base(const Object *p_object) const;
  640. StringName get_object_custom_type_name(const Object *p_object) const;
  641. Ref<Texture> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
  642. Ref<Texture> get_class_icon(const String &p_class, const String &p_fallback = "Object") const;
  643. void show_accept(const String &p_text, const String &p_title);
  644. void show_save_accept(const String &p_text, const String &p_title);
  645. void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
  646. void _copy_warning(const String &p_str);
  647. Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only);
  648. static void register_editor_types();
  649. static void unregister_editor_types();
  650. Control *get_gui_base() { return gui_base; }
  651. Control *get_theme_base() { return gui_base->get_parent_control(); }
  652. static void add_io_error(const String &p_error);
  653. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  654. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  655. static void progress_end_task(const String &p_task);
  656. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  657. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  658. static void progress_end_task_bg(const String &p_task);
  659. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  660. if (p_with_preview) {
  661. _save_scene_with_preview(p_file);
  662. } else {
  663. _save_scene(p_file);
  664. }
  665. }
  666. bool is_scene_in_use(const String &p_path);
  667. void save_layout();
  668. void open_export_template_manager();
  669. void reload_scene(const String &p_path);
  670. bool is_exiting() const { return exiting; }
  671. ToolButton *get_pause_button() { return pause_button; }
  672. ToolButton *add_bottom_panel_item(String p_text, Control *p_item);
  673. bool are_bottom_panels_hidden() const;
  674. void make_bottom_panel_item_visible(Control *p_item);
  675. void raise_bottom_panel_item(Control *p_item);
  676. void hide_bottom_panel();
  677. void remove_bottom_panel_item(Control *p_item);
  678. Variant drag_resource(const Ref<Resource> &p_res, Control *p_from);
  679. Variant drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  680. void add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant());
  681. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  682. void remove_tool_menu_item(const String &p_name);
  683. void save_all_scenes();
  684. void save_scene_list(Vector<String> p_scene_filenames);
  685. void restart_editor();
  686. void dim_editor(bool p_dimming, bool p_force_dim = false);
  687. bool is_editor_dimmed() const;
  688. void edit_current() { _edit_current(); };
  689. void update_keying() const { inspector_dock->update_keying(); };
  690. bool has_scenes_in_session();
  691. 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);
  692. EditorNode();
  693. ~EditorNode();
  694. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  695. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  696. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin(const Ref<Resource> &p_for_resource);
  697. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  698. static void add_build_callback(EditorBuildCallback p_callback);
  699. bool ensure_main_scene(bool p_from_native);
  700. void run_play();
  701. void run_play_current();
  702. void run_play_custom(const String &p_custom);
  703. void run_stop();
  704. bool is_run_playing() const;
  705. String get_run_playing_scene() const;
  706. };
  707. struct EditorProgress {
  708. String task;
  709. 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); }
  710. EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false) {
  711. EditorNode::progress_add_task(p_task, p_label, p_amount, p_can_cancel);
  712. task = p_task;
  713. }
  714. ~EditorProgress() { EditorNode::progress_end_task(task); }
  715. };
  716. class EditorPluginList : public Object {
  717. private:
  718. Vector<EditorPlugin *> plugins_list;
  719. public:
  720. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  721. plugins_list = p_plugins_list;
  722. }
  723. Vector<EditorPlugin *> &get_plugins_list() {
  724. return plugins_list;
  725. }
  726. void make_visible(bool p_visible);
  727. void edit(Object *p_object);
  728. bool forward_gui_input(const Ref<InputEvent> &p_event);
  729. void forward_canvas_draw_over_viewport(Control *p_overlay);
  730. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  731. bool forward_spatial_gui_input(Camera *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  732. void forward_spatial_draw_over_viewport(Control *p_overlay);
  733. void forward_spatial_force_draw_over_viewport(Control *p_overlay);
  734. void add_plugin(EditorPlugin *p_plugin);
  735. void remove_plugin(EditorPlugin *p_plugin);
  736. void clear();
  737. bool empty();
  738. EditorPluginList();
  739. ~EditorPluginList();
  740. };
  741. struct EditorProgressBG {
  742. String task;
  743. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  744. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  745. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  746. task = p_task;
  747. }
  748. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  749. };
  750. #endif // EDITOR_NODE_H