editor_node.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050
  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/editor_folding.h"
  35. #include "editor/plugins/editor_plugin.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, bool show_progress = true);
  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 _close_save_scene_progress();
  538. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  539. void _proceed_closing_scene_tabs();
  540. void _proceed_save_asing_scene_tabs();
  541. bool _is_closing_editor() const;
  542. void _restart_editor(bool p_goto_project_manager = false);
  543. Dictionary _get_main_scene_state();
  544. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  545. void _save_editor_layout();
  546. void _load_editor_layout();
  547. void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
  548. void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
  549. void _save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  550. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
  551. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
  552. void _update_layouts_menu();
  553. void _layout_menu_option(int p_id);
  554. void _update_addon_config();
  555. void _toggle_distraction_free_mode();
  556. void _inherit_imported(const String &p_action);
  557. void _open_imported();
  558. void _update_update_spinner();
  559. void _resources_changed(const Vector<String> &p_resources);
  560. void _scan_external_changes();
  561. void _reload_modified_scenes();
  562. void _reload_project_settings();
  563. void _resave_externally_modified_scenes(String p_str);
  564. void _feature_profile_changed();
  565. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  566. 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);
  567. Ref<Texture2D> _get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
  568. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  569. void _immediate_dialog_confirmed();
  570. void _begin_first_scan();
  571. void _notify_nodes_scene_reimported(Node *p_node, Array p_reimported_nodes);
  572. void _remove_all_not_owned_children(Node *p_node, Node *p_owner);
  573. void _progress_dialog_visibility_changed();
  574. void _load_error_dialog_visibility_changed();
  575. void _execute_upgrades();
  576. bool _is_project_data_missing();
  577. void _update_main_menu_type();
  578. void _add_to_main_menu(const String &p_name, PopupMenu *p_menu);
  579. protected:
  580. friend class FileSystemDock;
  581. static void _bind_methods();
  582. void _notification(int p_what);
  583. public:
  584. // Public for use with callable_mp.
  585. void init_plugins();
  586. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  587. bool call_build();
  588. // This is a very naive estimation, but we need something now. Will be reworked later.
  589. bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
  590. static EditorNode *get_singleton() { return singleton; }
  591. static EditorLog *get_log() { return singleton->log; }
  592. static EditorData &get_editor_data() { return singleton->editor_data; }
  593. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  594. static EditorTitleBar *get_title_bar() { return singleton->title_bar; }
  595. static VSplitContainer *get_top_split() { return singleton->top_split; }
  596. static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
  597. static EditorMainScreen *get_editor_main_screen() { return singleton->editor_main_screen; }
  598. static String adjust_scene_name_casing(const String &p_root_name);
  599. static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
  600. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  601. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  602. static void add_io_error(const String &p_error);
  603. static void add_io_warning(const String &p_warning);
  604. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  605. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  606. static void progress_end_task(const String &p_task);
  607. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  608. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  609. static void progress_end_task_bg(const String &p_task);
  610. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  611. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  612. static void add_extension_editor_plugin(const StringName &p_class_name);
  613. static void remove_extension_editor_plugin(const StringName &p_class_name);
  614. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  615. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  616. static void add_build_callback(EditorBuildCallback p_callback);
  617. 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);
  618. static void cleanup();
  619. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  620. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  621. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  622. EditorSelection *get_editor_selection() { return editor_selection; }
  623. EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
  624. ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
  625. void trigger_menu_option(int p_option, bool p_confirmed);
  626. bool has_previous_closed_scenes() const;
  627. void new_inherited_scene() { _menu_option_confirm(SCENE_NEW_INHERITED_SCENE, false); }
  628. void update_distraction_free_mode();
  629. void set_distraction_free_mode(bool p_enter);
  630. bool is_distraction_free_mode_enabled() const;
  631. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  632. bool is_addon_plugin_enabled(const String &p_addon) const;
  633. void edit_node(Node *p_node);
  634. void edit_resource(const Ref<Resource> &p_resource);
  635. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  636. void save_resource(const Ref<Resource> &p_resource);
  637. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  638. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  639. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  640. void push_item_no_inspector(Object *p_object);
  641. void edit_previous_item();
  642. void edit_item(Object *p_object, Object *p_editing_owner);
  643. void push_node_item(Node *p_node);
  644. void hide_unused_editors(const Object *p_editing_owner = nullptr);
  645. void replace_resources_in_object(
  646. Object *p_object,
  647. const Vector<Ref<Resource>> &p_source_resources,
  648. const Vector<Ref<Resource>> &p_target_resource);
  649. void replace_resources_in_scenes(
  650. const Vector<Ref<Resource>> &p_source_resources,
  651. const Vector<Ref<Resource>> &p_target_resource);
  652. void edit_foreign_resource(Ref<Resource> p_resource);
  653. bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
  654. String get_multiwindow_support_tooltip_text() const;
  655. bool is_changing_scene() const;
  656. SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
  657. void set_edited_scene(Node *p_scene);
  658. void set_edited_scene_root(Node *p_scene, bool p_auto_add);
  659. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  660. String get_preview_locale() const;
  661. void set_preview_locale(const String &p_locale);
  662. void fix_dependencies(const String &p_for_file);
  663. int new_scene();
  664. 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);
  665. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  666. Error load_scene_or_resource(const String &p_file, bool p_ignore_broken_deps = false, bool p_change_scene_tab_if_already_open = true);
  667. HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
  668. HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
  669. void set_unfocused_low_processor_usage_mode_enabled(bool p_enabled);
  670. struct AdditiveNodeEntry {
  671. Node *node = nullptr;
  672. NodePath parent;
  673. Node *owner = nullptr;
  674. int index = 0;
  675. // Used if the original parent node is lost
  676. Transform2D transform_2d;
  677. Transform3D transform_3d;
  678. };
  679. struct ConnectionWithNodePath {
  680. Connection connection;
  681. NodePath node_path;
  682. };
  683. struct ModificationNodeEntry {
  684. HashMap<StringName, Variant> property_table;
  685. List<ConnectionWithNodePath> connections_to;
  686. List<Connection> connections_from;
  687. List<Node::GroupInfo> groups;
  688. };
  689. struct InstanceModificationsEntry {
  690. Node *original_node;
  691. String instance_path;
  692. List<Node *> instance_list;
  693. HashMap<NodePath, ModificationNodeEntry> modifications;
  694. List<AdditiveNodeEntry> addition_list;
  695. };
  696. struct SceneModificationsEntry {
  697. List<InstanceModificationsEntry> instance_list;
  698. HashMap<NodePath, ModificationNodeEntry> other_instances_modifications;
  699. };
  700. struct SceneEditorDataEntry {
  701. bool is_editable = false;
  702. bool is_display_folded = false;
  703. };
  704. HashMap<int, SceneModificationsEntry> scenes_modification_table;
  705. List<String> scenes_reimported;
  706. List<String> resources_reimported;
  707. void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
  708. void get_scene_editor_data_for_node(Node *p_root, Node *p_node, HashMap<NodePath, SceneEditorDataEntry> &p_table);
  709. void get_preload_scene_modification_table(
  710. Node *p_edited_scene,
  711. Node *p_reimported_root,
  712. Node *p_node, InstanceModificationsEntry &p_instance_modifications);
  713. void get_preload_modifications_reference_to_nodes(
  714. Node *p_root,
  715. Node *p_node,
  716. HashSet<Node *> &p_excluded_nodes,
  717. List<Node *> &p_instance_list_with_children,
  718. HashMap<NodePath, ModificationNodeEntry> &p_modification_table);
  719. void get_children_nodes(Node *p_node, List<Node *> &p_nodes);
  720. bool is_additional_node_in_scene(Node *p_edited_scene, Node *p_reimported_root, Node *p_node);
  721. void replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node);
  722. bool is_scene_open(const String &p_path);
  723. bool is_multi_window_enabled() const;
  724. void setup_color_picker(ColorPicker *p_picker);
  725. void request_instantiate_scene(const String &p_path);
  726. void request_instantiate_scenes(const Vector<String> &p_files);
  727. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  728. void notify_all_debug_sessions_exited();
  729. OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
  730. void stop_child_process(OS::ProcessID p_pid);
  731. Ref<Theme> get_editor_theme() const { return theme; }
  732. void update_preview_themes(int p_mode);
  733. Ref<Script> get_object_custom_type_base(const Object *p_object) const;
  734. StringName get_object_custom_type_name(const Object *p_object) const;
  735. Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
  736. Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
  737. bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
  738. void show_accept(const String &p_text, const String &p_title);
  739. void show_save_accept(const String &p_text, const String &p_title);
  740. void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
  741. void _copy_warning(const String &p_str);
  742. 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);
  743. bool is_project_exporting() const;
  744. Control *get_gui_base() { return gui_base; }
  745. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  746. // p_with_preview has no effect, now generates preview at EditorPackedScenePreviewPlugin
  747. _save_scene(p_file);
  748. }
  749. bool close_scene();
  750. bool is_scene_in_use(const String &p_path);
  751. void save_editor_layout_delayed();
  752. void save_default_environment();
  753. void open_export_template_manager();
  754. void reload_scene(const String &p_path);
  755. void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, HashSet<Node *> &p_instance_list);
  756. void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
  757. void reload_instances_with_path_in_edited_scenes();
  758. bool is_exiting() const { return exiting; }
  759. Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
  760. Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  761. EditorQuickOpenDialog *get_quick_open_dialog() { return quick_open_dialog; }
  762. void add_tool_menu_item(const String &p_name, const Callable &p_callback);
  763. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  764. void remove_tool_menu_item(const String &p_name);
  765. PopupMenu *get_export_as_menu();
  766. void save_all_scenes();
  767. void save_scene_if_open(const String &p_scene_path);
  768. void save_scene_list(const HashSet<String> &p_scene_paths);
  769. void save_before_run();
  770. void try_autosave();
  771. void restart_editor(bool p_goto_project_manager = false);
  772. void unload_editor_addons();
  773. void open_setting_override(const String &p_property);
  774. void notify_settings_overrides_changed();
  775. void dim_editor(bool p_dimming);
  776. bool is_editor_dimmed() const;
  777. void edit_current() { _edit_current(); }
  778. bool has_scenes_in_session();
  779. void undo();
  780. void redo();
  781. 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);
  782. EditorNode();
  783. ~EditorNode();
  784. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  785. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  786. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_resource(const Ref<Resource> &p_for_resource);
  787. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
  788. bool ensure_main_scene(bool p_from_native);
  789. bool validate_custom_directory();
  790. void run_editor_script(const Ref<Script> &p_script);
  791. };
  792. class EditorPluginList : public Object {
  793. private:
  794. Vector<EditorPlugin *> plugins_list;
  795. public:
  796. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  797. plugins_list = p_plugins_list;
  798. }
  799. Vector<EditorPlugin *> &get_plugins_list() {
  800. return plugins_list;
  801. }
  802. void make_visible(bool p_visible);
  803. void edit(Object *p_object);
  804. bool forward_gui_input(const Ref<InputEvent> &p_event);
  805. void forward_canvas_draw_over_viewport(Control *p_overlay);
  806. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  807. EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  808. void forward_3d_draw_over_viewport(Control *p_overlay);
  809. void forward_3d_force_draw_over_viewport(Control *p_overlay);
  810. void add_plugin(EditorPlugin *p_plugin);
  811. void remove_plugin(EditorPlugin *p_plugin);
  812. void clear();
  813. bool is_empty();
  814. };
  815. struct EditorProgressBG {
  816. String task;
  817. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  818. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  819. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  820. task = p_task;
  821. }
  822. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  823. };