2
0

editor_node.h 34 KB

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