editor_node.h 32 KB

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