editor_node.h 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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. #pragma once
  31. #include "core/object/script_language.h"
  32. #include "core/templates/safe_refcount.h"
  33. #include "editor/editor_data.h"
  34. #include "editor/plugins/editor_plugin.h"
  35. #include "editor/settings/editor_folding.h"
  36. typedef void (*EditorNodeInitCallback)();
  37. typedef void (*EditorPluginInitializeCallback)();
  38. typedef bool (*EditorBuildCallback)();
  39. class AcceptDialog;
  40. class ColorPicker;
  41. class ConfirmationDialog;
  42. class Control;
  43. class FileDialog;
  44. class HBoxContainer;
  45. class MenuBar;
  46. class MenuButton;
  47. class OptionButton;
  48. class Panel;
  49. class PanelContainer;
  50. class RichTextLabel;
  51. class SubViewport;
  52. class TextureProgressBar;
  53. class Translation;
  54. class Tree;
  55. class VBoxContainer;
  56. class VSplitContainer;
  57. class Window;
  58. class AudioStreamImportSettingsDialog;
  59. class AudioStreamPreviewGenerator;
  60. class BackgroundProgress;
  61. class DependencyEditor;
  62. class DependencyErrorDialog;
  63. class DockSplitContainer;
  64. class DynamicFontImportSettingsDialog;
  65. class EditorAbout;
  66. class EditorBuildProfileManager;
  67. class EditorBottomPanel;
  68. class EditorCommandPalette;
  69. class EditorDockManager;
  70. class EditorExport;
  71. class EditorExportPreset;
  72. class EditorFeatureProfileManager;
  73. class EditorFileDialog;
  74. class EditorFolding;
  75. class EditorLayoutsDialog;
  76. class EditorLog;
  77. class EditorMainScreen;
  78. class EditorNativeShaderSourceVisualizer;
  79. class EditorPluginList;
  80. class EditorResourcePreview;
  81. class EditorResourceConversionPlugin;
  82. class EditorRunBar;
  83. class EditorSceneTabs;
  84. class EditorSelectionHistory;
  85. class EditorSettingsDialog;
  86. class EditorTitleBar;
  87. class ExportTemplateManager;
  88. class EditorQuickOpenDialog;
  89. class FBXImporterManager;
  90. class FileSystemDock;
  91. class HistoryDock;
  92. class OrphanResourcesDialog;
  93. class ProgressDialog;
  94. class ProjectExportDialog;
  95. class ProjectSettingsEditor;
  96. class SceneImportSettingsDialog;
  97. class ProjectUpgradeTool;
  98. #ifdef ANDROID_ENABLED
  99. class TouchActionsPanel;
  100. #endif
  101. struct EditorProgress {
  102. String task;
  103. bool force_background = false;
  104. bool step(const String &p_state, int p_step = -1, bool p_force_refresh = true);
  105. EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false, bool p_force_background = false);
  106. ~EditorProgress();
  107. };
  108. class EditorNode : public Node {
  109. GDCLASS(EditorNode, Node);
  110. public:
  111. enum SceneNameCasing {
  112. SCENE_NAME_CASING_AUTO,
  113. SCENE_NAME_CASING_PASCAL_CASE,
  114. SCENE_NAME_CASING_SNAKE_CASE,
  115. SCENE_NAME_CASING_KEBAB_CASE,
  116. SCENE_NAME_CASING_CAMEL_CASE,
  117. };
  118. enum ActionOnPlay {
  119. ACTION_ON_PLAY_DO_NOTHING,
  120. ACTION_ON_PLAY_OPEN_OUTPUT,
  121. ACTION_ON_PLAY_OPEN_DEBUGGER,
  122. };
  123. enum ActionOnStop {
  124. ACTION_ON_STOP_DO_NOTHING,
  125. ACTION_ON_STOP_CLOSE_BUTTOM_PANEL,
  126. };
  127. enum MenuOptions {
  128. // Scene menu.
  129. SCENE_NEW_SCENE,
  130. SCENE_NEW_INHERITED_SCENE,
  131. SCENE_OPEN_SCENE,
  132. SCENE_OPEN_PREV,
  133. SCENE_OPEN_RECENT,
  134. SCENE_SAVE_SCENE,
  135. SCENE_SAVE_AS_SCENE,
  136. SCENE_SAVE_ALL_SCENES,
  137. SCENE_MULTI_SAVE_AS_SCENE,
  138. SCENE_QUICK_OPEN,
  139. SCENE_QUICK_OPEN_SCENE,
  140. SCENE_QUICK_OPEN_SCRIPT,
  141. SCENE_UNDO,
  142. SCENE_REDO,
  143. SCENE_RELOAD_SAVED_SCENE,
  144. SCENE_CLOSE,
  145. SCENE_QUIT,
  146. FILE_EXPORT_MESH_LIBRARY,
  147. // Project menu.
  148. PROJECT_OPEN_SETTINGS,
  149. PROJECT_FIND_IN_FILES,
  150. PROJECT_VERSION_CONTROL,
  151. PROJECT_EXPORT,
  152. PROJECT_PACK_AS_ZIP,
  153. PROJECT_INSTALL_ANDROID_SOURCE,
  154. PROJECT_OPEN_USER_DATA_FOLDER,
  155. PROJECT_RELOAD_CURRENT_PROJECT,
  156. PROJECT_QUIT_TO_PROJECT_MANAGER,
  157. TOOLS_ORPHAN_RESOURCES,
  158. TOOLS_BUILD_PROFILE_MANAGER,
  159. TOOLS_PROJECT_UPGRADE,
  160. TOOLS_CUSTOM,
  161. VCS_METADATA,
  162. VCS_SETTINGS,
  163. // Editor menu.
  164. EDITOR_OPEN_SETTINGS,
  165. EDITOR_COMMAND_PALETTE,
  166. EDITOR_TAKE_SCREENSHOT,
  167. EDITOR_TOGGLE_FULLSCREEN,
  168. EDITOR_OPEN_DATA_FOLDER,
  169. EDITOR_OPEN_CONFIG_FOLDER,
  170. EDITOR_MANAGE_FEATURE_PROFILES,
  171. EDITOR_MANAGE_EXPORT_TEMPLATES,
  172. EDITOR_CONFIGURE_FBX_IMPORTER,
  173. LAYOUT_SAVE,
  174. LAYOUT_DELETE,
  175. LAYOUT_DEFAULT,
  176. // Help menu.
  177. HELP_SEARCH,
  178. HELP_DOCS,
  179. HELP_FORUM,
  180. HELP_COMMUNITY,
  181. HELP_COPY_SYSTEM_INFO,
  182. HELP_REPORT_A_BUG,
  183. HELP_SUGGEST_A_FEATURE,
  184. HELP_SEND_DOCS_FEEDBACK,
  185. HELP_ABOUT,
  186. HELP_SUPPORT_GODOT_DEVELOPMENT,
  187. // Update spinner menu.
  188. SPINNER_UPDATE_CONTINUOUSLY,
  189. SPINNER_UPDATE_WHEN_CHANGED,
  190. SPINNER_UPDATE_SPINNER_HIDE,
  191. // Non-menu options.
  192. SCENE_TAB_CLOSE,
  193. SAVE_AND_RUN,
  194. SAVE_AND_RUN_MAIN_SCENE,
  195. RESOURCE_SAVE,
  196. RESOURCE_SAVE_AS,
  197. SETTINGS_PICK_MAIN_SCENE,
  198. };
  199. struct ExecuteThreadArgs {
  200. String path;
  201. List<String> args;
  202. String output;
  203. Thread execute_output_thread;
  204. Mutex execute_output_mutex;
  205. int exitcode = 0;
  206. SafeFlag done;
  207. };
  208. private:
  209. friend class EditorSceneTabs;
  210. enum {
  211. MAX_INIT_CALLBACKS = 128,
  212. MAX_BUILD_CALLBACKS = 128,
  213. };
  214. struct ExportDefer {
  215. String preset;
  216. String path;
  217. bool debug = false;
  218. bool pack_only = false;
  219. bool android_build_template = false;
  220. bool patch = false;
  221. Vector<String> patches;
  222. } export_defer;
  223. static EditorNode *singleton;
  224. EditorData editor_data;
  225. EditorFolding editor_folding;
  226. EditorSelectionHistory editor_history;
  227. EditorCommandPalette *command_palette = nullptr;
  228. EditorQuickOpenDialog *quick_open_dialog = nullptr;
  229. EditorExport *editor_export = nullptr;
  230. EditorLog *log = nullptr;
  231. EditorNativeShaderSourceVisualizer *native_shader_source_visualizer = nullptr;
  232. EditorPluginList *editor_plugins_force_input_forwarding = nullptr;
  233. EditorPluginList *editor_plugins_force_over = nullptr;
  234. EditorPluginList *editor_plugins_over = nullptr;
  235. EditorQuickOpenDialog *quick_open_color_palette = nullptr;
  236. EditorResourcePreview *resource_preview = nullptr;
  237. EditorSelection *editor_selection = nullptr;
  238. EditorSettingsDialog *editor_settings_dialog = nullptr;
  239. HistoryDock *history_dock = nullptr;
  240. ProjectExportDialog *project_export = nullptr;
  241. ProjectSettingsEditor *project_settings_editor = nullptr;
  242. FBXImporterManager *fbx_importer_manager = nullptr;
  243. Vector<EditorPlugin *> editor_plugins;
  244. bool _initializing_plugins = false;
  245. HashMap<String, EditorPlugin *> addon_name_to_plugin;
  246. LocalVector<String> pending_addons;
  247. HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
  248. bool is_main_screen_editing = false;
  249. Control *gui_base = nullptr;
  250. VBoxContainer *main_vbox = nullptr;
  251. OptionButton *renderer = nullptr;
  252. #ifdef ANDROID_ENABLED
  253. VBoxContainer *base_vbox = nullptr; // It only contains the title_bar and main_hbox.
  254. HBoxContainer *main_hbox = nullptr; // It only contains the touch_actions_panel and main_vbox.
  255. TouchActionsPanel *touch_actions_panel = nullptr;
  256. void _touch_actions_panel_mode_changed();
  257. #endif
  258. ConfirmationDialog *video_restart_dialog = nullptr;
  259. int renderer_current = 0;
  260. String renderer_request;
  261. // Split containers.
  262. DockSplitContainer *left_l_hsplit = nullptr;
  263. DockSplitContainer *left_l_vsplit = nullptr;
  264. DockSplitContainer *left_r_hsplit = nullptr;
  265. DockSplitContainer *left_r_vsplit = nullptr;
  266. DockSplitContainer *main_hsplit = nullptr;
  267. DockSplitContainer *right_hsplit = nullptr;
  268. DockSplitContainer *right_l_vsplit = nullptr;
  269. DockSplitContainer *right_r_vsplit = nullptr;
  270. DockSplitContainer *center_split = nullptr;
  271. // Main tabs.
  272. EditorSceneTabs *scene_tabs = nullptr;
  273. int tab_closing_idx = 0;
  274. List<String> tabs_to_close;
  275. List<int> scenes_to_save_as;
  276. int tab_closing_menu_option = -1;
  277. bool exiting = false;
  278. bool dimmed = false;
  279. DisplayServer::WindowMode prev_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
  280. int old_split_ofs = 0;
  281. VSplitContainer *top_split = nullptr;
  282. Control *vp_base = nullptr;
  283. Label *project_title = nullptr;
  284. Control *left_menu_spacer = nullptr;
  285. Control *right_menu_spacer = nullptr;
  286. EditorTitleBar *title_bar = nullptr;
  287. EditorRunBar *project_run_bar = nullptr;
  288. HBoxContainer *right_menu_hb = nullptr;
  289. // Spacers to center 2D / 3D / Script buttons.
  290. HBoxContainer *left_spacer = nullptr;
  291. Control *right_spacer = nullptr;
  292. Control *menu_btn_spacer = nullptr;
  293. MenuButton *main_menu_button = nullptr;
  294. MenuBar *main_menu_bar = nullptr;
  295. PopupMenu *apple_menu = nullptr;
  296. PopupMenu *file_menu = nullptr;
  297. PopupMenu *project_menu = nullptr;
  298. PopupMenu *debug_menu = nullptr;
  299. PopupMenu *settings_menu = nullptr;
  300. PopupMenu *help_menu = nullptr;
  301. PopupMenu *tool_menu = nullptr;
  302. PopupMenu *export_as_menu = nullptr;
  303. Button *export_button = nullptr;
  304. Button *search_button = nullptr;
  305. TextureProgressBar *audio_vu = nullptr;
  306. Timer *screenshot_timer = nullptr;
  307. uint64_t started_timestamp = 0;
  308. RichTextLabel *load_errors = nullptr;
  309. AcceptDialog *load_error_dialog = nullptr;
  310. bool load_errors_queued_to_display = false;
  311. RichTextLabel *execute_outputs = nullptr;
  312. AcceptDialog *execute_output_dialog = nullptr;
  313. Ref<Theme> theme;
  314. Timer *system_theme_timer = nullptr;
  315. bool follow_system_theme = false;
  316. bool use_system_accent_color = false;
  317. bool last_dark_mode_state = false;
  318. Color last_system_base_color = Color(0, 0, 0, 0);
  319. Color last_system_accent_color = Color(0, 0, 0, 0);
  320. PopupMenu *recent_scenes = nullptr;
  321. String _recent_scene;
  322. List<String> prev_closed_scenes;
  323. String defer_load_scene;
  324. Node *_last_instantiated_scene = nullptr;
  325. ConfirmationDialog *confirmation = nullptr;
  326. Button *confirmation_button = nullptr;
  327. ConfirmationDialog *save_confirmation = nullptr;
  328. ConfirmationDialog *import_confirmation = nullptr;
  329. ConfirmationDialog *pick_main_scene = nullptr;
  330. ConfirmationDialog *open_project_settings = nullptr;
  331. Button *select_current_scene_button = nullptr;
  332. AcceptDialog *accept = nullptr;
  333. AcceptDialog *save_accept = nullptr;
  334. EditorAbout *about = nullptr;
  335. AcceptDialog *warning = nullptr;
  336. EditorPlugin *plugin_to_save = nullptr;
  337. int overridden_default_layout = -1;
  338. Ref<ConfigFile> default_layout;
  339. PopupMenu *editor_layouts = nullptr;
  340. EditorLayoutsDialog *layout_dialog = nullptr;
  341. ConfirmationDialog *gradle_build_manage_templates = nullptr;
  342. ConfirmationDialog *install_android_build_template = nullptr;
  343. ConfirmationDialog *remove_android_build_template = nullptr;
  344. Label *install_android_build_template_message = nullptr;
  345. OptionButton *choose_android_export_profile = nullptr;
  346. Ref<EditorExportPreset> android_export_preset;
  347. PopupMenu *vcs_actions_menu = nullptr;
  348. EditorFileDialog *file = nullptr;
  349. ExportTemplateManager *export_template_manager = nullptr;
  350. EditorFeatureProfileManager *feature_profile_manager = nullptr;
  351. EditorBuildProfileManager *build_profile_manager = nullptr;
  352. EditorFileDialog *file_templates = nullptr;
  353. EditorFileDialog *file_export_lib = nullptr;
  354. EditorFileDialog *file_script = nullptr;
  355. EditorFileDialog *file_android_build_source = nullptr;
  356. EditorFileDialog *file_pack_zip = nullptr;
  357. String current_path;
  358. MenuButton *update_spinner = nullptr;
  359. EditorMainScreen *editor_main_screen = nullptr;
  360. AudioStreamPreviewGenerator *audio_preview_gen = nullptr;
  361. ProgressDialog *progress_dialog = nullptr;
  362. BackgroundProgress *progress_hb = nullptr;
  363. DependencyErrorDialog *dependency_error = nullptr;
  364. HashMap<String, HashSet<String>> dependency_errors;
  365. DependencyEditor *dependency_fixer = nullptr;
  366. OrphanResourcesDialog *orphan_resources = nullptr;
  367. ConfirmationDialog *open_imported = nullptr;
  368. Button *new_inherited_button = nullptr;
  369. String open_import_request;
  370. EditorDockManager *editor_dock_manager = nullptr;
  371. Timer *editor_layout_save_delay_timer = nullptr;
  372. Timer *scan_changes_timer = nullptr;
  373. Button *distraction_free = nullptr;
  374. Callable palette_file_selected_callback;
  375. EditorBottomPanel *bottom_panel = nullptr;
  376. Tree *disk_changed_list = nullptr;
  377. LocalVector<String> disk_changed_scenes;
  378. bool disk_changed_project = false;
  379. ConfirmationDialog *disk_changed = nullptr;
  380. ConfirmationDialog *project_data_missing = nullptr;
  381. bool scene_distraction_free = false;
  382. bool script_distraction_free = false;
  383. bool changing_scene = false;
  384. bool cmdline_mode = false;
  385. bool convert_old = false;
  386. bool immediate_dialog_confirmed = false;
  387. bool restoring_scenes = false;
  388. bool settings_overrides_changed = false;
  389. bool unsaved_cache = true;
  390. bool requested_first_scan = false;
  391. bool waiting_for_first_scan = true;
  392. bool load_editor_layout_done = false;
  393. HashSet<Ref<Translation>> tracked_translations;
  394. bool pending_translation_notification = false;
  395. int current_menu_option = 0;
  396. SubViewport *scene_root = nullptr; // Root of the scene being edited.
  397. Object *current = nullptr;
  398. Ref<Resource> saving_resource;
  399. HashSet<Ref<Resource>> saving_resources_in_path;
  400. uint64_t update_spinner_step_msec = 0;
  401. uint64_t update_spinner_step_frame = 0;
  402. int update_spinner_step = 0;
  403. String saving_scene;
  404. EditorProgress *save_scene_progress = nullptr;
  405. DynamicFontImportSettingsDialog *fontdata_import_settings = nullptr;
  406. SceneImportSettingsDialog *scene_import_settings = nullptr;
  407. AudioStreamImportSettingsDialog *audio_stream_import_settings = nullptr;
  408. String import_reload_fn;
  409. HashSet<String> textfile_extensions;
  410. HashSet<String> other_file_extensions;
  411. HashSet<FileDialog *> file_dialogs;
  412. HashSet<EditorFileDialog *> editor_file_dialogs;
  413. Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
  414. PrintHandlerList print_handler;
  415. HashMap<String, Ref<Texture2D>> icon_type_cache;
  416. HashMap<Pair<String, String>, Ref<Texture2D>> class_icon_cache;
  417. ProjectUpgradeTool *project_upgrade_tool = nullptr;
  418. bool run_project_upgrade_tool = false;
  419. bool was_window_windowed_last = false;
  420. bool unfocused_low_processor_usage_mode_enabled = true;
  421. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  422. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  423. static int build_callback_count;
  424. static int plugin_init_callback_count;
  425. static Vector<EditorNodeInitCallback> _init_callbacks;
  426. String _get_system_info() const;
  427. bool _should_display_update_spinner() const;
  428. static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
  429. DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
  430. if (!singleton->dependency_errors.has(p_path)) {
  431. singleton->dependency_errors[p_path] = HashSet<String>();
  432. }
  433. singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
  434. }
  435. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  436. static void _file_dialog_register(FileDialog *p_dialog);
  437. static void _file_dialog_unregister(FileDialog *p_dialog);
  438. static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
  439. static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
  440. static void _file_access_close_error_notify(const String &p_str);
  441. static void _file_access_close_error_notify_impl(const String &p_str);
  442. static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
  443. static void _print_handler_impl(const String &p_string, bool p_error, bool p_rich);
  444. static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
  445. static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
  446. void _update_theme(bool p_skip_creation = false);
  447. void _build_icon_type_cache();
  448. void _enable_pending_addons();
  449. void _dialog_action(String p_file);
  450. void _add_to_history(const Object *p_object, const String &p_property, bool p_inspector_only);
  451. void _edit_current(bool p_skip_foreign = false, bool p_skip_inspector_update = false);
  452. void _dialog_display_save_error(String p_file, Error p_error);
  453. void _dialog_display_load_error(String p_file, Error p_error);
  454. void _menu_option(int p_option);
  455. void _menu_confirm_current();
  456. void _menu_option_confirm(int p_option, bool p_confirmed);
  457. void _android_build_source_selected(const String &p_file);
  458. void _android_export_preset_selected(int p_index);
  459. void _android_install_build_template();
  460. void _android_explore_build_templates();
  461. void _request_screenshot();
  462. void _screenshot(bool p_use_utc = false);
  463. void _save_screenshot(const String &p_path);
  464. void _save_screenshot_with_embedded_process(int64_t p_w, int64_t p_h, const String &p_emb_path, const Rect2i &p_rect, const String &p_path);
  465. void _check_system_theme_changed();
  466. void _tool_menu_option(int p_idx);
  467. void _export_as_menu_option(int p_idx);
  468. void _update_file_menu_opened();
  469. void _palette_quick_open_dialog();
  470. void _remove_plugin_from_enabled(const String &p_name);
  471. void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
  472. void _plugin_over_self_own(EditorPlugin *p_plugin);
  473. void _fs_changed();
  474. void _resources_reimporting(const Vector<String> &p_resources);
  475. void _resources_reimported(const Vector<String> &p_resources);
  476. void _sources_changed(bool p_exist);
  477. void _remove_lock_file();
  478. void _node_renamed();
  479. void _save_editor_states(const String &p_file, int p_idx = -1);
  480. void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
  481. void _update_title();
  482. void _update_unsaved_cache();
  483. void _version_control_menu_option(int p_idx);
  484. void _close_messages();
  485. void _show_messages();
  486. void _vp_resized();
  487. void _titlebar_resized();
  488. void _viewport_resized();
  489. void _update_undo_redo_allowed();
  490. int _save_external_resources(bool p_also_save_external_data = false);
  491. void _save_scene_silently();
  492. void _set_current_scene(int p_idx);
  493. void _set_current_scene_nocheck(int p_idx);
  494. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  495. void _save_scene(String p_file, int idx = -1);
  496. void _save_all_scenes();
  497. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  498. void _discard_changes(const String &p_str = String());
  499. void _scene_tab_closed(int p_tab);
  500. void _cancel_close_scene_tab();
  501. void _prepare_save_confirmation_popup();
  502. void _inherit_request(String p_file);
  503. void _instantiate_request(const Vector<String> &p_files);
  504. void _quick_opened(const String &p_file_path);
  505. void _open_command_palette();
  506. void _project_run_started();
  507. void _project_run_stopped();
  508. void _update_prev_closed_scenes(const String &p_scene_path, bool p_add_scene);
  509. void _add_to_recent_scenes(const String &p_scene);
  510. void _update_recent_scenes();
  511. void _open_recent_scene(int p_idx);
  512. void _dropped_files(const Vector<String> &p_files);
  513. void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
  514. void _update_vsync_mode();
  515. void _update_from_settings();
  516. void _gdextensions_reloaded();
  517. void _update_translations();
  518. void _translation_resources_changed();
  519. void _queue_translation_notification();
  520. void _propagate_translation_notification();
  521. void _renderer_selected(int);
  522. void _update_renderer_color();
  523. void _add_renderer_entry(const String &p_renderer_name, bool p_mark_overridden);
  524. void _set_renderer_name_save_and_restart();
  525. void _exit_editor(int p_exit_code);
  526. virtual void input(const Ref<InputEvent> &p_event) override;
  527. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  528. bool has_main_screen() const { return true; }
  529. void _remove_edited_scene(bool p_change_tab = true);
  530. void _remove_scene(int index, bool p_change_tab = true);
  531. bool _find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  532. bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  533. void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  534. void _mark_unsaved_scenes();
  535. bool _is_scene_unsaved(int p_idx);
  536. void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
  537. void _save_scene_with_preview(String p_file, int p_idx = -1);
  538. void _close_save_scene_progress();
  539. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  540. void _proceed_closing_scene_tabs();
  541. void _proceed_save_asing_scene_tabs();
  542. bool _is_closing_editor() const;
  543. void _restart_editor(bool p_goto_project_manager = false);
  544. Dictionary _get_main_scene_state();
  545. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  546. void _save_editor_layout();
  547. void _load_editor_layout();
  548. void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
  549. void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
  550. void _save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  551. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
  552. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
  553. void _update_layouts_menu();
  554. void _layout_menu_option(int p_id);
  555. void _update_addon_config();
  556. void _toggle_distraction_free_mode();
  557. void _inherit_imported(const String &p_action);
  558. void _open_imported();
  559. void _update_update_spinner();
  560. void _resources_changed(const Vector<String> &p_resources);
  561. void _scan_external_changes();
  562. void _reload_modified_scenes();
  563. void _reload_project_settings();
  564. void _resave_externally_modified_scenes(String p_str);
  565. void _feature_profile_changed();
  566. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  567. Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback = "Object", bool p_fallback_script_to_theme = false);
  568. Ref<Texture2D> _get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
  569. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  570. void _immediate_dialog_confirmed();
  571. void _begin_first_scan();
  572. void _notify_nodes_scene_reimported(Node *p_node, Array p_reimported_nodes);
  573. void _remove_all_not_owned_children(Node *p_node, Node *p_owner);
  574. void _progress_dialog_visibility_changed();
  575. void _load_error_dialog_visibility_changed();
  576. void _execute_upgrades();
  577. bool _is_project_data_missing();
  578. void _update_main_menu_type();
  579. void _add_to_main_menu(const String &p_name, PopupMenu *p_menu);
  580. protected:
  581. friend class FileSystemDock;
  582. static void _bind_methods();
  583. void _notification(int p_what);
  584. public:
  585. // Public for use with callable_mp.
  586. void init_plugins();
  587. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  588. bool call_build();
  589. // This is a very naive estimation, but we need something now. Will be reworked later.
  590. bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
  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 EditorTitleBar *get_title_bar() { return singleton->title_bar; }
  596. static VSplitContainer *get_top_split() { return singleton->top_split; }
  597. static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
  598. static EditorMainScreen *get_editor_main_screen() { return singleton->editor_main_screen; }
  599. static String adjust_scene_name_casing(const String &p_root_name);
  600. static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
  601. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  602. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  603. static void add_io_error(const String &p_error);
  604. static void add_io_warning(const String &p_warning);
  605. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  606. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  607. static void progress_end_task(const String &p_task);
  608. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  609. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  610. static void progress_end_task_bg(const String &p_task);
  611. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  612. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  613. static void add_extension_editor_plugin(const StringName &p_class_name);
  614. static void remove_extension_editor_plugin(const StringName &p_class_name);
  615. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  616. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  617. static void add_build_callback(EditorBuildCallback p_callback);
  618. static bool immediate_confirmation_dialog(const String &p_text, const String &p_ok_text = TTR("Ok"), const String &p_cancel_text = TTR("Cancel"), uint32_t p_wrap_width = 0);
  619. static void cleanup();
  620. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  621. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  622. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  623. EditorSelection *get_editor_selection() { return editor_selection; }
  624. EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
  625. ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
  626. void trigger_menu_option(int p_option, bool p_confirmed);
  627. bool has_previous_closed_scenes() const;
  628. void new_inherited_scene() { _menu_option_confirm(SCENE_NEW_INHERITED_SCENE, false); }
  629. void update_distraction_free_mode();
  630. void set_distraction_free_mode(bool p_enter);
  631. bool is_distraction_free_mode_enabled() const;
  632. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  633. bool is_addon_plugin_enabled(const String &p_addon) const;
  634. void edit_node(Node *p_node);
  635. void edit_resource(const Ref<Resource> &p_resource);
  636. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  637. void save_resource(const Ref<Resource> &p_resource);
  638. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  639. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  640. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  641. void push_item_no_inspector(Object *p_object);
  642. void edit_previous_item();
  643. void edit_item(Object *p_object, Object *p_editing_owner);
  644. void push_node_item(Node *p_node);
  645. void hide_unused_editors(const Object *p_editing_owner = nullptr);
  646. void replace_resources_in_object(
  647. Object *p_object,
  648. const Vector<Ref<Resource>> &p_source_resources,
  649. const Vector<Ref<Resource>> &p_target_resource);
  650. void replace_resources_in_scenes(
  651. const Vector<Ref<Resource>> &p_source_resources,
  652. const Vector<Ref<Resource>> &p_target_resource);
  653. void edit_foreign_resource(Ref<Resource> p_resource);
  654. bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
  655. String get_multiwindow_support_tooltip_text() const;
  656. bool is_changing_scene() const;
  657. SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
  658. void set_edited_scene(Node *p_scene);
  659. void set_edited_scene_root(Node *p_scene, bool p_auto_add);
  660. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  661. String get_preview_locale() const;
  662. void set_preview_locale(const String &p_locale);
  663. void fix_dependencies(const String &p_for_file);
  664. int new_scene();
  665. Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_force_open_imported = false, bool p_silent_change_tab = false);
  666. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  667. Error load_scene_or_resource(const String &p_file, bool p_ignore_broken_deps = false, bool p_change_scene_tab_if_already_open = true);
  668. HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
  669. HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
  670. void set_unfocused_low_processor_usage_mode_enabled(bool p_enabled);
  671. struct AdditiveNodeEntry {
  672. Node *node = nullptr;
  673. NodePath parent;
  674. Node *owner = nullptr;
  675. int index = 0;
  676. // Used if the original parent node is lost
  677. Transform2D transform_2d;
  678. Transform3D transform_3d;
  679. };
  680. struct ConnectionWithNodePath {
  681. Connection connection;
  682. NodePath node_path;
  683. };
  684. struct ModificationNodeEntry {
  685. HashMap<StringName, Variant> property_table;
  686. List<ConnectionWithNodePath> connections_to;
  687. List<Connection> connections_from;
  688. List<Node::GroupInfo> groups;
  689. };
  690. struct InstanceModificationsEntry {
  691. Node *original_node;
  692. String instance_path;
  693. List<Node *> instance_list;
  694. HashMap<NodePath, ModificationNodeEntry> modifications;
  695. List<AdditiveNodeEntry> addition_list;
  696. };
  697. struct SceneModificationsEntry {
  698. List<InstanceModificationsEntry> instance_list;
  699. HashMap<NodePath, ModificationNodeEntry> other_instances_modifications;
  700. };
  701. struct SceneEditorDataEntry {
  702. bool is_editable = false;
  703. bool is_display_folded = false;
  704. };
  705. HashMap<int, SceneModificationsEntry> scenes_modification_table;
  706. List<String> scenes_reimported;
  707. List<String> resources_reimported;
  708. void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
  709. void get_scene_editor_data_for_node(Node *p_root, Node *p_node, HashMap<NodePath, SceneEditorDataEntry> &p_table);
  710. void get_preload_scene_modification_table(
  711. Node *p_edited_scene,
  712. Node *p_reimported_root,
  713. Node *p_node, InstanceModificationsEntry &p_instance_modifications);
  714. void get_preload_modifications_reference_to_nodes(
  715. Node *p_root,
  716. Node *p_node,
  717. HashSet<Node *> &p_excluded_nodes,
  718. List<Node *> &p_instance_list_with_children,
  719. HashMap<NodePath, ModificationNodeEntry> &p_modification_table);
  720. void get_children_nodes(Node *p_node, List<Node *> &p_nodes);
  721. bool is_additional_node_in_scene(Node *p_edited_scene, Node *p_reimported_root, Node *p_node);
  722. void replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node);
  723. bool is_scene_open(const String &p_path);
  724. bool is_multi_window_enabled() const;
  725. void setup_color_picker(ColorPicker *p_picker);
  726. void request_instantiate_scene(const String &p_path);
  727. void request_instantiate_scenes(const Vector<String> &p_files);
  728. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  729. void notify_all_debug_sessions_exited();
  730. OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
  731. void stop_child_process(OS::ProcessID p_pid);
  732. Ref<Theme> get_editor_theme() const { return theme; }
  733. void update_preview_themes(int p_mode);
  734. Ref<Script> get_object_custom_type_base(const Object *p_object) const;
  735. StringName get_object_custom_type_name(const Object *p_object) const;
  736. Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
  737. Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
  738. bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
  739. void show_accept(const String &p_text, const String &p_title);
  740. void show_save_accept(const String &p_text, const String &p_title);
  741. void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
  742. void _copy_warning(const String &p_str);
  743. Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template, bool p_patch, const Vector<String> &p_patches);
  744. bool is_project_exporting() const;
  745. Control *get_gui_base() { return gui_base; }
  746. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  747. if (p_with_preview) {
  748. _save_scene_with_preview(p_file);
  749. } else {
  750. _save_scene(p_file);
  751. }
  752. }
  753. bool close_scene();
  754. bool is_scene_in_use(const String &p_path);
  755. void save_editor_layout_delayed();
  756. void save_default_environment();
  757. void open_export_template_manager();
  758. void reload_scene(const String &p_path);
  759. void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, HashSet<Node *> &p_instance_list);
  760. void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
  761. void reload_instances_with_path_in_edited_scenes();
  762. bool is_exiting() const { return exiting; }
  763. Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
  764. Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  765. EditorQuickOpenDialog *get_quick_open_dialog() { return quick_open_dialog; }
  766. void add_tool_menu_item(const String &p_name, const Callable &p_callback);
  767. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  768. void remove_tool_menu_item(const String &p_name);
  769. PopupMenu *get_export_as_menu();
  770. void save_all_scenes();
  771. void save_scene_if_open(const String &p_scene_path);
  772. void save_scene_list(const HashSet<String> &p_scene_paths);
  773. void save_before_run();
  774. void try_autosave();
  775. void restart_editor(bool p_goto_project_manager = false);
  776. void unload_editor_addons();
  777. void open_setting_override(const String &p_property);
  778. void notify_settings_overrides_changed();
  779. void dim_editor(bool p_dimming);
  780. bool is_editor_dimmed() const;
  781. void edit_current() { _edit_current(); }
  782. bool has_scenes_in_session();
  783. void undo();
  784. void redo();
  785. 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, String *r_output = nullptr);
  786. EditorNode();
  787. ~EditorNode();
  788. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  789. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  790. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_resource(const Ref<Resource> &p_for_resource);
  791. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
  792. bool ensure_main_scene(bool p_from_native);
  793. bool validate_custom_directory();
  794. void run_editor_script(const Ref<Script> &p_script);
  795. };
  796. class EditorPluginList : public Object {
  797. private:
  798. Vector<EditorPlugin *> plugins_list;
  799. public:
  800. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  801. plugins_list = p_plugins_list;
  802. }
  803. Vector<EditorPlugin *> &get_plugins_list() {
  804. return plugins_list;
  805. }
  806. void make_visible(bool p_visible);
  807. void edit(Object *p_object);
  808. bool forward_gui_input(const Ref<InputEvent> &p_event);
  809. void forward_canvas_draw_over_viewport(Control *p_overlay);
  810. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  811. EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  812. void forward_3d_draw_over_viewport(Control *p_overlay);
  813. void forward_3d_force_draw_over_viewport(Control *p_overlay);
  814. void add_plugin(EditorPlugin *p_plugin);
  815. void remove_plugin(EditorPlugin *p_plugin);
  816. void clear();
  817. bool is_empty();
  818. };
  819. struct EditorProgressBG {
  820. String task;
  821. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  822. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  823. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  824. task = p_task;
  825. }
  826. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  827. };