editor_node.h 34 KB

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