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