project_dialog.cpp 41 KB

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