editor_node.h 33 KB

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