Debian Codegraph @

editor/project_manager/project_dialog.cpp

raw symbols SCIP
1 /**************************************************************************/
2 /* project_dialog.cpp */
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 #include "project_dialog.h"
32
33 #include "core/config/project_settings.h"
34 #include "core/io/dir_access.h"
35 #include "core/io/zip_io.h"
36 #include "core/version.h"
37 #include "editor/editor_node.h"
38 #include "editor/editor_string_names.h"
39 #include "editor/gui/editor_file_dialog.h"
40 #include "editor/settings/editor_settings.h"
41 #include "editor/themes/editor_icons.h"
42 #include "editor/themes/editor_scale.h"
43 #include "editor/version_control/editor_vcs_interface.h"
44 #include "scene/gui/check_box.h"
45 #include "scene/gui/check_button.h"
46 #include "scene/gui/line_edit.h"
47 #include "scene/gui/link_button.h"
48 #include "scene/gui/option_button.h"
49 #include "scene/gui/separator.h"
50 #include "scene/gui/texture_rect.h"
51
52 void ProjectDialog::_set_message(const String &p_msg, MessageType p_type, InputType p_input_type) {
53 msg->set_text(p_msg);
54
55 if (p_type == MESSAGE_ERROR) {
56 invalid_state_flags.set_flag(InvalidStateFlag::INVALID_STATE_FLAG_PATH_INPUT);
57 } else {
58 invalid_state_flags.clear_flag(InvalidStateFlag::INVALID_STATE_FLAG_PATH_INPUT);
59 }
60
61 Ref<Texture2D> new_icon;
62 switch (p_type) {
63 case MESSAGE_ERROR: {
64 msg->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
65 new_icon = get_editor_theme_icon(SNAME("StatusError"));
66 } break;
67 case MESSAGE_WARNING: {
68 msg->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("warning_color"), EditorStringName(Editor)));
69 new_icon = get_editor_theme_icon(SNAME("StatusWarning"));
70 } break;
71 case MESSAGE_SUCCESS: {
72 msg->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("success_color"), EditorStringName(Editor)));
73 new_icon = get_editor_theme_icon(SNAME("StatusSuccess"));
74 } break;
75 }
76
77 if (p_input_type == PROJECT_PATH) {
78 project_status_rect->set_texture(new_icon);
79 } else if (p_input_type == INSTALL_PATH) {
80 install_status_rect->set_texture(new_icon);
81 }
82
83 _update_ok_button();
84 }
85
86 void ProjectDialog::_update_ok_button() {
87 get_ok_button()->set_disabled(!invalid_state_flags.is_empty());
88 }
89
90 static bool is_zip_file(Ref<DirAccess> p_d, const String &p_path) {
91 return p_path.get_extension() == "zip" && p_d->file_exists(p_path);
92 }
93
94 void ProjectDialog::_validate_path() {
95 _set_message("", MESSAGE_SUCCESS, PROJECT_PATH);
96 _set_message("", MESSAGE_SUCCESS, INSTALL_PATH);
97
98 if (project_name->get_text().strip_edges().is_empty()) {
99 _set_message(TTRC("It would be a good idea to name your project."), MESSAGE_ERROR);
100 return;
101 }
102
103 Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
104 String path = project_path->get_text().simplify_path();
105
106 String target_path = path;
107 InputType target_path_input_type = PROJECT_PATH;
108
109 if (mode == MODE_IMPORT) {
110 if (path.get_file().strip_edges() == "project.godot") {
111 path = path.get_base_dir();
112 project_path->set_text(path);
113 }
114
115 if (is_zip_file(d, path)) {
116 zip_path = path;
117 } else if (is_zip_file(d, path.strip_edges())) {
118 zip_path = path.strip_edges();
119 } else {
120 zip_path = "";
121 }
122
123 if (!zip_path.is_empty()) {
124 target_path = install_path->get_text().simplify_path();
125 target_path_input_type = INSTALL_PATH;
126
127 create_dir->show();
128 install_path_container->show();
129
130 Ref<FileAccess> io_fa;
131 zlib_filefunc_def io = zipio_create_io(&io_fa);
132
133 unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io);
134 if (!pkg) {
135 _set_message(TTRC("Invalid \".zip\" project file; it is not in ZIP format."), MESSAGE_ERROR);
136 unzClose(pkg);
137 return;
138 }
139
140 int ret = unzGoToFirstFile(pkg);
141 while (ret == UNZ_OK) {
142 unz_file_info info;
143 char fname[16384];
144 ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
145 ERR_FAIL_COND_MSG(ret != UNZ_OK, "Failed to get current file info.");
146
147 String name = String::utf8(fname);
148
149 // Skip the __MACOSX directory created by macOS's built-in file zipper.
150 if (name.begins_with("__MACOSX")) {
151 ret = unzGoToNextFile(pkg);
152 continue;
153 }
154
155 if (name.get_file() == "project.godot") {
156 break; // ret == UNZ_OK.
157 }
158
159 ret = unzGoToNextFile(pkg);
160 }
161
162 if (ret == UNZ_END_OF_LIST_OF_FILE) {
163 _set_message(TTRC("Invalid \".zip\" project file; it doesn't contain a \"project.godot\" file."), MESSAGE_ERROR);
164 unzClose(pkg);
165 return;
166 }
167
168 unzClose(pkg);
169 } else if (d->dir_exists(path) && d->file_exists(path.path_join("project.godot"))) {
170 zip_path = "";
171
172 create_dir->hide();
173 install_path_container->hide();
174
175 _set_message(TTRC("Valid project found at path."), MESSAGE_SUCCESS);
176 } else {
177 create_dir->hide();
178 install_path_container->hide();
179
180 _set_message(TTRC("Please choose a \"project.godot\", a directory with one, or a \".zip\" file."), MESSAGE_ERROR);
181 return;
182 }
183 }
184
185 if (target_path.is_relative_path()) {
186 _set_message(TTRC("The path specified is invalid."), MESSAGE_ERROR, target_path_input_type);
187 return;
188 }
189
190 if (target_path.get_file() != OS::get_singleton()->get_safe_dir_name(target_path.get_file())) {
191 _set_message(TTRC("The directory name specified contains invalid characters or trailing whitespace."), MESSAGE_ERROR, target_path_input_type);
192 return;
193 }
194
195 String working_dir = d->get_current_dir();
196 String executable_dir = OS::get_singleton()->get_executable_path().get_base_dir();
197 if (target_path == working_dir || target_path == executable_dir) {
198 _set_message(TTRC("Creating a project at the engine's working directory or executable directory is not allowed, as it would prevent the project manager from starting."), MESSAGE_ERROR, target_path_input_type);
199 return;
200 }
201
202 // TODO: The following 5 lines could be simplified if OS.get_user_home_dir() or SYSTEM_DIR_HOME is implemented. See: https://github.com/godotengine/godot-proposals/issues/4851.
203 #ifdef WINDOWS_ENABLED
204 String home_dir = OS::get_singleton()->get_environment("USERPROFILE");
205 #else
206 String home_dir = OS::get_singleton()->get_environment("HOME");
207 #endif
208 String documents_dir = OS::get_singleton()->get_system_dir(OS::SYSTEM_DIR_DOCUMENTS);
209 if (target_path == home_dir || target_path == documents_dir) {
210 _set_message(TTRC("You cannot save a project at the selected path. Please create a subfolder or choose a new path."), MESSAGE_ERROR, target_path_input_type);
211 return;
212 }
213
214 is_folder_empty = true;
215 if (mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE || (mode == MODE_IMPORT && target_path_input_type == InputType::INSTALL_PATH)) {
216 if (create_dir->is_pressed()) {
217 if (!d->dir_exists(target_path.get_base_dir())) {
218 _set_message(TTRC("The parent directory of the path specified doesn't exist."), MESSAGE_ERROR, target_path_input_type);
219 return;
220 }
221
222 if (d->dir_exists(target_path)) {
223 // The path is not necessarily empty here, but we will update the message later if it isn't.
224 _set_message(TTRC("The project folder already exists and is empty."), MESSAGE_SUCCESS, target_path_input_type);
225 } else {
226 _set_message(TTRC("The project folder will be automatically created."), MESSAGE_SUCCESS, target_path_input_type);
227 }
228 } else {
229 if (!d->dir_exists(target_path)) {
230 _set_message(TTRC("The path specified doesn't exist."), MESSAGE_ERROR, target_path_input_type);
231 return;
232 }
233
234 // The path is not necessarily empty here, but we will update the message later if it isn't.
235 _set_message(TTRC("The project folder exists and is empty."), MESSAGE_SUCCESS, target_path_input_type);
236 }
237
238 // Check if the directory is empty. Not an error, but we want to warn the user.
239 if (d->change_dir(target_path) == OK) {
240 d->list_dir_begin();
241 String n = d->get_next();
242 while (!n.is_empty()) {
243 if (n[0] != '.') {
244 // Allow `.`, `..` (reserved current/parent folder names)
245 // and hidden files/folders to be present.
246 // For instance, this lets users initialize a Git repository
247 // and still be able to create a project in the directory afterwards.
248 is_folder_empty = false;
249 break;
250 }
251 n = d->get_next();
252 }
253 d->list_dir_end();
254
255 if (!is_folder_empty) {
256 _set_message(TTRC("The selected path is not empty. Choosing an empty folder is highly recommended."), MESSAGE_WARNING, target_path_input_type);
257 }
258 }
259 }
260
261 // Check if the target path is a subdirectory of original when duplicating
262 if (mode == MODE_DUPLICATE) {
263 String base_path = original_project_path;
264 String duplicate_target = target_path;
265
266 // Ensure the paths end with a slash
267 if (!base_path.ends_with("/")) {
268 base_path += "/";
269 }
270
271 if (!duplicate_target.ends_with("/")) {
272 duplicate_target += "/";
273 }
274
275 bool is_subdirectory_or_equal;
276
277 if (d->is_case_sensitive(base_path) || d->is_case_sensitive(duplicate_target)) {
278 is_subdirectory_or_equal = duplicate_target.begins_with(base_path);
279 } else {
280 base_path = base_path.to_lower();
281 String target_lower = duplicate_target.to_lower();
282 is_subdirectory_or_equal = target_lower.begins_with(base_path);
283 }
284
285 if (is_subdirectory_or_equal) {
286 _set_message(TTRC("Cannot duplicate a project into itself."), MESSAGE_ERROR, target_path_input_type);
287 }
288 }
289 }
290
291 String ProjectDialog::_get_target_path() {
292 if (mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE) {
293 return project_path->get_text();
294 } else if (mode == MODE_IMPORT) {
295 return install_path->get_text();
296 } else {
297 ERR_FAIL_V("");
298 }
299 }
300 void ProjectDialog::_set_target_path(const String &p_text) {
301 if (mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE) {
302 project_path->set_text(p_text);
303 } else if (mode == MODE_IMPORT) {
304 install_path->set_text(p_text);
305 } else {
306 ERR_FAIL();
307 }
308 }
309
310 void ProjectDialog::_update_target_auto_dir() {
311 String new_auto_dir;
312 if (mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE) {
313 new_auto_dir = project_name->get_text();
314 } else if (mode == MODE_IMPORT) {
315 new_auto_dir = project_path->get_text().get_file().get_basename();
316 }
317 int naming_convention = (int)EDITOR_GET("project_manager/directory_naming_convention");
318 switch (naming_convention) {
319 case 0: // No Convention
320 break;
321 case 1: // kebab-case
322 new_auto_dir = new_auto_dir.to_kebab_case();
323 break;
324 case 2: // snake_case
325 new_auto_dir = new_auto_dir.to_snake_case();
326 break;
327 case 3: // camelCase
328 new_auto_dir = new_auto_dir.to_camel_case();
329 break;
330 case 4: // PascalCase
331 new_auto_dir = new_auto_dir.to_pascal_case();
332 break;
333 case 5: // Title Case
334 new_auto_dir = new_auto_dir.capitalize();
335 break;
336 default:
337 ERR_FAIL_MSG("Invalid directory naming convention.");
338 break;
339 }
340 new_auto_dir = OS::get_singleton()->get_safe_dir_name(new_auto_dir);
341
342 if (create_dir->is_pressed()) {
343 String target_path = _get_target_path();
344
345 if (target_path.get_file() == auto_dir) {
346 // Update target dir name to new project name / ZIP name.
347 target_path = target_path.get_base_dir().path_join(new_auto_dir);
348 }
349
350 _set_target_path(target_path);
351 }
352
353 auto_dir = new_auto_dir;
354 }
355
356 void ProjectDialog::_create_dir_toggled(bool p_pressed) {
357 String target_path = _get_target_path();
358
359 if (create_dir->is_pressed()) {
360 // (Re-)append target dir name.
361 if (last_custom_target_dir.is_empty()) {
362 target_path = target_path.path_join(auto_dir);
363 } else {
364 target_path = target_path.path_join(last_custom_target_dir);
365 }
366 } else {
367 // Strip any trailing slash.
368 target_path = target_path.rstrip("/\\");
369 // Save and remove target dir name.
370 if (target_path.get_file() == auto_dir) {
371 last_custom_target_dir = "";
372 } else {
373 last_custom_target_dir = target_path.get_file();
374 }
375 target_path = target_path.get_base_dir();
376 }
377
378 _set_target_path(target_path);
379 _validate_path();
380 }
381
382 void ProjectDialog::_project_name_changed() {
383 if (mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE) {
384 _update_target_auto_dir();
385 }
386
387 _validate_path();
388 }
389
390 void ProjectDialog::_project_path_changed() {
391 if (mode == MODE_IMPORT) {
392 _update_target_auto_dir();
393 }
394
395 _validate_path();
396 }
397
398 void ProjectDialog::_install_path_changed() {
399 _validate_path();
400 }
401
402 void ProjectDialog::_browse_project_path() {
403 String path = project_path->get_text();
404 if (path.is_relative_path()) {
405 path = EDITOR_GET("filesystem/directories/default_project_path");
406 }
407 if (mode == MODE_IMPORT && install_path->is_visible_in_tree()) {
408 // Select last ZIP file.
409 fdialog_project->set_current_path(path);
410 } else if ((mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE) && create_dir->is_pressed()) {
411 // Select parent directory of project path.
412 fdialog_project->set_current_dir(path.get_base_dir());
413 } else {
414 // Select project path.
415 fdialog_project->set_current_dir(path);
416 }
417
418 if (mode == MODE_IMPORT) {
419 fdialog_project->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_ANY);
420 fdialog_project->clear_filters();
421 fdialog_project->add_filter("project.godot", vformat("%s %s", GODOT_VERSION_NAME, TTR("Project")));
422 fdialog_project->add_filter("*.zip", TTR("ZIP File"));
423 } else {
424 fdialog_project->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
425 }
426
427 hide();
428 fdialog_project->popup_file_dialog();
429 }
430
431 void ProjectDialog::_browse_install_path() {
432 ERR_FAIL_COND_MSG(mode != MODE_IMPORT, "Install path is only used for MODE_IMPORT.");
433
434 String path = install_path->get_text();
435 if (path.is_relative_path() || !DirAccess::dir_exists_absolute(path)) {
436 path = EDITOR_GET("filesystem/directories/default_project_path");
437 }
438 if (create_dir->is_pressed()) {
439 // Select parent directory of install path.
440 fdialog_install->set_current_dir(path.get_base_dir());
441 } else {
442 // Select install path.
443 fdialog_install->set_current_dir(path);
444 }
445
446 fdialog_install->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
447 fdialog_install->popup_file_dialog();
448 }
449
450 void ProjectDialog::_project_path_selected(const String &p_path) {
451 show_dialog(false);
452
453 if (create_dir->is_pressed() && (mode == MODE_NEW || mode == MODE_INSTALL || mode == MODE_DUPLICATE)) {
454 // Replace parent directory, but keep target dir name.
455 project_path->set_text(p_path.path_join(project_path->get_text().get_file()));
456 } else {
457 project_path->set_text(p_path);
458 }
459
460 _project_path_changed();
461
462 if (install_path->is_visible_in_tree()) {
463 // ZIP is selected; focus install path.
464 install_path->grab_focus();
465 } else {
466 get_ok_button()->grab_focus();
467 }
468 }
469
470 void ProjectDialog::_install_path_selected(const String &p_path) {
471 ERR_FAIL_COND_MSG(mode != MODE_IMPORT, "Install path is only used for MODE_IMPORT.");
472
473 if (create_dir->is_pressed()) {
474 // Replace parent directory, but keep target dir name.
475 install_path->set_text(p_path.path_join(install_path->get_text().get_file()));
476 } else {
477 install_path->set_text(p_path);
478 }
479
480 _install_path_changed();
481
482 get_ok_button()->grab_focus();
483 }
484
485 void ProjectDialog::_reset_name() {
486 project_name->set_text(TTR("New Game Project"));
487 }
488
489 void ProjectDialog::_renderer_selected() {
490 ERR_FAIL_NULL(renderer_button_group->get_pressed_button());
491
492 String renderer_type = renderer_button_group->get_pressed_button()->get_meta(SNAME("rendering_method"));
493
494 bool rd_error = false;
495
496 if (renderer_type == "forward_plus") {
497 renderer_info->set_text(
498 String::utf8("• ") + TTR("Supports desktop platforms only.") +
499 String::utf8("\n• ") + TTR("Advanced 3D graphics available.") +
500 String::utf8("\n• ") + TTR("Can scale to large complex scenes.") +
501 String::utf8("\n• ") + TTR("Uses RenderingDevice backend.") +
502 String::utf8("\n• ") + TTR("Slower rendering of simple scenes."));
503 rd_error = !rendering_device_supported;
504 } else if (renderer_type == "mobile") {
505 renderer_info->set_text(
506 String::utf8("• ") + TTR("Supports desktop + mobile platforms.") +
507 String::utf8("\n• ") + TTR("Less advanced 3D graphics.") +
508 String::utf8("\n• ") + TTR("Less scalable for complex scenes.") +
509 String::utf8("\n• ") + TTR("Uses RenderingDevice backend.") +
510 String::utf8("\n• ") + TTR("Fast rendering of simple scenes."));
511 rd_error = !rendering_device_supported;
512 } else if (renderer_type == "gl_compatibility") {
513 renderer_info->set_text(
514 String::utf8("• ") + TTR("Supports desktop, mobile + web platforms.") +
515 String::utf8("\n• ") + TTR("Least advanced 3D graphics.") +
516 String::utf8("\n• ") + TTR("Intended for low-end/older devices.") +
517 String::utf8("\n• ") + TTR("Uses OpenGL 3 backend (OpenGL 3.3/ES 3.0/WebGL2).") +
518 String::utf8("\n• ") + TTR("Fastest rendering of simple scenes."));
519 } else {
520 WARN_PRINT("Unknown renderer type. Please report this as a bug on GitHub.");
521 }
522
523 rd_not_supported->set_visible(rd_error);
524 if (rd_error) {
525 // Needs to be set here since theme colors aren't available at startup.
526 rd_not_supported->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
527 invalid_state_flags.set_flag(InvalidStateFlag::INVALID_STATE_FLAG_RENDERER_SELECT);
528 } else {
529 invalid_state_flags.clear_flag(InvalidStateFlag::INVALID_STATE_FLAG_RENDERER_SELECT);
530 }
531
532 _update_ok_button();
533 }
534
535 void ProjectDialog::_nonempty_confirmation_ok_pressed() {
536 is_folder_empty = true;
537 ok_pressed();
538 }
539
540 void ProjectDialog::ok_pressed() {
541 // Before we create a project, check that the target folder is empty.
542 // If not, we need to ask the user if they're sure they want to do this.
543 if (!is_folder_empty) {
544 if (!nonempty_confirmation) {
545 nonempty_confirmation = memnew(ConfirmationDialog);
546 nonempty_confirmation->set_title(TTRC("Warning: This folder is not empty"));
547 nonempty_confirmation->set_text(TTRC("You are about to create a Godot project in a non-empty folder.\nThe entire contents of this folder will be imported as project resources!\n\nAre you sure you wish to continue?"));
548 nonempty_confirmation->get_ok_button()->connect(SceneStringName(pressed), callable_mp(this, &ProjectDialog::_nonempty_confirmation_ok_pressed));
549 add_child(nonempty_confirmation);
550 }
551 nonempty_confirmation->popup_centered();
552 return;
553 }
554
555 String path = project_path->get_text();
556
557 if (mode == MODE_NEW) {
558 if (create_dir->is_pressed()) {
559 Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
560 if (!d->dir_exists(path) && d->make_dir(path) != OK) {
561 _set_message(TTRC("Couldn't create project directory, check permissions."), MESSAGE_ERROR);
562 return;
563 }
564 }
565
566 PackedStringArray project_features = ProjectSettings::get_required_features();
567 ProjectSettings::CustomMap initial_settings;
568
569 // Be sure to change this code if/when renderers are changed.
570 // Default values are "forward_plus" for the main setting, "mobile" for the mobile override,
571 // and "gl_compatibility" for the web override.
572 String renderer_type = renderer_button_group->get_pressed_button()->get_meta(SNAME("rendering_method"));
573 initial_settings["rendering/renderer/rendering_method"] = renderer_type;
574
575 EditorSettings::get_singleton()->set("project_manager/default_renderer", renderer_type);
576 EditorSettings::get_singleton()->save();
577
578 if (renderer_type == "forward_plus") {
579 project_features.push_back("Forward Plus");
580 } else if (renderer_type == "mobile") {
581 project_features.push_back("Mobile");
582 } else if (renderer_type == "gl_compatibility") {
583 project_features.push_back("GL Compatibility");
584 // Also change the default renderer for the mobile override.
585 initial_settings["rendering/renderer/rendering_method.mobile"] = "gl_compatibility";
586 } else {
587 WARN_PRINT("Unknown renderer type. Please report this as a bug on GitHub.");
588 }
589
590 project_features.sort();
591 initial_settings["application/config/features"] = project_features;
592 initial_settings["application/config/name"] = project_name->get_text().strip_edges();
593 initial_settings["application/config/icon"] = "res://icon.svg";
594 ProjectSettings::CustomMap extra_settings = EditorNode::get_initial_settings();
595 for (const KeyValue<String, Variant> &extra_setting : extra_settings) {
596 // Merge with other initial settings defined above.
597 initial_settings[extra_setting.key] = extra_setting.value;
598 }
599
600 Error err = ProjectSettings::get_singleton()->save_custom(path.path_join("project.godot"), initial_settings, Vector<String>(), false);
601 if (err != OK) {
602 _set_message(TTRC("Couldn't create project.godot in project path."), MESSAGE_ERROR);
603 return;
604 }
605
606 // Store default project icon in SVG format.
607 Ref<FileAccess> fa_icon = FileAccess::open(path.path_join("icon.svg"), FileAccess::WRITE, &err);
608 if (err != OK) {
609 _set_message(TTRC("Couldn't create icon.svg in project path."), MESSAGE_ERROR);
610 return;
611 }
612 fa_icon->store_string(get_default_project_icon());
613
614 EditorVCSInterface::create_vcs_metadata_files(EditorVCSInterface::VCSMetadata(vcs_metadata_selection->get_selected()), path);
615
616 // Ensures external editors and IDEs use UTF-8 encoding.
617 const String editor_config_path = path.path_join(".editorconfig");
618 Ref<FileAccess> f = FileAccess::open(editor_config_path, FileAccess::WRITE);
619 if (f.is_null()) {
620 // .editorconfig isn't so critical.
621 ERR_PRINT("Couldn't create .editorconfig in project path.");
622 } else {
623 f->store_line("root = true");
624 f->store_line("");
625 f->store_line("[*]");
626 f->store_line("charset = utf-8");
627 f->close();
628 FileAccess::set_hidden_attribute(editor_config_path, true);
629 }
630 }
631
632 // Two cases for importing a ZIP.
633 switch (mode) {
634 case MODE_IMPORT: {
635 if (zip_path.is_empty()) {
636 break;
637 }
638
639 path = install_path->get_text().simplify_path();
640 [[fallthrough]];
641 }
642 case MODE_INSTALL: {
643 ERR_FAIL_COND(zip_path.is_empty());
644
645 Ref<FileAccess> io_fa;
646 zlib_filefunc_def io = zipio_create_io(&io_fa);
647
648 unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io);
649 if (!pkg) {
650 dialog_error->set_text(TTRC("Error opening package file, not in ZIP format."));
651 dialog_error->popup_centered();
652 return;
653 }
654
655 // Find the first directory with a "project.godot".
656 String zip_root;
657 int ret = unzGoToFirstFile(pkg);
658 while (ret == UNZ_OK) {
659 unz_file_info info;
660 char fname[16384];
661 unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
662 ERR_FAIL_COND_MSG(ret != UNZ_OK, "Failed to get current file info.");
663
664 String name = String::utf8(fname);
665
666 // Skip the __MACOSX directory created by macOS's built-in file zipper.
667 if (name.begins_with("__MACOSX")) {
668 ret = unzGoToNextFile(pkg);
669 continue;
670 }
671
672 if (name.get_file() == "project.godot") {
673 zip_root = name.get_base_dir();
674 break;
675 }
676
677 ret = unzGoToNextFile(pkg);
678 }
679
680 if (ret == UNZ_END_OF_LIST_OF_FILE) {
681 _set_message(TTRC("Invalid \".zip\" project file; it doesn't contain a \"project.godot\" file."), MESSAGE_ERROR);
682 unzClose(pkg);
683 return;
684 }
685
686 if (create_dir->is_pressed()) {
687 Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
688 if (!d->dir_exists(path) && d->make_dir(path) != OK) {
689 _set_message(TTRC("Couldn't create project directory, check permissions."), MESSAGE_ERROR);
690 return;
691 }
692 }
693
694 ret = unzGoToFirstFile(pkg);
695
696 Vector<String> failed_files;
697 while (ret == UNZ_OK) {
698 //get filename
699 unz_file_info info;
700 char fname[16384];
701 ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
702 ERR_FAIL_COND_MSG(ret != UNZ_OK, "Failed to get current file info.");
703
704 String name = String::utf8(fname);
705
706 // Skip the __MACOSX directory created by macOS's built-in file zipper.
707 if (name.begins_with("__MACOSX")) {
708 ret = unzGoToNextFile(pkg);
709 continue;
710 }
711
712 String rel_path = name.trim_prefix(zip_root);
713 if (rel_path.is_empty()) { // Root.
714 } else if (rel_path.ends_with("/")) { // Directory.
715 Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
716 da->make_dir(path.path_join(rel_path));
717 } else { // File.
718 Vector<uint8_t> uncomp_data;
719 uncomp_data.resize(info.uncompressed_size);
720
721 unzOpenCurrentFile(pkg);
722 ret = unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
723 ERR_BREAK_MSG(ret < 0, vformat("An error occurred while attempting to read from file: %s. This file will not be used.", rel_path));
724 unzCloseCurrentFile(pkg);
725
726 Ref<FileAccess> f = FileAccess::open(path.path_join(rel_path), FileAccess::WRITE);
727 if (f.is_valid()) {
728 f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
729 } else {
730 failed_files.push_back(rel_path);
731 }
732 }
733
734 ret = unzGoToNextFile(pkg);
735 }
736
737 unzClose(pkg);
738
739 if (failed_files.size()) {
740 String err_msg = TTR("The following files failed extraction from package:") + "\n\n";
741 for (int i = 0; i < failed_files.size(); i++) {
742 if (i > 15) {
743 err_msg += "\nAnd " + itos(failed_files.size() - i) + " more files.";
744 break;
745 }
746 err_msg += failed_files[i] + "\n";
747 }
748
749 dialog_error->set_text(err_msg);
750 dialog_error->popup_centered();
751 return;
752 }
753 } break;
754 default: {
755 } break;
756 }
757
758 if (mode == MODE_DUPLICATE) {
759 Ref<DirAccess> dir = DirAccess::open(original_project_path);
760 Error err = FAILED;
761 if (dir.is_valid()) {
762 err = dir->copy_dir(".", path, -1, true);
763 }
764 if (err != OK) {
765 dialog_error->set_text(vformat(TTR("Couldn't duplicate project (error %d)."), err));
766 dialog_error->popup_centered();
767 return;
768 }
769 }
770
771 if (mode == MODE_RENAME || mode == MODE_INSTALL || mode == MODE_DUPLICATE) {
772 // Load project.godot as ConfigFile to set the new name.
773 ConfigFile cfg;
774 String project_godot = path.path_join("project.godot");
775 Error err = cfg.load(project_godot);
776 if (err != OK) {
777 dialog_error->set_text(vformat(TTR("Couldn't load project at '%s' (error %d). It may be missing or corrupted."), project_godot, err));
778 dialog_error->popup_centered();
779 return;
780 }
781 cfg.set_value("application", "config/name", project_name->get_text().strip_edges());
782 err = cfg.save(project_godot);
783 if (err != OK) {
784 dialog_error->set_text(vformat(TTR("Couldn't save project at '%s' (error %d)."), project_godot, err));
785 dialog_error->popup_centered();
786 return;
787 }
788 }
789
790 hide();
791 if (mode == MODE_NEW || mode == MODE_IMPORT || mode == MODE_INSTALL) {
792 #ifdef ANDROID_ENABLED
793 // Create a .nomedia file to hide assets from media apps on Android.
794 // Android 11 has some issues with nomedia files, so it's disabled there. See GH-106479, GH-105399 for details.
795 // NOTE: Nomedia file is also handled during the first filesystem scan. See editor_file_system.cpp -> EditorFileSystem::scan().
796 String sdk_version = OS::get_singleton()->get_version().get_slicec('.', 0);
797 if (sdk_version != "30") {
798 const String nomedia_file_path = path.path_join(".nomedia");
799 Ref<FileAccess> f2 = FileAccess::open(nomedia_file_path, FileAccess::WRITE);
800 if (f2.is_null()) {
801 // .nomedia isn't so critical.
802 ERR_PRINT("Couldn't create .nomedia in project path.");
803 } else {
804 f2->close();
805 }
806 }
807 #endif
808 emit_signal(SNAME("project_created"), path, edit_check_box->is_pressed());
809 } else if (mode == MODE_DUPLICATE) {
810 emit_signal(SNAME("project_duplicated"), original_project_path, path, edit_check_box->is_visible() && edit_check_box->is_pressed());
811 } else if (mode == MODE_RENAME) {
812 emit_signal(SNAME("projects_updated"));
813 }
814 }
815
816 void ProjectDialog::set_zip_path(const String &p_path) {
817 zip_path = p_path;
818 }
819
820 void ProjectDialog::set_zip_title(const String &p_title) {
821 zip_title = p_title;
822 }
823
824 void ProjectDialog::set_original_project_path(const String &p_path) {
825 original_project_path = p_path;
826 }
827
828 void ProjectDialog::set_duplicate_can_edit(bool p_duplicate_can_edit) {
829 duplicate_can_edit = p_duplicate_can_edit;
830 }
831
832 void ProjectDialog::set_mode(Mode p_mode) {
833 mode = p_mode;
834 }
835
836 void ProjectDialog::set_project_name(const String &p_name) {
837 project_name->set_text(p_name);
838 }
839
840 void ProjectDialog::set_project_path(const String &p_path) {
841 project_path->set_text(p_path);
842 }
843
844 void ProjectDialog::ask_for_path_and_show() {
845 _reset_name();
846 _browse_project_path();
847 }
848
849 void ProjectDialog::show_dialog(bool p_reset_name, bool p_is_confirmed) {
850 _update_ok_button();
851
852 if (mode == MODE_IMPORT && !p_is_confirmed) {
853 return;
854 }
855 if (mode == MODE_RENAME) {
856 // Name and path are set in `ProjectManager::_rename_project`.
857 project_path->set_editable(false);
858
859 set_title(TTRC("Rename Project"));
860 set_ok_button_text(TTRC("Rename"));
861
862 create_dir->hide();
863 project_status_rect->hide();
864 project_browse->hide();
865 edit_check_box->hide();
866
867 name_container->show();
868 install_path_container->hide();
869 renderer_container->hide();
870 default_files_container->hide();
871
872 callable_mp((Control *)project_name, &Control::grab_focus).call_deferred(false);
873 callable_mp(project_name, &LineEdit::select_all).call_deferred();
874 } else {
875 if (p_reset_name) {
876 _reset_name();
877 }
878 project_path->set_editable(true);
879
880 if (mode == MODE_DUPLICATE) {
881 String original_dir = original_project_path.get_base_dir();
882 project_path->set_text(original_dir);
883 install_path->set_text(original_dir);
884 fdialog_project->set_current_dir(original_dir);
885 } else {
886 String fav_dir = EDITOR_GET("filesystem/directories/default_project_path");
887 fav_dir = fav_dir.simplify_path();
888 if (!fav_dir.is_empty()) {
889 project_path->set_text(fav_dir);
890 install_path->set_text(fav_dir);
891 fdialog_project->set_current_dir(fav_dir);
892 } else {
893 Ref<DirAccess> d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
894 project_path->set_text(d->get_current_dir());
895 install_path->set_text(d->get_current_dir());
896 fdialog_project->set_current_dir(d->get_current_dir());
897 }
898 }
899
900 create_dir->show();
901 project_status_rect->show();
902 project_browse->show();
903 edit_check_box->show();
904
905 if (mode == MODE_IMPORT) {
906 set_title(TTRC("Import Existing Project"));
907 set_ok_button_text(TTRC("Import"));
908
909 name_container->hide();
910 install_path_container->hide();
911 renderer_container->hide();
912 default_files_container->hide();
913
914 // Project path dialog is also opened; no need to change focus.
915 } else if (mode == MODE_NEW) {
916 set_title(TTRC("Create New Project"));
917 set_ok_button_text(TTRC("Create"));
918
919 if (!rendering_device_checked) {
920 rendering_device_supported = DisplayServer::is_rendering_device_supported();
921
922 if (!rendering_device_supported) {
923 List<BaseButton *> buttons;
924 renderer_button_group->get_buttons(&buttons);
925 for (BaseButton *button : buttons) {
926 if (button->get_meta(SNAME("rendering_method")) == "gl_compatibility") {
927 button->set_pressed(true);
928 break;
929 }
930 }
931 }
932 _renderer_selected();
933 rendering_device_checked = true;
934 }
935
936 name_container->show();
937 install_path_container->hide();
938 renderer_container->show();
939 default_files_container->show();
940
941 callable_mp((Control *)project_name, &Control::grab_focus).call_deferred(false);
942 callable_mp(project_name, &LineEdit::select_all).call_deferred();
943 } else if (mode == MODE_INSTALL) {
944 set_title(TTR("Install Project:") + " " + zip_title);
945 set_ok_button_text(TTRC("Install"));
946
947 project_name->set_text(zip_title);
948
949 name_container->show();
950 install_path_container->hide();
951 renderer_container->hide();
952 default_files_container->hide();
953
954 callable_mp((Control *)project_path, &Control::grab_focus).call_deferred(false);
955 } else if (mode == MODE_DUPLICATE) {
956 set_title(TTRC("Duplicate Project"));
957 set_ok_button_text(TTRC("Duplicate"));
958
959 name_container->show();
960 install_path_container->hide();
961 renderer_container->hide();
962 default_files_container->hide();
963 if (!duplicate_can_edit) {
964 edit_check_box->hide();
965 }
966
967 callable_mp((Control *)project_name, &Control::grab_focus).call_deferred(false);
968 callable_mp(project_name, &LineEdit::select_all).call_deferred();
969 }
970
971 auto_dir = "";
972 last_custom_target_dir = "";
973 _update_target_auto_dir();
974 if (create_dir->is_pressed()) {
975 // Append `auto_dir` to target path.
976 _create_dir_toggled(true);
977 }
978 }
979
980 _validate_path();
981
982 popup_centered(Size2(500, 0) * EDSCALE);
983 }
984
985 void ProjectDialog::_notification(int p_what) {
986 switch (p_what) {
987 case NOTIFICATION_TRANSLATION_CHANGED: {
988 if (rendering_device_checked) {
989 _renderer_selected();
990 }
991 } break;
992
993 case NOTIFICATION_THEME_CHANGED: {
994 create_dir->set_button_icon(get_editor_theme_icon(SNAME("FolderCreate")));
995 project_browse->set_button_icon(get_editor_theme_icon(SNAME("FolderBrowse")));
996 install_browse->set_button_icon(get_editor_theme_icon(SNAME("FolderBrowse")));
997 } break;
998 case NOTIFICATION_READY: {
999 fdialog_project = memnew(EditorFileDialog);
1000 fdialog_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
1001 fdialog_project->connect("dir_selected", callable_mp(this, &ProjectDialog::_project_path_selected));
1002 fdialog_project->connect("file_selected", callable_mp(this, &ProjectDialog::_project_path_selected));
1003 fdialog_project->connect("canceled", callable_mp(this, &ProjectDialog::show_dialog).bind(false, false), CONNECT_DEFERRED);
1004 callable_mp((Node *)this, &Node::add_sibling).call_deferred(fdialog_project, false);
1005 } break;
1006 }
1007 }
1008
1009 void ProjectDialog::_bind_methods() {
1010 ADD_SIGNAL(MethodInfo("project_created"));
1011 ADD_SIGNAL(MethodInfo("project_duplicated"));
1012 ADD_SIGNAL(MethodInfo("projects_updated"));
1013 }
1014
1015 ProjectDialog::ProjectDialog() {
1016 VBoxContainer *vb = memnew(VBoxContainer);
1017 add_child(vb);
1018
1019 name_container = memnew(VBoxContainer);
1020 vb->add_child(name_container);
1021
1022 Label *l = memnew(Label);
1023 l->set_text(TTRC("Project Name:"));
1024 name_container->add_child(l);
1025
1026 project_name = memnew(LineEdit);
1027 project_name->set_virtual_keyboard_show_on_focus(false);
1028 project_name->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1029 project_name->set_accessibility_name(TTRC("Project Name:"));
1030 name_container->add_child(project_name);
1031
1032 project_path_container = memnew(VBoxContainer);
1033 vb->add_child(project_path_container);
1034
1035 HBoxContainer *pphb_label = memnew(HBoxContainer);
1036 project_path_container->add_child(pphb_label);
1037
1038 l = memnew(Label);
1039 l->set_text(TTRC("Project Path:"));
1040 l->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1041 pphb_label->add_child(l);
1042
1043 create_dir = memnew(CheckButton);
1044 create_dir->set_text(TTRC("Create Folder"));
1045 create_dir->set_pressed(true);
1046 pphb_label->add_child(create_dir);
1047 create_dir->connect(SceneStringName(toggled), callable_mp(this, &ProjectDialog::_create_dir_toggled));
1048
1049 HBoxContainer *pphb = memnew(HBoxContainer);
1050 project_path_container->add_child(pphb);
1051
1052 project_path = memnew(LineEdit);
1053 project_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1054 project_path->set_accessibility_name(TTRC("Project Path:"));
1055 project_path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
1056 pphb->add_child(project_path);
1057
1058 install_path_container = memnew(VBoxContainer);
1059 vb->add_child(install_path_container);
1060
1061 l = memnew(Label);
1062 l->set_text(TTRC("Project Installation Path:"));
1063 install_path_container->add_child(l);
1064
1065 HBoxContainer *iphb = memnew(HBoxContainer);
1066 install_path_container->add_child(iphb);
1067
1068 install_path = memnew(LineEdit);
1069 install_path->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1070 install_path->set_accessibility_name(TTRC("Project Installation Path:"));
1071 install_path->set_structured_text_bidi_override(TextServer::STRUCTURED_TEXT_FILE);
1072 iphb->add_child(install_path);
1073
1074 // status icon
1075 project_status_rect = memnew(TextureRect);
1076 project_status_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
1077 pphb->add_child(project_status_rect);
1078
1079 project_browse = memnew(Button);
1080 project_browse->set_text(TTRC("Browse"));
1081 project_browse->connect(SceneStringName(pressed), callable_mp(this, &ProjectDialog::_browse_project_path));
1082 pphb->add_child(project_browse);
1083
1084 // install status icon
1085 install_status_rect = memnew(TextureRect);
1086 install_status_rect->set_stretch_mode(TextureRect::STRETCH_KEEP_CENTERED);
1087 iphb->add_child(install_status_rect);
1088
1089 install_browse = memnew(Button);
1090 install_browse->set_text(TTRC("Browse"));
1091 install_browse->connect(SceneStringName(pressed), callable_mp(this, &ProjectDialog::_browse_install_path));
1092 iphb->add_child(install_browse);
1093
1094 msg = memnew(Label);
1095 msg->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
1096 msg->set_accessibility_live(DisplayServer::LIVE_POLITE);
1097 msg->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
1098 msg->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
1099 msg->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
1100 vb->add_child(msg);
1101
1102 // Renderer selection.
1103 renderer_container = memnew(VBoxContainer);
1104 vb->add_child(renderer_container);
1105 l = memnew(Label);
1106 l->set_text(TTRC("Renderer:"));
1107 renderer_container->add_child(l);
1108 HBoxContainer *rshc = memnew(HBoxContainer);
1109 renderer_container->add_child(rshc);
1110 renderer_button_group.instantiate();
1111
1112 // Left hand side, used for checkboxes to select renderer.
1113 Container *rvb = memnew(VBoxContainer);
1114 rshc->add_child(rvb);
1115
1116 String default_renderer_type = "forward_plus";
1117 if (EditorSettings::get_singleton()->has_setting("project_manager/default_renderer")) {
1118 default_renderer_type = EditorSettings::get_singleton()->get_setting("project_manager/default_renderer");
1119 }
1120
1121 Button *rs_button = memnew(CheckBox);
1122 rs_button->set_button_group(renderer_button_group);
1123 rs_button->set_text(TTRC("Forward+"));
1124 rs_button->set_accessibility_name(TTRC("Renderer:"));
1125 #ifndef RD_ENABLED
1126 rs_button->set_disabled(true);
1127 #endif
1128 rs_button->set_meta(SNAME("rendering_method"), "forward_plus");
1129 rs_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectDialog::_renderer_selected));
1130 rvb->add_child(rs_button);
1131 if (default_renderer_type == "forward_plus") {
1132 rs_button->set_pressed(true);
1133 }
1134 rs_button = memnew(CheckBox);
1135 rs_button->set_button_group(renderer_button_group);
1136 rs_button->set_text(TTRC("Mobile"));
1137 rs_button->set_accessibility_name(TTRC("Renderer:"));
1138 #ifndef RD_ENABLED
1139 rs_button->set_disabled(true);
1140 #endif
1141 rs_button->set_meta(SNAME("rendering_method"), "mobile");
1142 rs_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectDialog::_renderer_selected));
1143 rvb->add_child(rs_button);
1144 if (default_renderer_type == "mobile") {
1145 rs_button->set_pressed(true);
1146 }
1147 rs_button = memnew(CheckBox);
1148 rs_button->set_button_group(renderer_button_group);
1149 rs_button->set_text(TTRC("Compatibility"));
1150 rs_button->set_accessibility_name(TTRC("Renderer:"));
1151 #if !defined(GLES3_ENABLED)
1152 rs_button->set_disabled(true);
1153 #endif
1154 rs_button->set_meta(SNAME("rendering_method"), "gl_compatibility");
1155 rs_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectDialog::_renderer_selected));
1156 rvb->add_child(rs_button);
1157 LinkButton *ri_link = memnew(LinkButton);
1158 ri_link->set_text(TTRC("More information"));
1159 ri_link->set_uri(GODOT_VERSION_DOCS_URL "/tutorials/rendering/renderers.html");
1160 ri_link->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
1161 rvb->add_child(ri_link);
1162 #if defined(GLES3_ENABLED)
1163 if (default_renderer_type == "gl_compatibility") {
1164 rs_button->set_pressed(true);
1165 }
1166 #endif
1167 rshc->add_child(memnew(VSeparator));
1168
1169 // Right hand side, used for text explaining each choice.
1170 rvb = memnew(VBoxContainer);
1171 rvb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1172 rshc->add_child(rvb);
1173 renderer_info = memnew(Label);
1174 renderer_info->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
1175 renderer_info->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
1176 renderer_info->set_modulate(Color(1, 1, 1, 0.7));
1177 rvb->add_child(renderer_info);
1178
1179 rd_not_supported = memnew(Label);
1180 rd_not_supported->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
1181 rd_not_supported->set_text(vformat(TTR("RenderingDevice-based methods not available on this GPU:\n%s\nPlease use the Compatibility renderer."), RenderingServer::get_singleton()->get_video_adapter_name()));
1182 rd_not_supported->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
1183 rd_not_supported->set_custom_minimum_size(Size2(200, 0) * EDSCALE);
1184 rd_not_supported->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
1185 rd_not_supported->set_visible(false);
1186 renderer_container->add_child(rd_not_supported);
1187
1188 l = memnew(Label);
1189 l->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
1190 l->set_text(TTRC("The renderer can be changed later, but scenes may need to be adjusted."));
1191 // Add some extra spacing to separate it from the list above and the buttons below.
1192 l->set_custom_minimum_size(Size2(0, 40) * EDSCALE);
1193 l->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER);
1194 l->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER);
1195 l->set_modulate(Color(1, 1, 1, 0.7));
1196 renderer_container->add_child(l);
1197
1198 default_files_container = memnew(HBoxContainer);
1199 vb->add_child(default_files_container);
1200 l = memnew(Label);
1201 l->set_text(TTRC("Version Control Metadata:"));
1202 default_files_container->add_child(l);
1203 vcs_metadata_selection = memnew(OptionButton);
1204 vcs_metadata_selection->set_custom_minimum_size(Size2(100, 20));
1205 vcs_metadata_selection->add_item(TTRC("None"), (int)EditorVCSInterface::VCSMetadata::NONE);
1206 vcs_metadata_selection->add_item(TTRC("Git"), (int)EditorVCSInterface::VCSMetadata::GIT);
1207 vcs_metadata_selection->select((int)EditorVCSInterface::VCSMetadata::GIT);
1208 vcs_metadata_selection->set_accessibility_name(TTRC("Version Control Metadata:"));
1209 default_files_container->add_child(vcs_metadata_selection);
1210 Control *spacer = memnew(Control);
1211 spacer->set_h_size_flags(Control::SIZE_EXPAND_FILL);
1212 default_files_container->add_child(spacer);
1213 fdialog_install = memnew(EditorFileDialog);
1214 fdialog_install->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
1215 add_child(fdialog_install);
1216
1217 Control *spacer2 = memnew(Control);
1218 spacer2->set_v_size_flags(Control::SIZE_EXPAND_FILL);
1219 vb->add_child(spacer2);
1220
1221 edit_check_box = memnew(CheckBox);
1222 edit_check_box->set_text(TTRC("Edit Now"));
1223 edit_check_box->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
1224 edit_check_box->set_pressed(true);
1225 vb->add_child(edit_check_box);
1226
1227 project_name->connect(SceneStringName(text_changed), callable_mp(this, &ProjectDialog::_project_name_changed).unbind(1));
1228 project_name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectDialog::ok_pressed).unbind(1));
1229
1230 project_path->connect(SceneStringName(text_changed), callable_mp(this, &ProjectDialog::_project_path_changed).unbind(1));
1231 project_path->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectDialog::ok_pressed).unbind(1));
1232
1233 install_path->connect(SceneStringName(text_changed), callable_mp(this, &ProjectDialog::_install_path_changed).unbind(1));
1234 install_path->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectDialog::ok_pressed).unbind(1));
1235
1236 fdialog_install->connect("dir_selected", callable_mp(this, &ProjectDialog::_install_path_selected));
1237 fdialog_install->connect("file_selected", callable_mp(this, &ProjectDialog::_install_path_selected));
1238
1239 set_hide_on_ok(false);
1240
1241 dialog_error = memnew(AcceptDialog);
1242 add_child(dialog_error);
1243 }