editor_node.h 29 KB

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