Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/editor_node.h
22517 views
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
#pragma once
32
33
#include "core/object/script_language.h"
34
#include "core/templates/safe_refcount.h"
35
#include "editor/editor_data.h"
36
#include "editor/plugins/editor_plugin.h"
37
#include "editor/settings/editor_folding.h"
38
39
typedef void (*EditorNodeInitCallback)();
40
typedef void (*EditorPluginInitializeCallback)();
41
typedef bool (*EditorBuildCallback)();
42
43
class AcceptDialog;
44
class ColorPicker;
45
class ConfirmationDialog;
46
class Control;
47
class FileDialog;
48
class HBoxContainer;
49
class ImageTexture;
50
class MenuBar;
51
class MenuButton;
52
class OptionButton;
53
class Panel;
54
class PanelContainer;
55
class RichTextLabel;
56
class SubViewport;
57
class TextureProgressBar;
58
class Timer;
59
class Translation;
60
class Tree;
61
class VBoxContainer;
62
class VSplitContainer;
63
class Window;
64
65
class AudioStreamImportSettingsDialog;
66
class AudioStreamPreviewGenerator;
67
class BackgroundProgress;
68
class DependencyErrorDialog;
69
class DockSplitContainer;
70
class DynamicFontImportSettingsDialog;
71
class EditorAbout;
72
class EditorBuildProfileManager;
73
class EditorBottomPanel;
74
class EditorCommandPalette;
75
class EditorDockManager;
76
class EditorExport;
77
class EditorExportPreset;
78
class EditorFeatureProfileManager;
79
class EditorFileDialog;
80
class EditorFolding;
81
class EditorLayoutsDialog;
82
class EditorLog;
83
class EditorMainScreen;
84
class EditorNativeShaderSourceVisualizer;
85
class EditorPluginList;
86
class EditorResourcePreview;
87
class EditorResourceConversionPlugin;
88
class EditorRunBar;
89
class EditorSceneTabs;
90
class EditorSelectionHistory;
91
class EditorSettingsDialog;
92
class EditorTitleBar;
93
class ExportTemplateManager;
94
class EditorQuickOpenDialog;
95
class FBXImporterManager;
96
class FileSystemDock;
97
class HistoryDock;
98
class OrphanResourcesDialog;
99
class ProgressDialog;
100
class ProjectExportDialog;
101
class ProjectSettingsEditor;
102
class SceneImportSettingsDialog;
103
class ProjectUpgradeTool;
104
105
#ifdef ANDROID_ENABLED
106
class TouchActionsPanel;
107
#endif
108
109
struct EditorProgress {
110
String task;
111
bool force_background = false;
112
bool step(const String &p_state, int p_step = -1, bool p_force_refresh = true);
113
114
EditorProgress(const String &p_task, const String &p_label, int p_amount, bool p_can_cancel = false, bool p_force_background = false);
115
~EditorProgress();
116
};
117
118
class EditorNode : public Node {
119
GDCLASS(EditorNode, Node);
120
121
public:
122
enum SceneNameCasing {
123
SCENE_NAME_CASING_AUTO,
124
SCENE_NAME_CASING_PASCAL_CASE,
125
SCENE_NAME_CASING_SNAKE_CASE,
126
SCENE_NAME_CASING_KEBAB_CASE,
127
SCENE_NAME_CASING_CAMEL_CASE,
128
};
129
130
enum ActionOnPlay {
131
ACTION_ON_PLAY_DO_NOTHING,
132
ACTION_ON_PLAY_OPEN_OUTPUT,
133
ACTION_ON_PLAY_OPEN_DEBUGGER,
134
};
135
136
enum ActionOnStop {
137
ACTION_ON_STOP_DO_NOTHING,
138
ACTION_ON_STOP_CLOSE_BUTTOM_PANEL,
139
};
140
141
enum MenuOptions {
142
// Scene menu.
143
SCENE_NEW_SCENE,
144
SCENE_NEW_INHERITED_SCENE,
145
SCENE_OPEN_SCENE,
146
SCENE_OPEN_PREV,
147
SCENE_OPEN_RECENT,
148
SCENE_SAVE_SCENE,
149
SCENE_SAVE_AS_SCENE,
150
SCENE_SAVE_ALL_SCENES,
151
SCENE_MULTI_SAVE_AS_SCENE,
152
SCENE_QUICK_OPEN,
153
SCENE_QUICK_OPEN_SCENE,
154
SCENE_QUICK_OPEN_SCRIPT,
155
SCENE_EXPORT_AS,
156
SCENE_UNDO,
157
SCENE_REDO,
158
SCENE_RELOAD_SAVED_SCENE,
159
SCENE_CLOSE,
160
SCENE_CLOSE_ALL,
161
SCENE_QUIT,
162
163
FILE_EXPORT_MESH_LIBRARY,
164
165
// Project menu.
166
PROJECT_OPEN_SETTINGS,
167
PROJECT_FIND_IN_FILES,
168
PROJECT_VERSION_CONTROL,
169
PROJECT_EXPORT,
170
PROJECT_PACK_AS_ZIP,
171
PROJECT_INSTALL_ANDROID_SOURCE,
172
PROJECT_OPEN_USER_DATA_FOLDER,
173
PROJECT_RELOAD_CURRENT_PROJECT,
174
PROJECT_QUIT_TO_PROJECT_MANAGER,
175
176
TOOLS_ORPHAN_RESOURCES,
177
TOOLS_BUILD_PROFILE_MANAGER,
178
TOOLS_PROJECT_UPGRADE,
179
TOOLS_CUSTOM,
180
181
VCS_METADATA,
182
VCS_SETTINGS,
183
184
// Editor menu.
185
EDITOR_OPEN_SETTINGS,
186
EDITOR_COMMAND_PALETTE,
187
EDITOR_TAKE_SCREENSHOT,
188
EDITOR_TOGGLE_FULLSCREEN,
189
EDITOR_OPEN_DATA_FOLDER,
190
EDITOR_OPEN_CONFIG_FOLDER,
191
EDITOR_MANAGE_FEATURE_PROFILES,
192
EDITOR_MANAGE_EXPORT_TEMPLATES,
193
EDITOR_CONFIGURE_FBX_IMPORTER,
194
195
LAYOUT_SAVE,
196
LAYOUT_DELETE,
197
LAYOUT_DEFAULT,
198
199
// Help menu.
200
HELP_SEARCH,
201
HELP_DOCS,
202
HELP_FORUM,
203
HELP_COMMUNITY,
204
HELP_COPY_SYSTEM_INFO,
205
HELP_REPORT_A_BUG,
206
HELP_SUGGEST_A_FEATURE,
207
HELP_SEND_DOCS_FEEDBACK,
208
HELP_ABOUT,
209
HELP_SUPPORT_GODOT_DEVELOPMENT,
210
211
// Update spinner menu.
212
SPINNER_UPDATE_CONTINUOUSLY,
213
SPINNER_UPDATE_WHEN_CHANGED,
214
SPINNER_UPDATE_SPINNER_HIDE,
215
216
// Non-menu options.
217
SCENE_TAB_CLOSE,
218
SCENE_TAB_SET_AS_MAIN_SCENE,
219
SAVE_AND_RUN,
220
SAVE_AND_RUN_MAIN_SCENE,
221
SAVE_AND_SET_MAIN_SCENE,
222
RESOURCE_SAVE,
223
RESOURCE_SAVE_AS,
224
SETTINGS_PICK_MAIN_SCENE,
225
};
226
227
struct ExecuteThreadArgs {
228
String path;
229
List<String> args;
230
String output;
231
Thread execute_output_thread;
232
Mutex execute_output_mutex;
233
int exitcode = 0;
234
SafeFlag done;
235
};
236
237
private:
238
friend class EditorSceneTabs;
239
240
enum {
241
MAX_INIT_CALLBACKS = 128,
242
MAX_BUILD_CALLBACKS = 128,
243
};
244
245
struct ExportDefer {
246
String preset;
247
String path;
248
bool debug = false;
249
bool pack_only = false;
250
bool android_build_template = false;
251
bool patch = false;
252
Vector<String> patches;
253
} export_defer;
254
255
static EditorNode *singleton;
256
257
EditorData editor_data;
258
EditorFolding editor_folding;
259
EditorSelectionHistory editor_history;
260
261
EditorCommandPalette *command_palette = nullptr;
262
EditorQuickOpenDialog *quick_open_dialog = nullptr;
263
EditorExport *editor_export = nullptr;
264
EditorLog *log = nullptr;
265
EditorNativeShaderSourceVisualizer *native_shader_source_visualizer = nullptr;
266
EditorPluginList *editor_plugins_force_input_forwarding = nullptr;
267
EditorPluginList *editor_plugins_force_over = nullptr;
268
EditorPluginList *editor_plugins_over = nullptr;
269
EditorQuickOpenDialog *quick_open_color_palette = nullptr;
270
EditorResourcePreview *resource_preview = nullptr;
271
EditorSelection *editor_selection = nullptr;
272
EditorSettingsDialog *editor_settings_dialog = nullptr;
273
HistoryDock *history_dock = nullptr;
274
275
ProjectExportDialog *project_export = nullptr;
276
ProjectSettingsEditor *project_settings_editor = nullptr;
277
278
FBXImporterManager *fbx_importer_manager = nullptr;
279
280
Vector<EditorPlugin *> editor_plugins;
281
bool _initializing_plugins = false;
282
HashMap<String, EditorPlugin *> addon_name_to_plugin;
283
LocalVector<String> pending_addons;
284
HashMap<ObjectID, HashSet<EditorPlugin *>> active_plugins;
285
bool is_main_screen_editing = false;
286
287
Control *gui_base = nullptr;
288
VBoxContainer *main_vbox = nullptr;
289
OptionButton *renderer = nullptr;
290
291
#ifdef ANDROID_ENABLED
292
VBoxContainer *base_vbox = nullptr; // It only contains the title_bar and main_hbox.
293
HBoxContainer *main_hbox = nullptr; // It only contains the touch_actions_panel and main_vbox.
294
TouchActionsPanel *touch_actions_panel = nullptr;
295
void _touch_actions_panel_mode_changed();
296
#endif
297
298
ConfirmationDialog *video_restart_dialog = nullptr;
299
300
// Split containers.
301
DockSplitContainer *left_l_vsplit = nullptr;
302
DockSplitContainer *left_r_vsplit = nullptr;
303
DockSplitContainer *main_hsplit = nullptr;
304
DockSplitContainer *right_l_vsplit = nullptr;
305
DockSplitContainer *right_r_vsplit = nullptr;
306
DockSplitContainer *center_split = nullptr;
307
308
// Main tabs.
309
EditorSceneTabs *scene_tabs = nullptr;
310
311
int tab_closing_idx = 0;
312
List<String> tabs_to_close;
313
List<int> scenes_to_save_as;
314
int tab_closing_menu_option = -1;
315
316
bool exiting = false;
317
bool dimmed = false;
318
319
DisplayServer::WindowMode prev_mode = DisplayServer::WINDOW_MODE_MAXIMIZED;
320
int old_split_ofs = 0;
321
VSplitContainer *top_split = nullptr;
322
Control *vp_base = nullptr;
323
324
Label *project_title = nullptr;
325
Control *left_menu_spacer = nullptr;
326
Control *right_menu_spacer = nullptr;
327
EditorTitleBar *title_bar = nullptr;
328
EditorRunBar *project_run_bar = nullptr;
329
HBoxContainer *right_menu_hb = nullptr;
330
331
// Spacers to center 2D / 3D / Script buttons.
332
HBoxContainer *left_spacer = nullptr;
333
Control *right_spacer = nullptr;
334
335
Control *menu_btn_spacer = nullptr;
336
MenuButton *main_menu_button = nullptr;
337
MenuBar *main_menu_bar = nullptr;
338
339
PopupMenu *apple_menu = nullptr;
340
PopupMenu *file_menu = nullptr;
341
PopupMenu *project_menu = nullptr;
342
PopupMenu *debug_menu = nullptr;
343
PopupMenu *settings_menu = nullptr;
344
PopupMenu *help_menu = nullptr;
345
PopupMenu *tool_menu = nullptr;
346
PopupMenu *export_as_menu = nullptr;
347
Button *export_button = nullptr;
348
349
Timer *screenshot_timer = nullptr;
350
351
RichTextLabel *load_errors = nullptr;
352
AcceptDialog *load_error_dialog = nullptr;
353
bool load_errors_queued_to_display = false;
354
355
RichTextLabel *execute_outputs = nullptr;
356
AcceptDialog *execute_output_dialog = nullptr;
357
358
Ref<Theme> theme;
359
360
bool follow_system_theme = false;
361
bool use_system_accent_color = false;
362
bool last_dark_mode_state = false;
363
Color last_system_base_color = Color(0, 0, 0, 0);
364
Color last_system_accent_color = Color(0, 0, 0, 0);
365
366
PopupMenu *recent_scenes = nullptr;
367
String _recent_scene;
368
List<String> prev_closed_scenes;
369
String defer_load_scene;
370
Node *_last_instantiated_scene = nullptr;
371
372
ConfirmationDialog *confirmation = nullptr;
373
bool stop_project_confirmation = false;
374
Button *confirmation_button = nullptr;
375
ConfirmationDialog *save_confirmation = nullptr;
376
ConfirmationDialog *import_confirmation = nullptr;
377
ConfirmationDialog *pick_main_scene = nullptr;
378
ConfirmationDialog *open_project_settings = nullptr;
379
Button *select_current_scene_button = nullptr;
380
AcceptDialog *accept = nullptr;
381
AcceptDialog *save_accept = nullptr;
382
EditorAbout *about = nullptr;
383
AcceptDialog *warning = nullptr;
384
EditorPlugin *plugin_to_save = nullptr;
385
386
int overridden_default_layout = -1;
387
Ref<ConfigFile> default_layout;
388
PopupMenu *editor_layouts = nullptr;
389
EditorLayoutsDialog *layout_dialog = nullptr;
390
391
ConfirmationDialog *gradle_build_manage_templates = nullptr;
392
ConfirmationDialog *install_android_build_template = nullptr;
393
ConfirmationDialog *remove_android_build_template = nullptr;
394
Label *install_android_build_template_message = nullptr;
395
OptionButton *choose_android_export_profile = nullptr;
396
Ref<EditorExportPreset> android_export_preset;
397
398
PopupMenu *vcs_actions_menu = nullptr;
399
EditorFileDialog *file = nullptr;
400
ExportTemplateManager *export_template_manager = nullptr;
401
EditorFeatureProfileManager *feature_profile_manager = nullptr;
402
EditorBuildProfileManager *build_profile_manager = nullptr;
403
EditorFileDialog *file_templates = nullptr;
404
EditorFileDialog *file_export_lib = nullptr;
405
EditorFileDialog *file_android_build_source = nullptr;
406
EditorFileDialog *file_pack_zip = nullptr;
407
MenuButton *update_spinner = nullptr;
408
409
EditorMainScreen *editor_main_screen = nullptr;
410
411
AudioStreamPreviewGenerator *audio_preview_gen = nullptr;
412
ProgressDialog *progress_dialog = nullptr;
413
BackgroundProgress *progress_hb = nullptr;
414
415
DependencyErrorDialog *dependency_error = nullptr;
416
HashMap<String, HashSet<String>> dependency_errors;
417
OrphanResourcesDialog *orphan_resources = nullptr;
418
ConfirmationDialog *open_imported = nullptr;
419
Button *new_inherited_button = nullptr;
420
String open_import_request;
421
422
EditorDockManager *editor_dock_manager = nullptr;
423
Timer *editor_layout_save_delay_timer = nullptr;
424
Timer *scan_changes_timer = nullptr;
425
Button *distraction_free = nullptr;
426
Callable palette_file_selected_callback;
427
428
EditorBottomPanel *bottom_panel = nullptr;
429
430
Tree *disk_changed_list = nullptr;
431
LocalVector<String> disk_changed_scenes;
432
bool disk_changed_project = false;
433
ConfirmationDialog *disk_changed = nullptr;
434
ConfirmationDialog *project_data_missing = nullptr;
435
436
bool scene_distraction_free = false;
437
bool script_distraction_free = false;
438
439
bool changing_scene = false;
440
bool cmdline_mode = false;
441
bool convert_old = false;
442
bool immediate_dialog_confirmed = false;
443
bool restoring_scenes = false;
444
bool settings_overrides_changed = false;
445
bool unsaved_cache = false;
446
447
bool requested_first_scan = false;
448
bool waiting_for_first_scan = true;
449
bool load_editor_layout_done = false;
450
451
bool select_current_scene_file_requested = false;
452
453
HashSet<Ref<Translation>> tracked_translations;
454
bool pending_translation_notification = false;
455
456
int current_menu_option = 0;
457
458
SubViewport *scene_root = nullptr; // Root of the scene being edited.
459
460
Ref<Resource> saving_resource;
461
HashSet<Ref<Resource>> saving_resources_in_path;
462
HashMap<Ref<Resource>, List<Node *>> resource_count; // Keeps track of linked Resources from a Scene.
463
464
uint64_t update_spinner_step_msec = 0;
465
uint64_t update_spinner_step_frame = 0;
466
int update_spinner_step = 0;
467
468
String saving_scene;
469
EditorProgress *save_scene_progress = nullptr;
470
471
DynamicFontImportSettingsDialog *fontdata_import_settings = nullptr;
472
SceneImportSettingsDialog *scene_import_settings = nullptr;
473
AudioStreamImportSettingsDialog *audio_stream_import_settings = nullptr;
474
475
HashSet<String> force_textfile_extensions;
476
HashSet<String> textfile_extensions;
477
HashSet<String> other_file_extensions;
478
HashSet<FileDialog *> file_dialogs;
479
480
Vector<Ref<EditorResourceConversionPlugin>> resource_conversion_plugins;
481
PrintHandlerList print_handler;
482
483
HashMap<String, Ref<Texture2D>> icon_type_cache;
484
HashMap<Pair<String, String>, Ref<Texture2D>> class_icon_cache;
485
486
ProjectUpgradeTool *project_upgrade_tool = nullptr;
487
bool run_project_upgrade_tool = false;
488
489
bool was_window_windowed_last = false;
490
491
bool unfocused_low_processor_usage_mode_enabled = true;
492
493
static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
494
static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
495
static int build_callback_count;
496
static int plugin_init_callback_count;
497
static Vector<EditorNodeInitCallback> _init_callbacks;
498
499
String _get_system_info() const;
500
501
bool _should_display_update_spinner() const;
502
503
static void _dependency_error_report(const String &p_path, const String &p_dep, const String &p_type) {
504
DEV_ASSERT(Thread::get_caller_id() == Thread::get_main_id());
505
if (!singleton->dependency_errors.has(p_path)) {
506
singleton->dependency_errors[p_path] = HashSet<String>();
507
}
508
singleton->dependency_errors[p_path].insert(p_dep + "::" + p_type);
509
}
510
511
static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
512
static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
513
static void _file_dialog_thumbnail_callback(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, Ref<ImageTexture> p_texture);
514
Ref<ImageTexture> default_thumbnail;
515
516
static void _file_dialog_register(FileDialog *p_dialog);
517
static void _file_dialog_unregister(FileDialog *p_dialog);
518
519
static void _file_access_close_error_notify(const String &p_str);
520
static void _file_access_close_error_notify_impl(const String &p_str);
521
522
static void _print_handler(void *p_this, const String &p_string, bool p_error, bool p_rich);
523
static void _print_handler_impl(const String &p_string, bool p_error, bool p_rich);
524
static void _resource_saved(Ref<Resource> p_resource, const String &p_path);
525
static void _resource_loaded(Ref<Resource> p_resource, const String &p_path);
526
527
void _update_theme(bool p_skip_creation = false);
528
void _build_icon_type_cache();
529
void _enable_pending_addons();
530
531
void _dialog_action(String p_file);
532
533
void _add_to_history(const Object *p_object, const String &p_property, bool p_inspector_only);
534
void _edit_current(bool p_skip_foreign = false, bool p_skip_inspector_update = false);
535
void _dialog_display_save_error(String p_file, Error p_error);
536
void _dialog_display_load_error(String p_file, Error p_error);
537
538
void _menu_option(int p_option);
539
void _menu_confirm_current();
540
void _menu_option_confirm(int p_option, bool p_confirmed);
541
542
void _android_build_source_selected(const String &p_file);
543
void _android_export_preset_selected(int p_index);
544
void _android_install_build_template();
545
void _android_explore_build_templates();
546
547
void _request_screenshot();
548
void _screenshot(bool p_use_utc = false);
549
void _save_screenshot(const String &p_path);
550
void _save_screenshot_with_embedded_process(int64_t p_w, int64_t p_h, const String &p_emb_path, const Rect2i &p_rect, const String &p_path);
551
552
void _check_system_theme_changed();
553
554
void _tool_menu_option(int p_idx);
555
void _export_as_menu_option(int p_idx);
556
void _update_file_menu_opened();
557
void _palette_quick_open_dialog();
558
559
void _remove_plugin_from_enabled(const String &p_name);
560
void _plugin_over_edit(EditorPlugin *p_plugin, Object *p_object);
561
void _plugin_over_self_own(EditorPlugin *p_plugin);
562
563
void _fs_changed();
564
void _resources_reimporting(const Vector<String> &p_resources);
565
void _resources_reimported(const Vector<String> &p_resources);
566
void _sources_changed(bool p_exist);
567
void _remove_lock_file();
568
569
void _node_renamed();
570
void _save_editor_states(const String &p_file, int p_idx = -1);
571
void _load_editor_plugin_states_from_config(const Ref<ConfigFile> &p_config_file);
572
void _update_title();
573
void _update_unsaved_cache();
574
void _version_control_menu_option(int p_idx);
575
void _close_messages();
576
void _show_messages();
577
void _vp_resized();
578
void _titlebar_resized();
579
void _viewport_resized();
580
581
void _update_undo_redo_allowed();
582
583
int _save_external_resources(bool p_also_save_external_data = false);
584
void _save_scene_silently();
585
586
void _set_current_scene(int p_idx);
587
void _set_current_scene_nocheck(int p_idx);
588
void _nav_to_selected_scene();
589
bool _validate_scene_recursive(const String &p_filename, Node *p_node);
590
void _save_scene(String p_file, int idx = -1);
591
void _save_all_scenes();
592
int _next_unsaved_scene(bool p_valid_filename, int p_start = 0);
593
void _discard_changes(const String &p_str = String());
594
void _scene_tab_closed(int p_tab);
595
void _cancel_close_scene_tab();
596
void _cancel_confirmation();
597
598
void _prepare_save_confirmation_popup();
599
600
void _inherit_request(String p_file);
601
void _instantiate_request(const Vector<String> &p_files);
602
603
void _quick_opened(const String &p_file_path);
604
void _open_command_palette();
605
606
void _project_run_started();
607
void _project_run_stopped();
608
609
void _update_prev_closed_scenes(const String &p_scene_path, bool p_add_scene);
610
611
void _add_to_recent_scenes(const String &p_scene);
612
void _update_recent_scenes();
613
void _open_recent_scene(int p_idx);
614
615
void _dropped_files(const Vector<String> &p_files);
616
void _add_dropped_files_recursive(const Vector<String> &p_files, String to_path);
617
618
void _update_vsync_mode();
619
void _update_from_settings();
620
void _gdextensions_reloaded();
621
void _update_translations();
622
void _translation_resources_changed();
623
void _queue_translation_notification();
624
void _propagate_translation_notification();
625
626
void _renderer_selected(int p_index);
627
void _update_renderer_color();
628
String _to_rendering_method_display_name(const String &p_rendering_method) const;
629
void _set_renderer_name_save_and_restart(const String &p_rendering_method);
630
631
void _exit_editor(int p_exit_code);
632
633
virtual void input(const Ref<InputEvent> &p_event) override;
634
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
635
636
bool has_main_screen() const { return true; }
637
638
void _remove_edited_scene(bool p_change_tab = true);
639
void _remove_scene(int index, bool p_change_tab = true);
640
bool _find_and_save_resource(Ref<Resource> p_res, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
641
bool _find_and_save_edited_subresources(Object *obj, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
642
void _save_edited_subresources(Node *scene, HashMap<Ref<Resource>, bool> &processed, int32_t flags);
643
void _mark_unsaved_scenes();
644
bool _is_scene_unsaved(int p_idx);
645
646
void _find_node_types(Node *p_node, int &count_2d, int &count_3d);
647
void _save_scene_with_preview(String p_file, int p_idx = -1);
648
void _close_save_scene_progress();
649
650
bool _find_scene_in_use(Node *p_node, const String &p_path) const;
651
652
void _proceed_closing_scene_tabs();
653
void _proceed_save_asing_scene_tabs();
654
bool _is_closing_editor() const;
655
void _restart_editor(bool p_goto_project_manager = false);
656
657
Dictionary _get_main_scene_state();
658
void _set_main_scene_state(Dictionary p_state, Node *p_for_scene);
659
660
void _save_editor_layout();
661
void _load_editor_layout();
662
663
void _save_central_editor_layout_to_config(Ref<ConfigFile> p_config_file);
664
void _load_central_editor_layout_from_config(Ref<ConfigFile> p_config_file);
665
666
void _save_window_settings_to_config(Ref<ConfigFile> p_layout, const String &p_section);
667
668
void _save_open_scenes_to_config(Ref<ConfigFile> p_layout);
669
void _load_open_scenes_from_config(Ref<ConfigFile> p_layout);
670
671
void _update_layouts_menu();
672
void _layout_menu_option(int p_id);
673
674
void _update_addon_config();
675
676
void _toggle_distraction_free_mode();
677
678
void _inherit_imported(const String &p_action);
679
void _open_imported();
680
681
void _update_update_spinner();
682
683
void _resources_changed(const Vector<String> &p_resources);
684
void _scan_external_changes();
685
void _reload_modified_scenes();
686
void _reload_project_settings();
687
void _resave_externally_modified_scenes(String p_str);
688
689
void _feature_profile_changed();
690
bool _is_class_editor_disabled_by_feature_profile(const StringName &p_class);
691
692
Ref<Texture2D> _get_class_or_script_icon(const String &p_class, const String &p_script_path, const String &p_fallback = "", bool p_fallback_script_to_theme = false, bool p_skip_fallback_virtual = false);
693
694
void _pick_main_scene_custom_action(const String &p_custom_action_name);
695
696
void _immediate_dialog_confirmed();
697
698
void _begin_first_scan();
699
700
void _notify_nodes_scene_reimported(Node *p_node, Array p_reimported_nodes);
701
702
void _remove_all_not_owned_children(Node *p_node, Node *p_owner);
703
704
void _progress_dialog_visibility_changed();
705
void _load_error_dialog_visibility_changed();
706
707
void _execute_upgrades();
708
709
bool _is_project_data_missing();
710
711
enum MenuType {
712
MENU_TYPE_NONE,
713
MENU_TYPE_GLOBAL,
714
MENU_TYPE_COMPACT,
715
MENU_TYPE_FULL,
716
};
717
MenuType menu_type = MENU_TYPE_NONE;
718
Vector<PopupMenu *> main_menu_items;
719
720
void _build_file_menu();
721
void _build_project_menu();
722
void _build_settings_menu();
723
void _build_help_menu();
724
725
void _update_main_menu_type();
726
void _add_to_main_menu(const String &p_name, PopupMenu *p_menu);
727
728
void _bottom_panel_resized();
729
730
protected:
731
friend class FileSystemDock;
732
733
static void _bind_methods();
734
void _notification(int p_what);
735
736
public:
737
// Public for use with callable_mp.
738
void init_plugins();
739
void _on_plugin_ready(Object *p_script, const String &p_activate_name);
740
741
bool call_build();
742
void call_run_scene(const String &p_scene, Vector<String> &r_args);
743
744
// This is a very naive estimation, but we need something now. Will be reworked later.
745
bool is_editor_ready() const { return is_inside_tree() && !waiting_for_first_scan; }
746
747
static EditorNode *get_singleton() { return singleton; }
748
749
static EditorLog *get_log() { return singleton->log; }
750
static EditorData &get_editor_data() { return singleton->editor_data; }
751
static EditorFolding &get_editor_folding() { return singleton->editor_folding; }
752
753
static EditorTitleBar *get_title_bar() { return singleton->title_bar; }
754
static VSplitContainer *get_top_split() { return singleton->top_split; }
755
static DockSplitContainer *get_center_split() { return singleton->center_split; }
756
static EditorBottomPanel *get_bottom_panel() { return singleton->bottom_panel; }
757
static EditorMainScreen *get_editor_main_screen() { return singleton->editor_main_screen; }
758
759
static Button *get_distraction_free_button() { return singleton->distraction_free; }
760
761
static String adjust_scene_name_casing(const String &p_root_name);
762
static String adjust_script_name_casing(const String &p_file_name, ScriptLanguage::ScriptNameCasing p_auto_casing);
763
764
static bool has_unsaved_changes() { return singleton->unsaved_cache; }
765
static void disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames);
766
static void add_io_error(const String &p_error);
767
static void add_io_warning(const String &p_warning);
768
static bool find_recursive_resources(const Variant &p_variant, HashSet<Resource *> &r_resources_found);
769
770
static void progress_add_task(const String &p_task, const String &p_label, int p_steps, bool p_can_cancel = false);
771
static bool progress_task_step(const String &p_task, const String &p_state, int p_step = -1, bool p_force_refresh = true);
772
static void progress_end_task(const String &p_task);
773
774
static void progress_add_task_bg(const String &p_task, const String &p_label, int p_steps);
775
static void progress_task_step_bg(const String &p_task, int p_step = -1);
776
static void progress_end_task_bg(const String &p_task);
777
778
static void add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
779
static void remove_editor_plugin(EditorPlugin *p_editor, bool p_config_changed = false);
780
781
static void add_extension_editor_plugin(const StringName &p_class_name);
782
static void remove_extension_editor_plugin(const StringName &p_class_name);
783
784
static void add_plugin_init_callback(EditorPluginInitializeCallback p_callback);
785
static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); }
786
static void add_build_callback(EditorBuildCallback p_callback);
787
788
static bool immediate_confirmation_dialog(const String &p_text, const String &p_ok_text = TTR("Ok"), const String &p_cancel_text = TTR("Cancel"), uint32_t p_wrap_width = 0);
789
790
static bool is_cmdline_mode();
791
792
static HashMap<String, Variant> get_initial_settings();
793
794
static void cleanup();
795
796
Ref<Texture2D> get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const;
797
798
EditorPluginList *get_editor_plugins_force_input_forwarding() { return editor_plugins_force_input_forwarding; }
799
EditorPluginList *get_editor_plugins_force_over() { return editor_plugins_force_over; }
800
EditorPluginList *get_editor_plugins_over() { return editor_plugins_over; }
801
EditorSelection *get_editor_selection() { return editor_selection; }
802
EditorSelectionHistory *get_editor_selection_history() { return &editor_history; }
803
804
ProjectSettingsEditor *get_project_settings() { return project_settings_editor; }
805
806
void trigger_menu_option(int p_option, bool p_confirmed);
807
bool has_previous_closed_scenes() const;
808
809
void new_inherited_scene() { _menu_option_confirm(SCENE_NEW_INHERITED_SCENE, false); }
810
811
void update_distraction_free_mode();
812
void set_distraction_free_mode(bool p_enter);
813
bool is_distraction_free_mode_enabled() const;
814
void update_distraction_free_button_theme();
815
816
void set_center_split_offset(int p_offset);
817
818
void set_addon_plugin_enabled(const String &p_addon, bool p_enabled, bool p_config_changed = false);
819
bool is_addon_plugin_enabled(const String &p_addon) const;
820
821
void edit_node(Node *p_node);
822
void edit_resource(const Ref<Resource> &p_resource);
823
824
void save_resource_in_path(const Ref<Resource> &p_resource, const String &p_path);
825
void save_resource(const Ref<Resource> &p_resource);
826
void save_resource_as(const Ref<Resource> &p_resource, const String &p_at_path = String());
827
bool is_resource_internal_to_scene(Ref<Resource> p_resource);
828
void gather_resources(const Variant &p_variant, List<Ref<Resource>> &r_list, bool p_subresources = false, bool p_allow_external = false);
829
void update_resource_count(Node *p_node, bool p_remove = false);
830
void update_node_reference(const Variant &p_value, Node *p_node, bool p_remove = false);
831
void clear_node_reference(Ref<Resource> p_res);
832
int get_resource_count(Ref<Resource> p_res);
833
List<Node *> get_resource_node_list(Ref<Resource> p_res);
834
835
void show_about() { _menu_option_confirm(HELP_ABOUT, false); }
836
837
void push_item(Object *p_object, const String &p_property = "", bool p_inspector_only = false);
838
void push_item_no_inspector(Object *p_object);
839
void edit_previous_item();
840
void edit_item(Object *p_object, Object *p_editing_owner);
841
void push_node_item(Node *p_node);
842
void hide_unused_editors(const Object *p_editing_owner = nullptr);
843
844
void replace_resources_in_object(
845
Object *p_object,
846
const Vector<Ref<Resource>> &p_source_resources,
847
const Vector<Ref<Resource>> &p_target_resource);
848
void replace_resources_in_scenes(
849
const Vector<Ref<Resource>> &p_source_resources,
850
const Vector<Ref<Resource>> &p_target_resource);
851
void edit_foreign_resource(Ref<Resource> p_resource);
852
853
bool is_resource_read_only(Ref<Resource> p_resource, bool p_foreign_resources_are_writable = false);
854
855
String get_multiwindow_support_tooltip_text() const;
856
857
bool is_changing_scene() const;
858
859
SubViewport *get_scene_root() { return scene_root; } // Root of the scene being edited.
860
861
void set_edited_scene(Node *p_scene);
862
void set_edited_scene_root(Node *p_scene, bool p_auto_add);
863
Node *get_edited_scene() { return editor_data.get_edited_scene_root(); }
864
865
String get_preview_locale() const;
866
void set_preview_locale(const String &p_locale);
867
868
int new_scene();
869
Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_force_open_imported = false, bool p_silent_change_tab = false);
870
Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false);
871
Error load_scene_or_resource(const String &p_file, bool p_ignore_broken_deps = false, bool p_change_scene_tab_if_already_open = true);
872
873
HashMap<StringName, Variant> get_modified_properties_for_node(Node *p_node, bool p_node_references_only);
874
HashMap<StringName, Variant> get_modified_properties_reference_to_nodes(Node *p_node, List<Node *> &p_nodes_referenced_by);
875
876
void set_unfocused_low_processor_usage_mode_enabled(bool p_enabled);
877
878
struct AdditiveNodeEntry {
879
Node *node = nullptr;
880
NodePath parent;
881
Node *owner = nullptr;
882
int index = 0;
883
// Used if the original parent node is lost
884
Transform2D transform_2d;
885
Transform3D transform_3d;
886
};
887
888
struct ConnectionWithNodePath {
889
Connection connection;
890
NodePath node_path;
891
};
892
893
struct ModificationNodeEntry {
894
HashMap<StringName, Variant> property_table;
895
List<ConnectionWithNodePath> connections_to;
896
List<Connection> connections_from;
897
List<Node::GroupInfo> groups;
898
};
899
900
struct InstanceModificationsEntry {
901
Node *original_node;
902
String instance_path;
903
List<Node *> instance_list;
904
HashMap<NodePath, ModificationNodeEntry> modifications;
905
List<AdditiveNodeEntry> addition_list;
906
};
907
908
struct SceneModificationsEntry {
909
List<InstanceModificationsEntry> instance_list;
910
HashMap<NodePath, ModificationNodeEntry> other_instances_modifications;
911
};
912
913
struct SceneEditorDataEntry {
914
bool is_editable = false;
915
bool is_display_folded = false;
916
};
917
918
HashMap<int, SceneModificationsEntry> scenes_modification_table;
919
List<String> scenes_reimported;
920
List<String> resources_reimported;
921
922
void update_node_from_node_modification_entry(Node *p_node, ModificationNodeEntry &p_node_modification);
923
924
void get_scene_editor_data_for_node(Node *p_root, Node *p_node, HashMap<NodePath, SceneEditorDataEntry> &p_table);
925
926
void get_preload_scene_modification_table(
927
Node *p_edited_scene,
928
Node *p_reimported_root,
929
Node *p_node, InstanceModificationsEntry &p_instance_modifications);
930
931
void get_preload_modifications_reference_to_nodes(
932
Node *p_root,
933
Node *p_node,
934
HashSet<Node *> &p_excluded_nodes,
935
List<Node *> &p_instance_list_with_children,
936
HashMap<NodePath, ModificationNodeEntry> &p_modification_table);
937
void get_children_nodes(Node *p_node, List<Node *> &p_nodes);
938
bool is_additional_node_in_scene(Node *p_edited_scene, Node *p_reimported_root, Node *p_node);
939
940
void replace_history_reimported_nodes(Node *p_original_root_node, Node *p_new_root_node, Node *p_node);
941
942
bool is_scene_open(const String &p_path);
943
bool is_multi_window_enabled() const;
944
945
void setup_color_picker(ColorPicker *p_picker);
946
947
void request_instantiate_scene(const String &p_path);
948
void request_instantiate_scenes(const Vector<String> &p_files);
949
950
void set_convert_old_scene(bool p_old) { convert_old = p_old; }
951
952
void notify_all_debug_sessions_exited();
953
954
OS::ProcessID has_child_process(OS::ProcessID p_pid) const;
955
void stop_child_process(OS::ProcessID p_pid);
956
957
Ref<Theme> get_editor_theme() const { return theme; }
958
void update_preview_themes(int p_mode);
959
960
Ref<Script> get_object_custom_type_base(const Object *p_object) const;
961
StringName get_object_custom_type_name(const Object *p_object) const;
962
Ref<Texture2D> get_object_icon(const Object *p_object, const String &p_fallback = "");
963
Ref<Texture2D> get_class_icon(const String &p_class, const String &p_fallback = "");
964
965
bool is_object_of_custom_type(const Object *p_object, const StringName &p_class);
966
967
void show_accept(const String &p_text, const String &p_title);
968
void show_save_accept(const String &p_text, const String &p_title);
969
void show_warning(const String &p_text, const String &p_title = TTR("Warning!"));
970
971
void _copy_warning(const String &p_str);
972
973
Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only, bool p_android_build_template, bool p_patch, const Vector<String> &p_patches);
974
bool is_project_exporting() const;
975
976
Control *get_gui_base() { return gui_base; }
977
978
void save_scene_to_path(String p_file, bool p_with_preview = true) {
979
if (p_with_preview) {
980
_save_scene_with_preview(p_file);
981
} else {
982
_save_scene(p_file);
983
}
984
}
985
986
bool close_scene();
987
988
bool is_scene_in_use(const String &p_path);
989
990
void save_editor_layout_delayed();
991
void save_default_environment();
992
993
void open_export_template_manager();
994
995
void reload_scene(const String &p_path);
996
997
void find_all_instances_inheriting_path_in_node(Node *p_root, Node *p_node, const String &p_instance_path, HashSet<Node *> &p_instance_list);
998
void preload_reimporting_with_path_in_edited_scenes(const List<String> &p_scenes);
999
void reload_instances_with_path_in_edited_scenes();
1000
1001
bool is_exiting() const { return exiting; }
1002
1003
Dictionary drag_resource(const Ref<Resource> &p_res, Control *p_from);
1004
Dictionary drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from);
1005
1006
EditorQuickOpenDialog *get_quick_open_dialog() { return quick_open_dialog; }
1007
1008
void add_tool_menu_item(const String &p_name, const Callable &p_callback);
1009
void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu);
1010
void remove_tool_menu_item(const String &p_name);
1011
1012
PopupMenu *get_export_as_menu();
1013
1014
void save_all_scenes();
1015
void save_scene_if_open(const String &p_scene_path);
1016
void save_scene_list(const HashSet<String> &p_scene_paths);
1017
void save_before_run();
1018
void try_autosave();
1019
void restart_editor(bool p_goto_project_manager = false);
1020
void unload_editor_addons();
1021
1022
void open_setting_override(const String &p_property);
1023
void notify_settings_overrides_changed();
1024
1025
void dim_editor(bool p_dimming);
1026
bool is_editor_dimmed() const;
1027
1028
void edit_current() { _edit_current(); }
1029
1030
bool has_scenes_in_session();
1031
1032
void undo();
1033
void redo();
1034
1035
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, String *r_output = nullptr);
1036
1037
EditorNode();
1038
~EditorNode();
1039
1040
void add_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
1041
void remove_resource_conversion_plugin(const Ref<EditorResourceConversionPlugin> &p_plugin);
1042
Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_resource(const Ref<Resource> &p_for_resource);
1043
Vector<Ref<EditorResourceConversionPlugin>> find_resource_conversion_plugin_for_type_name(const String &p_type);
1044
1045
bool ensure_main_scene(bool p_from_native);
1046
bool validate_custom_directory();
1047
void run_editor_script(const Ref<Script> &p_script);
1048
};
1049
1050
struct EditorProgressBG {
1051
String task;
1052
void step(int p_step = -1) { EditorNode::progress_task_step_bg(task, p_step); }
1053
EditorProgressBG(const String &p_task, const String &p_label, int p_amount) {
1054
EditorNode::progress_add_task_bg(p_task, p_label, p_amount);
1055
task = p_task;
1056
}
1057
~EditorProgressBG() { EditorNode::progress_end_task_bg(task); }
1058
};
1059
1060