editor_node.h 32 KB

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