editor_node.h 34 KB

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