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