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