editor_node.h 33 KB

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