editor_node.h 33 KB

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