editor_node.h 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004
  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. bool unfocused_low_processor_usage_mode_enabled = true;
  409. static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
  410. static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
  411. static int build_callback_count;
  412. static int plugin_init_callback_count;
  413. static Vector<EditorNodeInitCallback> _init_callbacks;
  414. String _get_system_info() const;
  415. bool _should_display_update_spinner() const;
  416. static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
  417. DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
  418. if (!singleton->dependency_errors.has(p_path)) {
  419. singleton->dependency_errors[p_path] = HashSet<String>();
  420. }
  421. singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
  422. }
  423. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  424. static void _file_dialog_register(FileDialog *p_dialog);
  425. static void _file_dialog_unregister(FileDialog *p_dialog);
  426. static void _editor_file_dialog_register(EditorFileDialog *p_dialog);
  427. static void _editor_file_dialog_unregister(EditorFileDialog *p_dialog);
  428. static void _file_access_close_error_notify(const String &p_str);
  429. static void _file_access_close_error_notify_impl(const String &p_str);
  430. static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
  431. static void _print_handler_impl(const String &p_string, bool p_error, bool p_rich);
  432. static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
  433. static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
  434. void _update_theme(bool p_skip_creation = false);
  435. void _build_icon_type_cache();
  436. void _enable_pending_addons();
  437. void _dialog_action(String p_file);
  438. void _add_to_history(const Object *p_object, const String &p_property, bool p_inspector_only);
  439. void _edit_current(bool p_skip_foreign = false, bool p_skip_inspector_update = false);
  440. void _dialog_display_save_error(String p_file, Error p_error);
  441. void _dialog_display_load_error(String p_file, Error p_error);
  442. void _menu_option(int p_option);
  443. void _menu_confirm_current();
  444. void _menu_option_confirm(int p_option, bool p_confirmed);
  445. void _android_build_source_selected(const String &p_file);
  446. void _android_export_preset_selected(int p_index);
  447. void _request_screenshot();
  448. void _screenshot(bool p_use_utc = false);
  449. void _save_screenshot(NodePath p_path);
  450. void _check_system_theme_changed();
  451. void _tool_menu_option(int p_idx);
  452. void _export_as_menu_option(int p_idx);
  453. void _update_file_menu_opened();
  454. void _update_file_menu_closed();
  455. void _palette_quick_open_dialog();
  456. void _remove_plugin_from_enabled(const String &p_name);
  457. void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
  458. void _plugin_over_self_own(EditorPlugin *p_plugin);
  459. void _fs_changed();
  460. void _resources_reimporting(const Vector<String> &p_resources);
  461. void _resources_reimported(const Vector<String> &p_resources);
  462. void _sources_changed(bool p_exist);
  463. void _node_renamed();
  464. void _save_editor_states(const String &p_file, int p_idx = -1);
  465. void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
  466. void _update_title();
  467. void _version_control_menu_option(int p_idx);
  468. void _close_messages();
  469. void _show_messages();
  470. void _vp_resized();
  471. void _titlebar_resized();
  472. void _viewport_resized();
  473. void _update_undo_redo_allowed();
  474. int _save_external_resources(bool p_also_save_external_data = false);
  475. void _set_current_scene(int p_idx);
  476. void _set_current_scene_nocheck(int p_idx);
  477. bool _validate_scene_recursive(const String &p_filename, Node *p_node);
  478. void _save_scene(String p_file, int idx = -1);
  479. void _save_all_scenes();
  480. int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
  481. void _discard_changes(const String &p_str = String());
  482. void _scene_tab_closed(int p_tab);
  483. void _cancel_close_scene_tab();
  484. void _inherit_request(String p_file);
  485. void _instantiate_request(const Vector<String> &p_files);
  486. void _quick_opened(const String &p_file_path);
  487. void _open_command_palette();
  488. void _project_run_started();
  489. void _project_run_stopped();
  490. void _add_to_recent_scenes(const String &p_scene);
  491. void _update_recent_scenes();
  492. void _open_recent_scene(int p_idx);
  493. void _dropped_files(const Vector<String> &p_files);
  494. void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
  495. void _update_vsync_mode();
  496. void _update_from_settings();
  497. void _gdextensions_reloaded();
  498. void _renderer_selected(int);
  499. void _update_renderer_color();
  500. void _add_renderer_entry(const String &p_renderer_name, bool p_mark_overridden);
  501. void _exit_editor(int p_exit_code);
  502. virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
  503. bool has_main_screen() const { return true; }
  504. void _remove_edited_scene(bool p_change_tab = true);
  505. void _remove_scene(int index, bool p_change_tab = true);
  506. bool _find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  507. bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  508. void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
  509. void _mark_unsaved_scenes();
  510. void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
  511. void _save_scene_with_preview(String p_file, int p_idx = -1);
  512. void _close_save_scene_progress();
  513. bool _find_scene_in_use(Node *p_node, const String &p_path) const;
  514. void _proceed_closing_scene_tabs();
  515. bool _is_closing_editor() const;
  516. Dictionary _get_main_scene_state();
  517. void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
  518. void _save_editor_layout();
  519. void _load_editor_layout();
  520. void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
  521. void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
  522. void _save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section);
  523. void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
  524. void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
  525. void _update_layouts_menu();
  526. void _layout_menu_option(int p_id);
  527. void _update_addon_config();
  528. void _toggle_distraction_free_mode();
  529. void _inherit_imported(const String &p_action);
  530. void _open_imported();
  531. void _update_update_spinner();
  532. void _resources_changed(const Vector<String> &p_resources);
  533. void _scan_external_changes();
  534. void _reload_modified_scenes();
  535. void _reload_project_settings();
  536. void _resave_scenes(String p_str);
  537. void _feature_profile_changed();
  538. bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
  539. 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);
  540. void _pick_main_scene_custom_action(const String &p_custom_action_name);
  541. void _immediate_dialog_confirmed();
  542. void _begin_first_scan();
  543. void _notify_nodes_scene_reimported(Node *p_node, Array p_reimported_nodes);
  544. void _remove_all_not_owned_children(Node *p_node, Node *p_owner);
  545. void _progress_dialog_visibility_changed();
  546. void _load_error_dialog_visibility_changed();
  547. protected:
  548. friend class FileSystemDock;
  549. static void _bind_methods();
  550. void _notification(int p_what);
  551. public:
  552. // Public for use with callable_mp.
  553. void init_plugins();
  554. void _on_plugin_ready(Object *p_script, const String &p_activate_name);
  555. bool call_build();
  556. // This is a very naive estimation, but we need something now. Will be reworked later.
  557. bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
  558. static EditorNode *get_singleton() { return singleton; }
  559. static EditorLog *get_log() { return singleton->log; }
  560. static EditorData &get_editor_data() { return singleton->editor_data; }
  561. static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
  562. static EditorTitleBar *get_title_bar() { return singleton->title_bar; }
  563. static VSplitContainer *get_top_split() { return singleton->top_split; }
  564. static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
  565. static EditorMainScreen *get_editor_main_screen() { return singleton->editor_main_screen; }
  566. static String adjust_scene_name_casing(const String &p_root_name);
  567. static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
  568. static bool has_unsaved_changes() { return singleton->unsaved_cache; }
  569. static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
  570. static void add_io_error(const String &p_error);
  571. static void add_io_warning(const String &p_warning);
  572. static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
  573. static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
  574. static void progress_end_task(const String &p_task);
  575. static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
  576. static void progress_task_step_bg(const String &p_task, int p_step = -1);
  577. static void progress_end_task_bg(const String &p_task);
  578. static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  579. static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
  580. static void add_extension_editor_plugin(const StringName &p_class_name);
  581. static void remove_extension_editor_plugin(const StringName &p_class_name);
  582. static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
  583. static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
  584. static void add_build_callback(EditorBuildCallback p_callback);
  585. 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);
  586. static void cleanup();
  587. EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
  588. EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
  589. EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
  590. EditorSelection *get_editor_selection() { return editor_selection; }
  591. EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
  592. ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
  593. void trigger_menu_option(int p_option, bool p_confirmed);
  594. bool has_previous_scenes() const;
  595. void new_inherited_scene() { _menu_option_confirm(FILE_NEW_INHERITED_SCENE, false); }
  596. void update_distraction_free_mode();
  597. void set_distraction_free_mode(bool p_enter);
  598. bool is_distraction_free_mode_enabled() const;
  599. void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
  600. bool is_addon_plugin_enabled(const String &p_addon) const;
  601. void edit_node(Node *p_node);
  602. void edit_resource(const Ref<Resource> &p_resource);
  603. void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
  604. void save_resource(const Ref<Resource> &p_resource);
  605. void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
  606. void ensure_uid_file(const String &p_new_resource_path);
  607. void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
  608. void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
  609. void push_item_no_inspector(Object *p_object);
  610. void edit_previous_item();
  611. void edit_item(Object *p_object, Object *p_editing_owner);
  612. void push_node_item(Node *p_node);
  613. void hide_unused_editors(const Object *p_editing_owner = nullptr);
  614. void replace_resources_in_object(
  615. Object *p_object,
  616. const Vector<Ref<Resource>> &p_source_resources,
  617. const Vector<Ref<Resource>> &p_target_resource);
  618. void replace_resources_in_scenes(
  619. const Vector<Ref<Resource>> &p_source_resources,
  620. const Vector<Ref<Resource>> &p_target_resource);
  621. void open_request(const String &p_path, bool p_set_inherited = false);
  622. void edit_foreign_resource(Ref<Resource> p_resource);
  623. bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
  624. String get_multiwindow_support_tooltip_text() const;
  625. bool is_changing_scene() const;
  626. SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
  627. void set_edited_scene(Node *p_scene);
  628. void set_edited_scene_root(Node *p_scene, bool p_auto_add);
  629. Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
  630. void fix_dependencies(const String &p_for_file);
  631. int new_scene();
  632. 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);
  633. Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
  634. HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
  635. HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
  636. void set_unfocused_low_processor_usage_mode_enabled(bool p_enabled);
  637. struct AdditiveNodeEntry {
  638. Node *node = nullptr;
  639. NodePath parent;
  640. Node *owner = nullptr;
  641. int index = 0;
  642. // Used if the original parent node is lost
  643. Transform2D transform_2d;
  644. Transform3D transform_3d;
  645. };
  646. struct ConnectionWithNodePath {
  647. Connection connection;
  648. NodePath node_path;
  649. };
  650. struct ModificationNodeEntry {
  651. HashMap<StringName, Variant> property_table;
  652. List<ConnectionWithNodePath> connections_to;
  653. List<Connection> connections_from;
  654. List<Node::GroupInfo> groups;
  655. };
  656. struct InstanceModificationsEntry {
  657. Node *original_node;
  658. String instance_path;
  659. List<Node *> instance_list;
  660. HashMap<NodePath, ModificationNodeEntry> modifications;
  661. List<AdditiveNodeEntry> addition_list;
  662. };
  663. struct SceneModificationsEntry {
  664. List<InstanceModificationsEntry> instance_list;
  665. HashMap<NodePath, ModificationNodeEntry> other_instances_modifications;
  666. };
  667. struct SceneEditorDataEntry {
  668. bool is_editable;
  669. bool is_display_folded;
  670. };
  671. HashMap<int, SceneModificationsEntry> scenes_modification_table;
  672. List<String> scenes_reimported;
  673. List<String> resources_reimported;
  674. void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
  675. void get_scene_editor_data_for_node(Node *p_root, Node *p_node, HashMap<NodePath, SceneEditorDataEntry> &p_table);
  676. void get_preload_scene_modification_table(
  677. Node *p_edited_scene,
  678. Node *p_reimported_root,
  679. Node *p_node, InstanceModificationsEntry &p_instance_modifications);
  680. void get_preload_modifications_reference_to_nodes(
  681. Node *p_root,
  682. Node *p_node,
  683. HashSet<Node *> &p_excluded_nodes,
  684. List<Node *> &p_instance_list_with_children,
  685. HashMap<NodePath, ModificationNodeEntry> &p_modification_table);
  686. void get_children_nodes(Node *p_node, List<Node *> &p_nodes);
  687. bool is_additional_node_in_scene(Node *p_edited_scene, Node *p_reimported_root, Node *p_node);
  688. void replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node);
  689. bool is_scene_open(const String &p_path);
  690. bool is_multi_window_enabled() const;
  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, bool p_android_build_template, bool p_patch, const Vector<String> &p_patches);
  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, HashSet<Node *> &p_instance_list);
  725. void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
  726. void reload_instances_with_path_in_edited_scenes();
  727. bool is_exiting() const { return exiting; }
  728. Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
  729. Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
  730. EditorQuickOpenDialog *get_quick_open_dialog() { return quick_open_dialog; }
  731. void add_tool_menu_item(const String &p_name, const Callable &p_callback);
  732. void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
  733. void remove_tool_menu_item(const String &p_name);
  734. PopupMenu *get_export_as_menu();
  735. void save_all_scenes();
  736. void save_scene_if_open(const String &p_scene_path);
  737. void save_scene_list(const HashSet<String> &p_scene_paths);
  738. void save_before_run();
  739. void try_autosave();
  740. void restart_editor(bool p_goto_project_manager = false);
  741. void unload_editor_addons();
  742. void dim_editor(bool p_dimming);
  743. bool is_editor_dimmed() const;
  744. void edit_current() { _edit_current(); }
  745. bool has_scenes_in_session();
  746. void undo();
  747. void redo();
  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_for_resource(const Ref<Resource> &p_for_resource);
  754. Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
  755. bool ensure_main_scene(bool p_from_native);
  756. };
  757. class EditorPluginList : public Object {
  758. private:
  759. Vector<EditorPlugin *> plugins_list;
  760. public:
  761. void set_plugins_list(Vector<EditorPlugin *> p_plugins_list) {
  762. plugins_list = p_plugins_list;
  763. }
  764. Vector<EditorPlugin *> &get_plugins_list() {
  765. return plugins_list;
  766. }
  767. void make_visible(bool p_visible);
  768. void edit(Object *p_object);
  769. bool forward_gui_input(const Ref<InputEvent> &p_event);
  770. void forward_canvas_draw_over_viewport(Control *p_overlay);
  771. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  772. EditorPlugin::AfterGUIInput forward_3d_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event, bool serve_when_force_input_enabled);
  773. void forward_3d_draw_over_viewport(Control *p_overlay);
  774. void forward_3d_force_draw_over_viewport(Control *p_overlay);
  775. void add_plugin(EditorPlugin *p_plugin);
  776. void remove_plugin(EditorPlugin *p_plugin);
  777. void clear();
  778. bool is_empty();
  779. EditorPluginList();
  780. ~EditorPluginList();
  781. };
  782. struct EditorProgressBG {
  783. String task;
  784. void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
  785. EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
  786. EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
  787. task = p_task;
  788. }
  789. ~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
  790. };
  791. #endif // EDITOR_NODE_H