editor_node.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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. EditorQuickOpenDialog *quick_open_color_palette = nullptr;
  242. EditorResourcePreview *resource_preview = nullptr;
  243. EditorSelection *editor_selection = nullptr;
  244. EditorSettingsDialog *editor_settings_dialog = nullptr;
  245. HistoryDock *history_dock = nullptr;
  246. ProjectExportDialog *project_export = nullptr;
  247. ProjectSettingsEditor *project_settings_editor = nullptr;
  248. FBXImporterManager *fbx_importer_manager = nullptr;
  249. Vector<EditorPlugin *> editor_plugins;
  250. bool _initializing_plugins = false;
  251. HashMap<String, EditorPlugin *> addon_name_to_plugin;
  252. LocalVector<String> pending_addons;
  253. HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
  254. bool is_main_screen_editing = false;
  255. Control *gui_base = nullptr;
  256. VBoxContainer *main_vbox = nullptr;
  257. OptionButton *renderer = nullptr;
  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. int tab_closing_menu_option = -1;
  276. bool exiting = false;
  277. bool dimmed = false;
  278. DisplayServer::WindowMode prev_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
  279. int old_split_ofs = 0;
  280. VSplitContainer *top_split = nullptr;
  281. Control *vp_base = nullptr;
  282. Label *project_title = nullptr;
  283. Control *left_menu_spacer = nullptr;
  284. Control *right_menu_spacer = nullptr;
  285. EditorTitleBar *title_bar = nullptr;
  286. EditorRunBar *project_run_bar = nullptr;
  287. MenuBar *main_menu = nullptr;
  288. PopupMenu *apple_menu = nullptr;
  289. PopupMenu *file_menu = nullptr;
  290. PopupMenu *project_menu = nullptr;
  291. PopupMenu *debug_menu = nullptr;
  292. PopupMenu *settings_menu = nullptr;
  293. PopupMenu *help_menu = nullptr;
  294. PopupMenu *tool_menu = nullptr;
  295. PopupMenu *export_as_menu = nullptr;
  296. Button *export_button = nullptr;
  297. Button *search_button = nullptr;
  298. TextureProgressBar *audio_vu = nullptr;
  299. Timer *screenshot_timer = nullptr;
  300. uint64_t started_timestamp = 0;
  301. RichTextLabel *load_errors = nullptr;
  302. AcceptDialog *load_error_dialog = nullptr;
  303. bool load_errors_queued_to_display = false;
  304. RichTextLabel *execute_outputs = nullptr;
  305. AcceptDialog *execute_output_dialog = nullptr;
  306. Ref<Theme> theme;
  307. Timer *system_theme_timer = nullptr;
  308. bool follow_system_theme = false;
  309. bool use_system_accent_color = false;
  310. bool last_dark_mode_state = false;
  311. Color last_system_base_color = Color(0, 0, 0, 0);
  312. Color last_system_accent_color = Color(0, 0, 0, 0);
  313. PopupMenu *recent_scenes = nullptr;
  314. String _recent_scene;
  315. List<String> previous_scenes;
  316. String defer_load_scene;
  317. Node *_last_instantiated_scene = nullptr;
  318. ConfirmationDialog *confirmation = nullptr;
  319. ConfirmationDialog *save_confirmation = nullptr;
  320. ConfirmationDialog *import_confirmation = nullptr;
  321. ConfirmationDialog *pick_main_scene = nullptr;
  322. Button *select_current_scene_button = nullptr;
  323. AcceptDialog *accept = nullptr;
  324. AcceptDialog *save_accept = nullptr;
  325. EditorAbout *about = nullptr;
  326. AcceptDialog *warning = nullptr;
  327. EditorPlugin *plugin_to_save = nullptr;
  328. int overridden_default_layout = -1;
  329. Ref<ConfigFile> default_layout;
  330. PopupMenu *editor_layouts = nullptr;
  331. EditorLayoutsDialog *layout_dialog = nullptr;
  332. ConfirmationDialog *gradle_build_manage_templates = nullptr;
  333. ConfirmationDialog *install_android_build_template = nullptr;
  334. ConfirmationDialog *remove_android_build_template = nullptr;
  335. Label *install_android_build_template_message = nullptr;
  336. OptionButton *choose_android_export_profile = nullptr;
  337. Ref<EditorExportPreset> android_export_preset;
  338. PopupMenu *vcs_actions_menu = nullptr;
  339. EditorFileDialog *file = nullptr;
  340. ExportTemplateManager *export_template_manager = nullptr;
  341. EditorFeatureProfileManager *feature_profile_manager = nullptr;
  342. EditorBuildProfileManager *build_profile_manager = nullptr;
  343. EditorFileDialog *file_templates = nullptr;
  344. EditorFileDialog *file_export_lib = nullptr;
  345. EditorFileDialog *file_script = nullptr;
  346. EditorFileDialog *file_android_build_source = nullptr;
  347. String current_path;
  348. MenuButton *update_spinner = nullptr;
  349. EditorMainScreen *editor_main_screen = nullptr;
  350. AudioStreamPreviewGenerator *audio_preview_gen = nullptr;
  351. ProgressDialog *progress_dialog = nullptr;
  352. BackgroundProgress *progress_hb = nullptr;
  353. DependencyErrorDialog *dependency_error = nullptr;
  354. HashMap<String, HashSet<String>> dependency_errors;
  355. DependencyEditor *dependency_fixer = nullptr;
  356. OrphanResourcesDialog *orphan_resources = nullptr;
  357. ConfirmationDialog *open_imported = nullptr;
  358. Button *new_inherited_button = nullptr;
  359. String open_import_request;
  360. EditorDockManager *editor_dock_manager = nullptr;
  361. Timer *editor_layout_save_delay_timer = nullptr;
  362. Timer *scan_changes_timer = nullptr;
  363. Button *distraction_free = nullptr;
  364. Callable palette_file_selected_callback;
  365. EditorBottomPanel *bottom_panel = nullptr;
  366. Tree *disk_changed_list = nullptr;
  367. ConfirmationDialog *disk_changed = nullptr;
  368. bool scene_distraction_free = false;
  369. bool script_distraction_free = false;
  370. bool changing_scene = false;
  371. bool cmdline_export_mode = false;
  372. bool convert_old = false;
  373. bool immediate_dialog_confirmed = false;
  374. bool opening_prev = false;
  375. bool restoring_scenes = false;
  376. bool unsaved_cache = true;
  377. bool requested_first_scan = false;
  378. bool waiting_for_first_scan = true;
  379. bool load_editor_layout_done = false;
  380. int current_menu_option = 0;
  381. SubViewport *scene_root = nullptr; // Root of the scene being edited.
  382. Object *current = nullptr;
  383. Ref<Resource> saving_resource;
  384. HashSet<Ref<Resource>> saving_resources_in_path;
  385. uint64_t update_spinner_step_msec = 0;
  386. uint64_t update_spinner_step_frame = 0;
  387. int update_spinner_step = 0;
  388. String _tmp_import_path;
  389. String external_file;
  390. String open_navigate;
  391. String saving_scene;
  392. EditorProgress *save_scene_progress = nullptr;
  393. DynamicFontImportSettingsDialog *fontdata_import_settings = nullptr;
  394. SceneImportSettingsDialog *scene_import_settings = nullptr;
  395. AudioStreamImportSettingsDialog *audio_stream_import_settings = nullptr;
  396. String import_reload_fn;
  397. HashSet<String> textfile_extensions;
  398. HashSet<String> other_file_extensions;
  399. HashSet<FileDialog *> file_dialogs;
  400. HashSet<EditorFileDialog *> editor_file_dialogs;
  401. Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
  402. PrintHandlerList print_handler;
  403. HashMap<String, Ref<Texture2D>> icon_type_cache;
  404. SurfaceUpgradeTool *surface_upgrade_tool = nullptr;
  405. SurfaceUpgradeDialog *surface_upgrade_dialog = nullptr;
  406. bool run_surface_upgrade_tool = false;
  407. bool was_window_windowed_last = false;
  408. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  409. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  410. static int build_callback_count;
  411. static int plugin_init_callback_count;
  412. static Vector<EditorNodeInitCallback> _init_callbacks;
  413. String _get_system_info() const;
  414. bool _should_display_update_spinner() const;
  415. static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
  416. DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
  417. if (!singleton->dependency_errors.has(p_path)) {
  418. singleton->dependency_errors[p_path] = HashSet<String>();
  419. }
  420. singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
  421. }
  422. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  423. static void _file_dialog_register(FileDialog *p_dialog);
  424. static void _file_dialog_unregister(FileDialog *p_dialog);
  425. static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
  426. static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
  427. static void _file_access_close_error_notify(const String &p_str);
  428. static void _file_access_close_error_notify_impl(const String &p_str);
  429. static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
  430. static void _print_handler_impl(const String &p_string, bool p_error, bool p_rich);
  431. static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
  432. static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
  433. void _update_theme(bool p_skip_creation = false);
  434. void _build_icon_type_cache();
  435. void _enable_pending_addons();
  436. void _dialog_action(String p_file);
  437. void _add_to_history(const Object *p_object, const String &p_property, bool p_inspector_only);
  438. void _edit_current(bool p_skip_foreign = false, bool p_skip_inspector_update = false);
  439. void _dialog_display_save_error(String p_file, Error p_error);
  440. void _dialog_display_load_error(String p_file, Error p_error);
  441. void _menu_option(int p_option);
  442. void _menu_confirm_current();
  443. void _menu_option_confirm(int p_option, bool p_confirmed);
  444. void _android_build_source_selected(const String &p_file);
  445. void _android_export_preset_selected(int p_index);
  446. void _request_screenshot();
  447. void _screenshot(bool p_use_utc = false);
  448. void _save_screenshot(NodePath p_path);
  449. void _check_system_theme_changed();
  450. void _tool_menu_option(int p_idx);
  451. void _export_as_menu_option(int p_idx);
  452. void _update_file_menu_opened();
  453. void _update_file_menu_closed();
  454. void _palette_quick_open_dialog();
  455. void _remove_plugin_from_enabled(const String &p_name);
  456. void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
  457. void _plugin_over_self_own(EditorPlugin *p_plugin);
  458. void _fs_changed();
  459. void _resources_reimporting(const Vector<String> &p_resources);
  460. void _resources_reimported(const Vector<String> &p_resources);
  461. void _sources_changed(bool p_exist);
  462. void _node_renamed();
  463. void _save_editor_states(const String &p_file, int p_idx = -1);
  464. void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
  465. void _update_title();
  466. void _version_control_menu_option(int p_idx);
  467. void _close_messages();
  468. void _show_messages();
  469. void _vp_resized();
  470. void _titlebar_resized();
  471. void _viewport_resized();
  472. void _update_undo_redo_allowed();
  473. int _save_external_resources(bool p_also_save_external_data = false);
  474. void _set_current_scene(int p_idx);
  475. void _set_current_scene_nocheck(int p_idx);
  476. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  477. void _save_scene(String p_file, int idx = -1);
  478. void _save_all_scenes();
  479. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  480. void _discard_changes(const String &p_str = String());
  481. void _scene_tab_closed(int p_tab);
  482. void _cancel_close_scene_tab();
  483. void _inherit_request(String p_file);
  484. void _instantiate_request(const Vector<String> &p_files);
  485. void _quick_opened(const String &p_file_path);
  486. void _open_command_palette();
  487. void _project_run_started();
  488. void _project_run_stopped();
  489. void _add_to_recent_scenes(const String &p_scene);
  490. void _update_recent_scenes();
  491. void _open_recent_scene(int p_idx);
  492. void _dropped_files(const Vector<String> &p_files);
  493. void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
  494. void _update_vsync_mode();
  495. void _update_from_settings();
  496. void _gdextensions_reloaded();
  497. void _renderer_selected(int);
  498. void _update_renderer_color();
  499. void _add_renderer_entry(const String &p_renderer_name, bool p_mark_overridden);
  500. void _exit_editor(int p_exit_code);
  501. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  502. bool has_main_screen() const { return true; }
  503. void _remove_edited_scene(bool p_change_tab = true);
  504. void _remove_scene(int index, bool p_change_tab = true);
  505. bool _find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  506. bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  507. void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  508. void _mark_unsaved_scenes();
  509. void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
  510. void _save_scene_with_preview(String p_file, int p_idx = -1);
  511. void _close_save_scene_progress();
  512. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  513. void _proceed_closing_scene_tabs();
  514. bool _is_closing_editor() const;
  515. Dictionary _get_main_scene_state();
  516. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  517. void _save_editor_layout();
  518. void _load_editor_layout();
  519. void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
  520. void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
  521. void _save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  522. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
  523. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
  524. void _update_layouts_menu();
  525. void _layout_menu_option(int p_id);
  526. void _update_addon_config();
  527. void _toggle_distraction_free_mode();
  528. void _inherit_imported(const String &p_action);
  529. void _open_imported();
  530. void _update_update_spinner();
  531. void _resources_changed(const Vector<String> &p_resources);
  532. void _scan_external_changes();
  533. void _reload_modified_scenes();
  534. void _reload_project_settings();
  535. void _resave_scenes(String p_str);
  536. void _feature_profile_changed();
  537. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  538. 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);
  539. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  540. void _immediate_dialog_confirmed();
  541. void _begin_first_scan();
  542. void _notify_nodes_scene_reimported(Node *p_node, Array p_reimported_nodes);
  543. void _remove_all_not_owned_children(Node *p_node, Node *p_owner);
  544. void _progress_dialog_visibility_changed();
  545. void _load_error_dialog_visibility_changed();
  546. protected:
  547. friend class FileSystemDock;
  548. static void _bind_methods();
  549. void _notification(int p_what);
  550. public:
  551. // Public for use with callable_mp.
  552. void init_plugins();
  553. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  554. bool call_build();
  555. // This is a very naive estimation, but we need something now. Will be reworked later.
  556. bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
  557. static EditorNode *get_singleton() { return singleton; }
  558. static EditorLog *get_log() { return singleton->log; }
  559. static EditorData &get_editor_data() { return singleton->editor_data; }
  560. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  561. static EditorTitleBar *get_title_bar() { return singleton->title_bar; }
  562. static VSplitContainer *get_top_split() { return singleton->top_split; }
  563. static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
  564. static EditorMainScreen *get_editor_main_screen() { return singleton->editor_main_screen; }
  565. static String adjust_scene_name_casing(const String &p_root_name);
  566. static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
  567. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  568. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  569. static void add_io_error(const String &p_error);
  570. static void add_io_warning(const String &p_warning);
  571. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  572. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  573. static void progress_end_task(const String &p_task);
  574. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  575. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  576. static void progress_end_task_bg(const String &p_task);
  577. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  578. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  579. static void add_extension_editor_plugin(const StringName &p_class_name);
  580. static void remove_extension_editor_plugin(const StringName &p_class_name);
  581. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  582. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  583. static void add_build_callback(EditorBuildCallback p_callback);
  584. 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);
  585. static void cleanup();
  586. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  587. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  588. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  589. EditorSelection *get_editor_selection() { return editor_selection; }
  590. EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
  591. ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
  592. void trigger_menu_option(int p_option, bool p_confirmed);
  593. bool has_previous_scenes() const;
  594. void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); }
  595. void update_distraction_free_mode();
  596. void set_distraction_free_mode(bool p_enter);
  597. bool is_distraction_free_mode_enabled() const;
  598. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  599. bool is_addon_plugin_enabled(const String &p_addon) const;
  600. void edit_node(Node *p_node);
  601. void edit_resource(const Ref<Resource> &p_resource);
  602. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  603. void save_resource(const Ref<Resource> &p_resource);
  604. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  605. void ensure_uid_file(const String &p_new_resource_path);
  606. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  607. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  608. void push_item_no_inspector(Object *p_object);
  609. void edit_previous_item();
  610. void edit_item(Object *p_object, Object *p_editing_owner);
  611. void push_node_item(Node *p_node);
  612. void hide_unused_editors(const Object *p_editing_owner = nullptr);
  613. void replace_resources_in_object(
  614. Object *p_object,
  615. const Vector<Ref<Resource>> &p_source_resources,
  616. const Vector<Ref<Resource>> &p_target_resource);
  617. void replace_resources_in_scenes(
  618. const Vector<Ref<Resource>> &p_source_resources,
  619. const Vector<Ref<Resource>> &p_target_resource);
  620. void open_request(const String &p_path);
  621. void edit_foreign_resource(Ref<Resource> p_resource);
  622. bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
  623. String get_multiwindow_support_tooltip_text() const;
  624. bool is_changing_scene() const;
  625. SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
  626. void set_edited_scene(Node *p_scene);
  627. void set_edited_scene_root(Node *p_scene, bool p_auto_add);
  628. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  629. void fix_dependencies(const String &p_for_file);
  630. int new_scene();
  631. 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);
  632. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  633. HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
  634. HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
  635. struct AdditiveNodeEntry {
  636. Node *node = nullptr;
  637. NodePath parent;
  638. Node *owner = nullptr;
  639. int index = 0;
  640. // Used if the original parent node is lost
  641. Transform2D transform_2d;
  642. Transform3D transform_3d;
  643. };
  644. struct ConnectionWithNodePath {
  645. Connection connection;
  646. NodePath node_path;
  647. };
  648. struct ModificationNodeEntry {
  649. HashMap<StringName, Variant> property_table;
  650. List<ConnectionWithNodePath> connections_to;
  651. List<Connection> connections_from;
  652. List<Node::GroupInfo> groups;
  653. };
  654. struct InstanceModificationsEntry {
  655. Node *original_node;
  656. String instance_path;
  657. List<Node *> instance_list;
  658. HashMap<NodePath, ModificationNodeEntry> modifications;
  659. List<AdditiveNodeEntry> addition_list;
  660. };
  661. struct SceneModificationsEntry {
  662. List<InstanceModificationsEntry> instance_list;
  663. HashMap<NodePath, ModificationNodeEntry> other_instances_modifications;
  664. };
  665. struct SceneEditorDataEntry {
  666. bool is_editable;
  667. bool is_display_folded;
  668. };
  669. HashMap<int, SceneModificationsEntry> scenes_modification_table;
  670. List<String> scenes_reimported;
  671. List<String> resources_reimported;
  672. void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
  673. void get_scene_editor_data_for_node(Node *p_root, Node *p_node, HashMap<NodePath, SceneEditorDataEntry> &p_table);
  674. void get_preload_scene_modification_table(
  675. Node *p_edited_scene,
  676. Node *p_reimported_root,
  677. Node *p_node, InstanceModificationsEntry &p_instance_modifications);
  678. void get_preload_modifications_reference_to_nodes(
  679. Node *p_root,
  680. Node *p_node,
  681. HashSet<Node *> &p_excluded_nodes,
  682. List<Node *> &p_instance_list_with_children,
  683. HashMap<NodePath, ModificationNodeEntry> &p_modification_table);
  684. void get_children_nodes(Node *p_node, List<Node *> &p_nodes);
  685. bool is_additional_node_in_scene(Node *p_edited_scene, Node *p_reimported_root, Node *p_node);
  686. void replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node);
  687. bool is_scene_open(const String &p_path);
  688. bool is_multi_window_enabled() const;
  689. void setup_color_picker(ColorPicker *p_picker);
  690. void request_instantiate_scene(const String &p_path);
  691. void request_instantiate_scenes(const Vector<String> &p_files);
  692. void set_convert_old_scene(bool p_old) { convert_old = p_old; }
  693. void notify_all_debug_sessions_exited();
  694. OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
  695. void stop_child_process(OS::ProcessID p_pid);
  696. Ref<Theme> get_editor_theme() const { return theme; }
  697. void update_preview_themes(int p_mode);
  698. Ref<Script> get_object_custom_type_base(const Object *p_object) const;
  699. StringName get_object_custom_type_name(const Object *p_object) const;
  700. Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "Object");
  701. Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
  702. bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
  703. void show_accept(const String &p_text, const String &p_title);
  704. void show_save_accept(const String &p_text, const String &p_title);
  705. void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
  706. void _copy_warning(const String &p_str);
  707. 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);
  708. bool is_project_exporting() const;
  709. Control *get_gui_base() { return gui_base; }
  710. void save_scene_to_path(String p_file, bool p_with_preview = true) {
  711. if (p_with_preview) {
  712. _save_scene_with_preview(p_file);
  713. } else {
  714. _save_scene(p_file);
  715. }
  716. }
  717. bool is_scene_in_use(const String &p_path);
  718. void save_editor_layout_delayed();
  719. void save_default_environment();
  720. void open_export_template_manager();
  721. void reload_scene(const String &p_path);
  722. void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, HashSet<Node *> &p_instance_list);
  723. void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
  724. void reload_instances_with_path_in_edited_scenes();
  725. bool is_exiting() const { return exiting; }
  726. Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
  727. Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  728. EditorQuickOpenDialog *get_quick_open_dialog() { return quick_open_dialog; }
  729. void add_tool_menu_item(const String &p_name, const Callable &p_callback);
  730. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  731. void remove_tool_menu_item(const String &p_name);
  732. PopupMenu *get_export_as_menu();
  733. void save_all_scenes();
  734. void save_scene_if_open(const String &p_scene_path);
  735. void save_scene_list(const HashSet<String> &p_scene_paths);
  736. void save_before_run();
  737. void try_autosave();
  738. void restart_editor(bool p_goto_project_manager = false);
  739. void unload_editor_addons();
  740. void dim_editor(bool p_dimming);
  741. bool is_editor_dimmed() const;
  742. void edit_current() { _edit_current(); }
  743. bool has_scenes_in_session();
  744. void undo();
  745. void redo();
  746. 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);
  747. EditorNode();
  748. ~EditorNode();
  749. void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  750. void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
  751. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_resource(const Ref<Resource> &p_for_resource);
  752. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
  753. bool ensure_main_scene(bool p_from_native);
  754. };
  755. class EditorPluginList : public Object {
  756. private:
  757. Vector<EditorPlugin *> plugins_list;
  758. public:
  759. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  760. plugins_list = p_plugins_list;
  761. }
  762. Vector<EditorPlugin *> &get_plugins_list() {
  763. return plugins_list;
  764. }
  765. void make_visible(bool p_visible);
  766. void edit(Object *p_object);
  767. bool forward_gui_input(const Ref<InputEvent> &p_event);
  768. void forward_canvas_draw_over_viewport(Control *p_overlay);
  769. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  770. EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  771. void forward_3d_draw_over_viewport(Control *p_overlay);
  772. void forward_3d_force_draw_over_viewport(Control *p_overlay);
  773. void add_plugin(EditorPlugin *p_plugin);
  774. void remove_plugin(EditorPlugin *p_plugin);
  775. void clear();
  776. bool is_empty();
  777. EditorPluginList();
  778. ~EditorPluginList();
  779. };
  780. struct EditorProgressBG {
  781. String task;
  782. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  783. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  784. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  785. task = p_task;
  786. }
  787. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  788. };
  789. #endif // EDITOR_NODE_H