project_dialog.cpp 43 KB

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