project_dialog.cpp 42 KB

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