editor_node.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961
  1. /**************************************************************************/
  2. /* editor_node.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef EDITOR_NODE_H
  31. #define EDITOR_NODE_H
  32. #include "core/object/script_language.h"
  33. #include "core/templates/safe_refcount.h"
  34. #include "editor/editor_data.h"
  35. #include "editor/editor_folding.h"
  36. #include "editor/plugins/editor_plugin.h"
  37. typedef void (*EditorNodeInitCallback)();
  38. typedef void (*EditorPluginInitializeCallback)();
  39. typedef bool (*EditorBuildCallback)();
  40. class AcceptDialog;
  41. class CenterContainer;
  42. class CheckBox;
  43. class ColorPicker;
  44. class ConfirmationDialog;
  45. class Control;
  46. class FileDialog;
  47. class HBoxContainer;
  48. class HSplitContainer;
  49. class LinkButton;
  50. class MenuBar;
  51. class MenuButton;
  52. class Node2D;
  53. class OptionButton;
  54. class Panel;
  55. class PanelContainer;
  56. class PopupPanel;
  57. class RichTextLabel;
  58. class SubViewport;
  59. class TabBar;
  60. class TabContainer;
  61. class TextureRect;
  62. class TextureProgressBar;
  63. class Tree;
  64. class VBoxContainer;
  65. class VSplitContainer;
  66. class Window;
  67. class AudioStreamImportSettingsDialog;
  68. class AudioStreamPreviewGenerator;
  69. class BackgroundProgress;
  70. class DependencyEditor;
  71. class DependencyErrorDialog;
  72. class DockSplitContainer;
  73. class DynamicFontImportSettingsDialog;
  74. class EditorAbout;
  75. class EditorBuildProfileManager;
  76. class EditorBottomPanel;
  77. class EditorCommandPalette;
  78. class EditorDockManager;
  79. class EditorExport;
  80. class EditorExportPreset;
  81. class EditorExtensionManager;
  82. class EditorFeatureProfileManager;
  83. class EditorFileDialog;
  84. class EditorFolding;
  85. class EditorInspector;
  86. class EditorLayoutsDialog;
  87. class EditorLog;
  88. class EditorNativeShaderSourceVisualizer;
  89. class EditorPluginList;
  90. class EditorQuickOpen;
  91. class EditorPropertyResource;
  92. class EditorResourcePreview;
  93. class EditorResourceConversionPlugin;
  94. class EditorRunBar;
  95. class EditorRunNative;
  96. class EditorSceneTabs;
  97. class EditorSelectionHistory;
  98. class EditorSettingsDialog;
  99. class EditorTitleBar;
  100. class EditorToaster;
  101. class EditorUndoRedoManager;
  102. class ExportTemplateManager;
  103. class FBXImporterManager;
  104. class FileSystemDock;
  105. class HistoryDock;
  106. class ImportDock;
  107. class NodeDock;
  108. class OrphanResourcesDialog;
  109. class PluginConfigDialog;
  110. class ProgressDialog;
  111. class ProjectExportDialog;
  112. class ProjectSettingsEditor;
  113. class RunSettingsDialog;
  114. class SceneImportSettingsDialog;
  115. class ScriptCreateDialog;
  116. class SurfaceUpgradeTool;
  117. class SurfaceUpgradeDialog;
  118. class WindowWrapper;
  119. class EditorNode : public Node {
  120. GDCLASS(EditorNode, Node);
  121. public:
  122. enum EditorTable {
  123. EDITOR_2D = 0,
  124. EDITOR_3D,
  125. EDITOR_SCRIPT,
  126. EDITOR_ASSETLIB
  127. };
  128. enum SceneNameCasing {
  129. SCENE_NAME_CASING_AUTO,
  130. SCENE_NAME_CASING_PASCAL_CASE,
  131. SCENE_NAME_CASING_SNAKE_CASE,
  132. SCENE_NAME_CASING_KEBAB_CASE,
  133. };
  134. struct ExecuteThreadArgs {
  135. String path;
  136. List<String> args;
  137. String output;
  138. Thread execute_output_thread;
  139. Mutex execute_output_mutex;
  140. int exitcode = 0;
  141. SafeFlag done;
  142. };
  143. private:
  144. friend class EditorSceneTabs;
  145. friend class SurfaceUpgradeTool;
  146. enum MenuOptions {
  147. FILE_NEW_SCENE,
  148. FILE_NEW_INHERITED_SCENE,
  149. FILE_OPEN_SCENE,
  150. FILE_SAVE_SCENE,
  151. FILE_SAVE_SCENE_SILENTLY,
  152. FILE_SAVE_AS_SCENE,
  153. FILE_SAVE_ALL_SCENES,
  154. FILE_SAVE_AND_RUN,
  155. FILE_SAVE_AND_RUN_MAIN_SCENE,
  156. FILE_RUN_SCENE,
  157. FILE_SHOW_IN_FILESYSTEM,
  158. FILE_EXPORT_PROJECT,
  159. FILE_EXPORT_MESH_LIBRARY,
  160. FILE_INSTALL_ANDROID_SOURCE,
  161. FILE_EXPLORE_ANDROID_BUILD_TEMPLATES,
  162. FILE_SAVE_OPTIMIZED,
  163. FILE_OPEN_RECENT,
  164. FILE_OPEN_OLD_SCENE,
  165. FILE_QUICK_OPEN,
  166. FILE_QUICK_OPEN_SCENE,
  167. FILE_QUICK_OPEN_SCRIPT,
  168. FILE_OPEN_PREV,
  169. FILE_CLOSE,
  170. FILE_CLOSE_OTHERS,
  171. FILE_CLOSE_RIGHT,
  172. FILE_CLOSE_ALL,
  173. FILE_QUIT,
  174. FILE_EXTERNAL_OPEN_SCENE,
  175. EDIT_UNDO,
  176. EDIT_REDO,
  177. EDIT_RELOAD_SAVED_SCENE,
  178. TOOLS_ORPHAN_RESOURCES,
  179. TOOLS_BUILD_PROFILE_MANAGER,
  180. TOOLS_SURFACE_UPGRADE,
  181. TOOLS_CUSTOM,
  182. RESOURCE_SAVE,
  183. RESOURCE_SAVE_AS,
  184. RUN_SETTINGS,
  185. RUN_USER_DATA_FOLDER,
  186. RELOAD_CURRENT_PROJECT,
  187. RUN_PROJECT_MANAGER,
  188. VCS_MENU,
  189. RUN_VCS_METADATA,
  190. RUN_VCS_SETTINGS,
  191. SETTINGS_UPDATE_CONTINUOUSLY,
  192. SETTINGS_UPDATE_WHEN_CHANGED,
  193. SETTINGS_UPDATE_ALWAYS,
  194. SETTINGS_UPDATE_CHANGES,
  195. SETTINGS_UPDATE_SPINNER_HIDE,
  196. SETTINGS_PREFERENCES,
  197. SETTINGS_LAYOUT_SAVE,
  198. SETTINGS_LAYOUT_DELETE,
  199. SETTINGS_LAYOUT_DEFAULT,
  200. SETTINGS_EDITOR_DATA_FOLDER,
  201. SETTINGS_EDITOR_CONFIG_FOLDER,
  202. SETTINGS_MANAGE_EXPORT_TEMPLATES,
  203. SETTINGS_MANAGE_FBX_IMPORTER,
  204. SETTINGS_MANAGE_FEATURE_PROFILES,
  205. SETTINGS_INSTALL_ANDROID_BUILD_TEMPLATE,
  206. SETTINGS_PICK_MAIN_SCENE,
  207. SETTINGS_TOGGLE_FULLSCREEN,
  208. SETTINGS_HELP,
  209. SCENE_TAB_CLOSE,
  210. EDITOR_SCREENSHOT,
  211. EDITOR_OPEN_SCREENSHOT,
  212. HELP_SEARCH,
  213. HELP_COMMAND_PALETTE,
  214. HELP_DOCS,
  215. HELP_FORUM,
  216. HELP_REPORT_A_BUG,
  217. HELP_COPY_SYSTEM_INFO,
  218. HELP_SUGGEST_A_FEATURE,
  219. HELP_SEND_DOCS_FEEDBACK,
  220. HELP_COMMUNITY,
  221. HELP_ABOUT,
  222. HELP_SUPPORT_GODOT_DEVELOPMENT,
  223. SET_RENDERER_NAME_SAVE_AND_RESTART,
  224. IMPORT_PLUGIN_BASE = 100,
  225. TOOL_MENU_BASE = 1000
  226. };
  227. enum {
  228. MAX_INIT_CALLBACKS = 128,
  229. MAX_BUILD_CALLBACKS = 128
  230. };
  231. struct ExportDefer {
  232. String preset;
  233. String path;
  234. bool debug = false;
  235. bool pack_only = false;
  236. bool android_build_template = false;
  237. } export_defer;
  238. static EditorNode *singleton;
  239. EditorData editor_data;
  240. EditorFolding editor_folding;
  241. EditorSelectionHistory editor_history;
  242. EditorCommandPalette *command_palette = nullptr;
  243. EditorExport *editor_export = nullptr;
  244. EditorLog *log = nullptr;
  245. EditorNativeShaderSourceVisualizer *native_shader_source_visualizer = nullptr;
  246. EditorPlugin *editor_plugin_screen = nullptr;
  247. EditorPluginList *editor_plugins_force_input_forwarding = nullptr;
  248. EditorPluginList *editor_plugins_force_over = nullptr;
  249. EditorPluginList *editor_plugins_over = nullptr;
  250. EditorQuickOpen *quick_open = nullptr;
  251. EditorResourcePreview *resource_preview = nullptr;
  252. EditorSelection *editor_selection = nullptr;
  253. EditorSettingsDialog *editor_settings_dialog = nullptr;
  254. HistoryDock *history_dock = nullptr;
  255. ProjectExportDialog *project_export = nullptr;
  256. ProjectSettingsEditor *project_settings_editor = nullptr;
  257. FBXImporterManager *fbx_importer_manager = nullptr;
  258. Vector<EditorPlugin *> editor_plugins;
  259. bool _initializing_plugins = false;
  260. HashMap<String, EditorPlugin *> addon_name_to_plugin;
  261. LocalVector<String> pending_addons;
  262. HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
  263. bool is_main_screen_editing = false;
  264. PanelContainer *scene_root_parent = nullptr;
  265. Control *gui_base = nullptr;
  266. VBoxContainer *main_vbox = nullptr;
  267. OptionButton *renderer = nullptr;
  268. ConfirmationDialog *video_restart_dialog = nullptr;
  269. int renderer_current = 0;
  270. String renderer_request;
  271. // Split containers.
  272. DockSplitContainer *left_l_hsplit = nullptr;
  273. DockSplitContainer *left_l_vsplit = nullptr;
  274. DockSplitContainer *left_r_hsplit = nullptr;
  275. DockSplitContainer *left_r_vsplit = nullptr;
  276. DockSplitContainer *main_hsplit = nullptr;
  277. DockSplitContainer *right_hsplit = nullptr;
  278. DockSplitContainer *right_l_vsplit = nullptr;
  279. DockSplitContainer *right_r_vsplit = nullptr;
  280. DockSplitContainer *center_split = nullptr;
  281. // Main tabs.
  282. EditorSceneTabs *scene_tabs = nullptr;
  283. int tab_closing_idx = 0;
  284. List<String> tabs_to_close;
  285. int tab_closing_menu_option = -1;
  286. bool exiting = false;
  287. bool dimmed = false;
  288. DisplayServer::WindowMode prev_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
  289. int old_split_ofs = 0;
  290. VSplitContainer *top_split = nullptr;
  291. Control *vp_base = nullptr;
  292. Label *project_title = nullptr;
  293. Control *left_menu_spacer = nullptr;
  294. Control *right_menu_spacer = nullptr;
  295. EditorTitleBar *title_bar = nullptr;
  296. EditorRunBar *project_run_bar = nullptr;
  297. VBoxContainer *main_screen_vbox = nullptr;
  298. MenuBar *main_menu = nullptr;
  299. PopupMenu *apple_menu = nullptr;
  300. PopupMenu *file_menu = nullptr;
  301. PopupMenu *project_menu = nullptr;
  302. PopupMenu *debug_menu = nullptr;
  303. PopupMenu *settings_menu = nullptr;
  304. PopupMenu *help_menu = nullptr;
  305. PopupMenu *tool_menu = nullptr;
  306. PopupMenu *export_as_menu = nullptr;
  307. Button *export_button = nullptr;
  308. Button *search_button = nullptr;
  309. TextureProgressBar *audio_vu = nullptr;
  310. Timer *screenshot_timer = nullptr;
  311. uint64_t started_timestamp = 0;
  312. RichTextLabel *load_errors = nullptr;
  313. AcceptDialog *load_error_dialog = nullptr;
  314. RichTextLabel *execute_outputs = nullptr;
  315. AcceptDialog *execute_output_dialog = nullptr;
  316. Ref<Theme> theme;
  317. Timer *system_theme_timer = nullptr;
  318. bool follow_system_theme = false;
  319. bool use_system_accent_color = false;
  320. bool last_dark_mode_state = false;
  321. Color last_system_base_color = Color(0, 0, 0, 0);
  322. Color last_system_accent_color = Color(0, 0, 0, 0);
  323. PopupMenu *recent_scenes = nullptr;
  324. String _recent_scene;
  325. List<String> previous_scenes;
  326. String defer_load_scene;
  327. Node *_last_instantiated_scene = nullptr;
  328. ConfirmationDialog *confirmation = nullptr;
  329. ConfirmationDialog *save_confirmation = nullptr;
  330. ConfirmationDialog *import_confirmation = nullptr;
  331. ConfirmationDialog *pick_main_scene = nullptr;
  332. Button *select_current_scene_button = nullptr;
  333. AcceptDialog *accept = nullptr;
  334. AcceptDialog *save_accept = nullptr;
  335. EditorAbout *about = nullptr;
  336. AcceptDialog *warning = nullptr;
  337. EditorPlugin *plugin_to_save = nullptr;
  338. int overridden_default_layout = -1;
  339. Ref<ConfigFile> default_layout;
  340. PopupMenu *editor_layouts = nullptr;
  341. EditorLayoutsDialog *layout_dialog = nullptr;
  342. ConfirmationDialog *gradle_build_manage_templates = nullptr;
  343. ConfirmationDialog *install_android_build_template = nullptr;
  344. ConfirmationDialog *remove_android_build_template = nullptr;
  345. Label *install_android_build_template_message = nullptr;
  346. OptionButton *choose_android_export_profile = nullptr;
  347. Ref<EditorExportPreset> android_export_preset;
  348. PopupMenu *vcs_actions_menu = nullptr;
  349. EditorFileDialog *file = nullptr;
  350. ExportTemplateManager *export_template_manager = nullptr;
  351. EditorFeatureProfileManager *feature_profile_manager = nullptr;
  352. EditorBuildProfileManager *build_profile_manager = nullptr;
  353. EditorFileDialog *file_templates = nullptr;
  354. EditorFileDialog *file_export_lib = nullptr;
  355. EditorFileDialog *file_script = nullptr;
  356. EditorFileDialog *file_android_build_source = nullptr;
  357. String current_path;
  358. MenuButton *update_spinner = nullptr;
  359. HBoxContainer *main_editor_button_hb = nullptr;
  360. Vector<Button *> main_editor_buttons;
  361. Vector<EditorPlugin *> editor_table;
  362. AudioStreamPreviewGenerator *audio_preview_gen = nullptr;
  363. ProgressDialog *progress_dialog = nullptr;
  364. BackgroundProgress *progress_hb = nullptr;
  365. DependencyErrorDialog *dependency_error = nullptr;
  366. HashMap<String, HashSet<String>> dependency_errors;
  367. DependencyEditor *dependency_fixer = nullptr;
  368. OrphanResourcesDialog *orphan_resources = nullptr;
  369. ConfirmationDialog *open_imported = nullptr;
  370. Button *new_inherited_button = nullptr;
  371. String open_import_request;
  372. EditorDockManager *editor_dock_manager = nullptr;
  373. Timer *editor_layout_save_delay_timer = nullptr;
  374. Timer *scan_changes_timer = nullptr;
  375. Button *distraction_free = nullptr;
  376. EditorBottomPanel *bottom_panel = nullptr;
  377. Tree *disk_changed_list = nullptr;
  378. ConfirmationDialog *disk_changed = nullptr;
  379. bool scene_distraction_free = false;
  380. bool script_distraction_free = false;
  381. bool changing_scene = false;
  382. bool cmdline_export_mode = false;
  383. bool convert_old = false;
  384. bool immediate_dialog_confirmed = false;
  385. bool opening_prev = false;
  386. bool restoring_scenes = false;
  387. bool unsaved_cache = true;
  388. bool requested_first_scan = false;
  389. bool waiting_for_first_scan = true;
  390. int current_menu_option = 0;
  391. SubViewport *scene_root = nullptr; // Root of the scene being edited.
  392. Object *current = nullptr;
  393. Ref<Resource> saving_resource;
  394. HashSet<Ref<Resource>> saving_resources_in_path;
  395. uint64_t update_spinner_step_msec = 0;
  396. uint64_t update_spinner_step_frame = 0;
  397. int update_spinner_step = 0;
  398. String _tmp_import_path;
  399. String external_file;
  400. String open_navigate;
  401. String saving_scene;
  402. DynamicFontImportSettingsDialog *fontdata_import_settings = nullptr;
  403. SceneImportSettingsDialog *scene_import_settings = nullptr;
  404. AudioStreamImportSettingsDialog *audio_stream_import_settings = nullptr;
  405. String import_reload_fn;
  406. HashSet<String> textfile_extensions;
  407. HashSet<FileDialog *> file_dialogs;
  408. HashSet<EditorFileDialog *> editor_file_dialogs;
  409. Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
  410. PrintHandlerList print_handler;
  411. HashMap<String, Ref<Texture2D>> icon_type_cache;
  412. SurfaceUpgradeTool *surface_upgrade_tool = nullptr;
  413. SurfaceUpgradeDialog *surface_upgrade_dialog = nullptr;
  414. bool run_surface_upgrade_tool = false;
  415. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  416. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  417. static int build_callback_count;
  418. static int plugin_init_callback_count;
  419. static Vector<EditorNodeInitCallback> _init_callbacks;
  420. String _get_system_info() const;
  421. bool _should_display_update_spinner() const;
  422. static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
  423. DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
  424. if (!singleton->dependency_errors.has(p_path)) {
  425. singleton->dependency_errors[p_path] = HashSet<String>();
  426. }
  427. singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
  428. }
  429. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  430. static void _file_dialog_register(FileDialog *p_dialog);
  431. static void _file_dialog_unregister(FileDialog *p_dialog);
  432. static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
  433. static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
  434. static void _file_access_close_error_notify(const String &p_str);
  435. static void _file_access_close_error_notify_impl(const String &p_str);
  436. static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
  437. static void _print_handler_impl(const String &p_string, bool p_error, bool p_rich);
  438. static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
  439. static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
  440. void _update_theme(bool p_skip_creation = false);
  441. void _build_icon_type_cache();
  442. void _enable_pending_addons();
  443. void _dialog_action(String p_file);
  444. void _add_to_history(const Object *p_object, const String &p_property, bool p_inspector_only);
  445. void _edit_current(bool p_skip_foreign = false, bool p_skip_inspector_update = false);
  446. void _dialog_display_save_error(String p_file, Error p_error);
  447. void _dialog_display_load_error(String p_file, Error p_error);
  448. void _menu_option(int p_option);
  449. void _menu_confirm_current();
  450. void _menu_option_confirm(int p_option, bool p_confirmed);
  451. void _android_build_source_selected(const String &p_file);
  452. void _android_export_preset_selected(int p_index);
  453. void _request_screenshot();
  454. void _screenshot(bool p_use_utc = false);
  455. void _save_screenshot(NodePath p_path);
  456. void _check_system_theme_changed();
  457. void _tool_menu_option(int p_idx);
  458. void _export_as_menu_option(int p_idx);
  459. void _update_file_menu_opened();
  460. void _update_file_menu_closed();
  461. void _remove_plugin_from_enabled(const String &p_name);
  462. void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
  463. void _plugin_over_self_own(EditorPlugin *p_plugin);
  464. void _fs_changed();
  465. void _resources_reimported(const Vector<String> &p_resources);
  466. void _sources_changed(bool p_exist);
  467. void _node_renamed();
  468. void _editor_select_next();
  469. void _editor_select_prev();
  470. void _save_editor_states(const String &p_file, int p_idx = -1);
  471. void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
  472. void _update_title();
  473. void _version_control_menu_option(int p_idx);
  474. void _close_messages();
  475. void _show_messages();
  476. void _vp_resized();
  477. void _titlebar_resized();
  478. void _update_undo_redo_allowed();
  479. int _save_external_resources();
  480. void _set_current_scene(int p_idx);
  481. void _set_current_scene_nocheck(int p_idx);
  482. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  483. void _save_scene(String p_file, int idx = -1);
  484. void _save_all_scenes();
  485. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  486. void _discard_changes(const String &p_str = String());
  487. void _scene_tab_closed(int p_tab);
  488. void _cancel_close_scene_tab();
  489. void _inherit_request(String p_file);
  490. void _instantiate_request(const Vector<String> &p_files);
  491. void _quick_opened();
  492. void _open_command_palette();
  493. void _project_run_started();
  494. void _project_run_stopped();
  495. void _add_to_recent_scenes(const String &p_scene);
  496. void _update_recent_scenes();
  497. void _open_recent_scene(int p_idx);
  498. void _dropped_files(const Vector<String> &p_files);
  499. void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
  500. void _update_vsync_mode();
  501. void _update_from_settings();
  502. void _gdextensions_reloaded();
  503. void _renderer_selected(int);
  504. void _update_renderer_color();
  505. void _add_renderer_entry(const String &p_renderer_name, bool p_mark_overridden);
  506. void _exit_editor(int p_exit_code);
  507. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  508. bool has_main_screen() const { return true; }
  509. void _remove_edited_scene(bool p_change_tab = true);
  510. void _remove_scene(int index, bool p_change_tab = true);
  511. bool _find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  512. bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  513. void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  514. void _mark_unsaved_scenes();
  515. void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
  516. void _save_scene_with_preview(String p_file, int p_idx = -1);
  517. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  518. void _proceed_closing_scene_tabs();
  519. bool _is_closing_editor() const;
  520. Dictionary _get_main_scene_state();
  521. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  522. int _get_current_main_editor();
  523. void _save_editor_layout();
  524. void _load_editor_layout();
  525. void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
  526. void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
  527. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
  528. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
  529. void _update_layouts_menu();
  530. void _layout_menu_option(int p_id);
  531. void _update_addon_config();
  532. void _toggle_distraction_free_mode();
  533. void _inherit_imported(const String &p_action);
  534. void _open_imported();
  535. void _update_update_spinner();
  536. void _resources_changed(const Vector<String> &p_resources);
  537. void _scan_external_changes();
  538. void _reload_modified_scenes();
  539. void _reload_project_settings();
  540. void _resave_scenes(String p_str);
  541. void _feature_profile_changed();
  542. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  543. Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const Ref<Script> &p_script, const String &p_fallback = "Object", bool p_fallback_script_to_theme = false);
  544. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  545. void _immediate_dialog_confirmed();
  546. void _select_default_main_screen_plugin();
  547. void _begin_first_scan();
  548. void _notify_scene_updated(Node *p_node);
  549. protected:
  550. friend class FileSystemDock;
  551. static void _bind_methods();
  552. void _notification(int p_what);
  553. public:
  554. // Public for use with callable_mp.
  555. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  556. void editor_select(int p_which);
  557. void set_visible_editor(EditorTable p_table) { editor_select(p_table); }
  558. bool call_build();
  559. // This is a very naive estimation, but we need something now. Will be reworked later.
  560. bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
  561. static EditorNode *get_singleton() { return singleton; }
  562. static EditorLog *get_log() { return singleton->log; }
  563. static EditorData &get_editor_data() { return singleton->editor_data; }
  564. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  565. static EditorTitleBar *get_title_bar() { return singleton->title_bar; }
  566. static VSplitContainer *get_top_split() { return singleton->top_split; }
  567. static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
  568. static String adjust_scene_name_casing(const String &p_root_name);
  569. static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
  570. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  571. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  572. static void add_io_error(const String &p_error);
  573. static void add_io_warning(const String &p_warning);
  574. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  575. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  576. static void progress_end_task(const String &p_task);
  577. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  578. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  579. static void progress_end_task_bg(const String &p_task);
  580. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  581. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  582. static void add_extension_editor_plugin(const StringName &p_class_name);
  583. static void remove_extension_editor_plugin(const StringName &p_class_name);
  584. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  585. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  586. static void add_build_callback(EditorBuildCallback p_callback);
  587. 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);
  588. static void cleanup();
  589. EditorPlugin *get_editor_plugin_screen() { return editor_plugin_screen; }
  590. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  591. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  592. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  593. EditorSelection *get_editor_selection() { return editor_selection; }
  594. EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
  595. ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
  596. void trigger_menu_option(int p_option, bool p_confirmed);
  597. bool has_previous_scenes() const;
  598. void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); }
  599. void set_distraction_free_mode(bool p_enter);
  600. bool is_distraction_free_mode_enabled() const;
  601. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  602. bool is_addon_plugin_enabled(const String &p_addon) const;
  603. void edit_node(Node *p_node);
  604. void edit_resource(const Ref<Resource> &p_resource);
  605. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  606. void save_resource(const Ref<Resource> &p_resource);
  607. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  608. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  609. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  610. void push_item_no_inspector(Object *p_object);
  611. void edit_item(Object *p_object, Object *p_editing_owner);
  612. void push_node_item(Node *p_node);
  613. void hide_unused_editors(const Object *p_editing_owner = nullptr);
  614. void select_editor_by_name(const String &p_name);
  615. void open_request(const String &p_path);
  616. void edit_foreign_resource(Ref<Resource> p_resource);
  617. bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
  618. String get_multiwindow_support_tooltip_text() const;
  619. bool is_changing_scene() const;
  620. VBoxContainer *get_main_screen_control();
  621. SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
  622. void set_edited_scene(Node *p_scene);
  623. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  624. void fix_dependencies(const String &p_for_file);
  625. int new_scene();
  626. 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);
  627. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  628. HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node);
  629. struct AdditiveNodeEntry {
  630. Node *node = nullptr;
  631. NodePath parent = NodePath();
  632. Node *owner = nullptr;
  633. int index = 0;
  634. // Used if the original parent node is lost
  635. Transform2D transform_2d;
  636. Transform3D transform_3d;
  637. // Used to keep track of the ownership of all ancestor nodes so they can be restored later.
  638. HashMap<Node *, Node *> ownership_table;
  639. };
  640. struct ConnectionWithNodePath {
  641. Connection connection;
  642. NodePath node_path;
  643. };
  644. struct ModificationNodeEntry {
  645. HashMap<StringName, Variant> property_table;
  646. List<ConnectionWithNodePath> connections_to;
  647. List<Connection> connections_from;
  648. List<Node::GroupInfo> groups;
  649. };
  650. void update_ownership_table_for_addition_node_ancestors(Node *p_current_node, HashMap<Node *, Node *> &p_ownership_table);
  651. void update_diff_data_for_node(
  652. Node *p_edited_scene,
  653. Node *p_root,
  654. Node *p_node,
  655. HashMap<NodePath, ModificationNodeEntry> &p_modification_table,
  656. List<AdditiveNodeEntry> &p_addition_list);
  657. bool is_scene_open(const String &p_path);
  658. bool is_multi_window_enabled() const;
  659. void setup_color_picker(ColorPicker *p_picker);
  660. void request_instantiate_scene(const String &p_path);
  661. void request_instantiate_scenes(const Vector<String> &p_files);
  662. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  663. void notify_all_debug_sessions_exited();
  664. OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
  665. void stop_child_process(OS::ProcessID p_pid);
  666. Ref<Theme> get_editor_theme() const { return theme; }
  667. void update_preview_themes(int p_mode);
  668. Ref<Script> get_object_custom_type_base(const Object *p_object) const;
  669. StringName get_object_custom_type_name(const Object *p_object) const;
  670. Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
  671. Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
  672. bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
  673. void show_accept(const String &p_text, const String &p_title);
  674. void show_save_accept(const String &p_text, const String &p_title);
  675. void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
  676. void _copy_warning(const String &p_str);
  677. Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template);
  678. bool is_project_exporting() const;
  679. Control *get_gui_base() { return gui_base; }
  680. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  681. if (p_with_preview) {
  682. _save_scene_with_preview(p_file);
  683. } else {
  684. _save_scene(p_file);
  685. }
  686. }
  687. bool is_scene_in_use(const String &p_path);
  688. void save_editor_layout_delayed();
  689. void save_default_environment();
  690. void open_export_template_manager();
  691. void reload_scene(const String &p_path);
  692. void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, List<Node *> &p_instance_list);
  693. void reload_instances_with_path_in_edited_scenes(const String &p_path);
  694. bool is_exiting() const { return exiting; }
  695. Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
  696. Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  697. void add_tool_menu_item(const String &p_name, const Callable &p_callback);
  698. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  699. void remove_tool_menu_item(const String &p_name);
  700. PopupMenu *get_export_as_menu();
  701. void save_all_scenes();
  702. void save_scene_if_open(const String &p_scene_path);
  703. void save_scene_list(const HashSet<String> &p_scene_paths);
  704. void save_before_run();
  705. void try_autosave();
  706. void restart_editor();
  707. void dim_editor(bool p_dimming);
  708. bool is_editor_dimmed() const;
  709. void edit_current() { _edit_current(); };
  710. bool has_scenes_in_session();
  711. 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);
  712. EditorNode();
  713. ~EditorNode();
  714. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  715. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  716. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin(const Ref<Resource> &p_for_resource);
  717. bool ensure_main_scene(bool p_from_native);
  718. };
  719. struct EditorProgress {
  720. String task;
  721. 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); }
  722. EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false) {
  723. EditorNode::progress_add_task(p_task, p_label, p_amount, p_can_cancel);
  724. task = p_task;
  725. }
  726. ~EditorProgress() { EditorNode::progress_end_task(task); }
  727. };
  728. class EditorPluginList : public Object {
  729. private:
  730. Vector<EditorPlugin *> plugins_list;
  731. public:
  732. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  733. plugins_list = p_plugins_list;
  734. }
  735. Vector<EditorPlugin *> &get_plugins_list() {
  736. return plugins_list;
  737. }
  738. void make_visible(bool p_visible);
  739. void edit(Object *p_object);
  740. bool forward_gui_input(const Ref<InputEvent> &p_event);
  741. void forward_canvas_draw_over_viewport(Control *p_overlay);
  742. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  743. EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  744. void forward_3d_draw_over_viewport(Control *p_overlay);
  745. void forward_3d_force_draw_over_viewport(Control *p_overlay);
  746. void add_plugin(EditorPlugin *p_plugin);
  747. void remove_plugin(EditorPlugin *p_plugin);
  748. void clear();
  749. bool is_empty();
  750. EditorPluginList();
  751. ~EditorPluginList();
  752. };
  753. struct EditorProgressBG {
  754. String task;
  755. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  756. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  757. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  758. task = p_task;
  759. }
  760. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  761. };
  762. #endif // EDITOR_NODE_H