project_dialog.cpp 44 KB

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