project_export.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  1. /**************************************************************************/
  2. /* project_export.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_export.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/version.h"
  33. #include "editor/editor_file_system.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_properties.h"
  36. #include "editor/editor_settings.h"
  37. #include "editor/editor_string_names.h"
  38. #include "editor/export/editor_export.h"
  39. #include "editor/gui/editor_file_dialog.h"
  40. #include "editor/import/resource_importer_texture_settings.h"
  41. #include "editor/themes/editor_scale.h"
  42. #include "scene/gui/check_box.h"
  43. #include "scene/gui/check_button.h"
  44. #include "scene/gui/item_list.h"
  45. #include "scene/gui/link_button.h"
  46. #include "scene/gui/margin_container.h"
  47. #include "scene/gui/menu_button.h"
  48. #include "scene/gui/option_button.h"
  49. #include "scene/gui/popup_menu.h"
  50. #include "scene/gui/split_container.h"
  51. #include "scene/gui/tab_container.h"
  52. #include "scene/gui/texture_rect.h"
  53. #include "scene/gui/tree.h"
  54. void ProjectExportTextureFormatError::_on_fix_texture_format_pressed() {
  55. ProjectSettings::get_singleton()->set_setting(setting_identifier, true);
  56. ProjectSettings::get_singleton()->save();
  57. EditorFileSystem::get_singleton()->scan_changes();
  58. emit_signal("texture_format_enabled");
  59. }
  60. void ProjectExportTextureFormatError::_bind_methods() {
  61. ADD_SIGNAL(MethodInfo("texture_format_enabled"));
  62. }
  63. void ProjectExportTextureFormatError::_notification(int p_what) {
  64. switch (p_what) {
  65. case NOTIFICATION_THEME_CHANGED: {
  66. texture_format_error_label->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
  67. } break;
  68. }
  69. }
  70. void ProjectExportTextureFormatError::show_for_texture_format(const String &p_friendly_name, const String &p_setting_identifier) {
  71. texture_format_error_label->set_text(vformat(TTR("Target platform requires '%s' texture compression. Enable 'Import %s' to fix."), p_friendly_name, p_friendly_name.replace("/", " ")));
  72. setting_identifier = p_setting_identifier;
  73. show();
  74. }
  75. ProjectExportTextureFormatError::ProjectExportTextureFormatError() {
  76. // Set up the label.
  77. texture_format_error_label = memnew(Label);
  78. add_child(texture_format_error_label);
  79. // Set up the fix button.
  80. fix_texture_format_button = memnew(LinkButton);
  81. fix_texture_format_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  82. fix_texture_format_button->set_text(TTR("Fix Import"));
  83. add_child(fix_texture_format_button);
  84. fix_texture_format_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportTextureFormatError::_on_fix_texture_format_pressed));
  85. }
  86. void ProjectExportDialog::_notification(int p_what) {
  87. switch (p_what) {
  88. case NOTIFICATION_VISIBILITY_CHANGED: {
  89. if (!is_visible()) {
  90. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "export", Rect2(get_position(), get_size()));
  91. }
  92. } break;
  93. case NOTIFICATION_THEME_CHANGED: {
  94. duplicate_preset->set_icon(presets->get_editor_theme_icon(SNAME("Duplicate")));
  95. delete_preset->set_icon(presets->get_editor_theme_icon(SNAME("Remove")));
  96. } break;
  97. case NOTIFICATION_READY: {
  98. duplicate_preset->set_icon(presets->get_editor_theme_icon(SNAME("Duplicate")));
  99. delete_preset->set_icon(presets->get_editor_theme_icon(SNAME("Remove")));
  100. connect("confirmed", callable_mp(this, &ProjectExportDialog::_export_pck_zip));
  101. _update_export_all();
  102. } break;
  103. }
  104. }
  105. void ProjectExportDialog::popup_export() {
  106. add_preset->get_popup()->clear();
  107. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  108. Ref<EditorExportPlatform> plat = EditorExport::get_singleton()->get_export_platform(i);
  109. add_preset->get_popup()->add_icon_item(plat->get_logo(), plat->get_name());
  110. }
  111. _update_presets();
  112. if (presets->get_current() >= 0) {
  113. _update_current_preset(); // triggers rescan for templates if newly installed
  114. }
  115. // Restore valid window bounds or pop up at default size.
  116. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "export", Rect2());
  117. if (saved_size != Rect2()) {
  118. popup(saved_size);
  119. } else {
  120. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  121. }
  122. }
  123. void ProjectExportDialog::_add_preset(int p_platform) {
  124. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_platform(p_platform)->create_preset();
  125. ERR_FAIL_COND(!preset.is_valid());
  126. String preset_name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name();
  127. bool make_runnable = true;
  128. int attempt = 1;
  129. while (true) {
  130. bool valid = true;
  131. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  132. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  133. if (p->get_platform() == preset->get_platform() && p->is_runnable()) {
  134. make_runnable = false;
  135. }
  136. if (p->get_name() == preset_name) {
  137. valid = false;
  138. break;
  139. }
  140. }
  141. if (valid) {
  142. break;
  143. }
  144. attempt++;
  145. preset_name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name() + " " + itos(attempt);
  146. }
  147. preset->set_name(preset_name);
  148. if (make_runnable) {
  149. preset->set_runnable(make_runnable);
  150. }
  151. EditorExport::get_singleton()->add_export_preset(preset);
  152. _update_presets();
  153. _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1);
  154. }
  155. void ProjectExportDialog::_force_update_current_preset_parameters() {
  156. // Force the parameters section to refresh its UI.
  157. parameters->edit(nullptr);
  158. _update_current_preset();
  159. }
  160. void ProjectExportDialog::_update_current_preset() {
  161. _edit_preset(presets->get_current());
  162. }
  163. void ProjectExportDialog::_update_presets() {
  164. updating = true;
  165. Ref<EditorExportPreset> current;
  166. if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count()) {
  167. current = get_current_preset();
  168. }
  169. int current_idx = -1;
  170. presets->clear();
  171. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  172. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  173. if (preset == current) {
  174. current_idx = i;
  175. }
  176. String preset_name = preset->get_name();
  177. if (preset->is_runnable()) {
  178. preset_name += " (" + TTR("Runnable") + ")";
  179. }
  180. preset->update_files();
  181. presets->add_item(preset_name, preset->get_platform()->get_logo());
  182. }
  183. if (current_idx != -1) {
  184. presets->select(current_idx);
  185. }
  186. updating = false;
  187. }
  188. void ProjectExportDialog::_update_export_all() {
  189. bool can_export = EditorExport::get_singleton()->get_export_preset_count() > 0;
  190. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  191. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  192. bool needs_templates;
  193. String error;
  194. if (preset->get_export_path().is_empty() || !preset->get_platform()->can_export(preset, error, needs_templates)) {
  195. can_export = false;
  196. break;
  197. }
  198. }
  199. export_all_button->set_disabled(!can_export);
  200. if (can_export) {
  201. export_all_button->set_tooltip_text(TTR("Export the project for all the presets defined."));
  202. } else {
  203. export_all_button->set_tooltip_text(TTR("All presets must have an export path defined for Export All to work."));
  204. }
  205. }
  206. void ProjectExportDialog::_edit_preset(int p_index) {
  207. if (p_index < 0 || p_index >= presets->get_item_count()) {
  208. name->set_text("");
  209. name->set_editable(false);
  210. export_path->hide();
  211. advanced_options->set_disabled(true);
  212. runnable->set_disabled(true);
  213. parameters->edit(nullptr);
  214. presets->deselect_all();
  215. duplicate_preset->set_disabled(true);
  216. delete_preset->set_disabled(true);
  217. sections->hide();
  218. export_error->hide();
  219. export_templates_error->hide();
  220. return;
  221. }
  222. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index);
  223. ERR_FAIL_COND(current.is_null());
  224. updating = true;
  225. presets->select(p_index);
  226. sections->show();
  227. name->set_editable(true);
  228. export_path->show();
  229. duplicate_preset->set_disabled(false);
  230. delete_preset->set_disabled(false);
  231. get_ok_button()->set_disabled(false);
  232. name->set_text(current->get_name());
  233. List<String> extension_list = current->get_platform()->get_binary_extensions(current);
  234. Vector<String> extension_vector;
  235. for (const String &extension : extension_list) {
  236. extension_vector.push_back("*." + extension);
  237. }
  238. export_path->setup(extension_vector, false, true);
  239. export_path->update_property();
  240. advanced_options->set_disabled(false);
  241. advanced_options->set_pressed(current->are_advanced_options_enabled());
  242. runnable->set_disabled(false);
  243. runnable->set_pressed(current->is_runnable());
  244. if (parameters->get_edited_object() != current.ptr()) {
  245. current->update_value_overrides();
  246. }
  247. parameters->set_object_class(current->get_platform()->get_class_name());
  248. parameters->edit(current.ptr());
  249. export_filter->select(current->get_export_filter());
  250. include_filters->set_text(current->get_include_filter());
  251. include_label->set_text(_get_resource_export_header(current->get_export_filter()));
  252. exclude_filters->set_text(current->get_exclude_filter());
  253. server_strip_message->set_visible(current->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED);
  254. _fill_resource_tree();
  255. bool needs_templates;
  256. String error;
  257. if (!current->get_platform()->can_export(current, error, needs_templates)) {
  258. if (!error.is_empty()) {
  259. Vector<String> items = error.split("\n", false);
  260. error = "";
  261. for (int i = 0; i < items.size(); i++) {
  262. if (i > 0) {
  263. error += "\n";
  264. }
  265. error += " - " + items[i];
  266. }
  267. export_error->set_text(error);
  268. export_error->show();
  269. } else {
  270. export_error->hide();
  271. }
  272. if (needs_templates) {
  273. export_templates_error->show();
  274. } else {
  275. export_templates_error->hide();
  276. }
  277. export_warning->hide();
  278. export_button->set_disabled(true);
  279. } else {
  280. if (error != String()) {
  281. Vector<String> items = error.split("\n", false);
  282. error = "";
  283. for (int i = 0; i < items.size(); i++) {
  284. if (i > 0) {
  285. error += "\n";
  286. }
  287. error += " - " + items[i];
  288. }
  289. export_warning->set_text(error);
  290. export_warning->show();
  291. } else {
  292. export_warning->hide();
  293. }
  294. export_error->hide();
  295. export_templates_error->hide();
  296. export_button->set_disabled(false);
  297. }
  298. custom_features->set_text(current->get_custom_features());
  299. _update_feature_list();
  300. _update_export_all();
  301. child_controls_changed();
  302. if ((feature_set.has("s3tc") || feature_set.has("bptc")) && !ResourceImporterTextureSettings::should_import_s3tc_bptc()) {
  303. export_texture_format_error->show_for_texture_format("S3TC/BPTC", "rendering/textures/vram_compression/import_s3tc_bptc");
  304. } else if ((feature_set.has("etc2") || feature_set.has("astc")) && !ResourceImporterTextureSettings::should_import_etc2_astc()) {
  305. export_texture_format_error->show_for_texture_format("ETC2/ASTC", "rendering/textures/vram_compression/import_etc2_astc");
  306. } else {
  307. export_texture_format_error->hide();
  308. }
  309. String enc_in_filters_str = current->get_enc_in_filter();
  310. String enc_ex_filters_str = current->get_enc_ex_filter();
  311. if (!updating_enc_filters) {
  312. enc_in_filters->set_text(enc_in_filters_str);
  313. enc_ex_filters->set_text(enc_ex_filters_str);
  314. }
  315. bool enc_pck_mode = current->get_enc_pck();
  316. enc_pck->set_pressed(enc_pck_mode);
  317. enc_directory->set_disabled(!enc_pck_mode);
  318. enc_in_filters->set_editable(enc_pck_mode);
  319. enc_ex_filters->set_editable(enc_pck_mode);
  320. script_key->set_editable(enc_pck_mode);
  321. bool enc_directory_mode = current->get_enc_directory();
  322. enc_directory->set_pressed(enc_directory_mode);
  323. String key = current->get_script_encryption_key();
  324. if (!updating_script_key) {
  325. script_key->set_text(key);
  326. }
  327. if (enc_pck_mode) {
  328. script_key->set_editable(true);
  329. bool key_valid = _validate_script_encryption_key(key);
  330. if (key_valid) {
  331. script_key_error->hide();
  332. } else {
  333. script_key_error->show();
  334. }
  335. } else {
  336. script_key->set_editable(false);
  337. script_key_error->hide();
  338. }
  339. int script_export_mode = current->get_script_export_mode();
  340. script_mode->select(script_export_mode);
  341. updating = false;
  342. }
  343. void ProjectExportDialog::_update_feature_list() {
  344. Ref<EditorExportPreset> current = get_current_preset();
  345. ERR_FAIL_COND(current.is_null());
  346. List<String> features_list;
  347. current->get_platform()->get_platform_features(&features_list);
  348. current->get_platform()->get_preset_features(current, &features_list);
  349. String custom = current->get_custom_features();
  350. Vector<String> custom_list = custom.split(",");
  351. for (int i = 0; i < custom_list.size(); i++) {
  352. String f = custom_list[i].strip_edges();
  353. if (!f.is_empty()) {
  354. features_list.push_back(f);
  355. }
  356. }
  357. feature_set.clear();
  358. for (const String &E : features_list) {
  359. feature_set.insert(E);
  360. }
  361. #ifdef REAL_T_IS_DOUBLE
  362. feature_set.insert("double");
  363. #else
  364. feature_set.insert("single");
  365. #endif // REAL_T_IS_DOUBLE
  366. custom_feature_display->clear();
  367. String text;
  368. bool first = true;
  369. for (const String &E : feature_set) {
  370. if (!first) {
  371. text += ", ";
  372. } else {
  373. first = false;
  374. }
  375. text += E;
  376. }
  377. custom_feature_display->add_text(text);
  378. }
  379. void ProjectExportDialog::_custom_features_changed(const String &p_text) {
  380. if (updating) {
  381. return;
  382. }
  383. Ref<EditorExportPreset> current = get_current_preset();
  384. ERR_FAIL_COND(current.is_null());
  385. current->set_custom_features(p_text);
  386. _update_feature_list();
  387. }
  388. void ProjectExportDialog::_tab_changed(int) {
  389. _update_feature_list();
  390. }
  391. void ProjectExportDialog::_update_parameters(const String &p_edited_property) {
  392. _update_current_preset();
  393. }
  394. void ProjectExportDialog::_advanced_options_pressed() {
  395. if (updating) {
  396. return;
  397. }
  398. Ref<EditorExportPreset> current = get_current_preset();
  399. ERR_FAIL_COND(current.is_null());
  400. current->set_advanced_options_enabled(advanced_options->is_pressed());
  401. _update_presets();
  402. }
  403. void ProjectExportDialog::_runnable_pressed() {
  404. if (updating) {
  405. return;
  406. }
  407. Ref<EditorExportPreset> current = get_current_preset();
  408. ERR_FAIL_COND(current.is_null());
  409. if (runnable->is_pressed()) {
  410. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  411. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  412. if (p->get_platform() == current->get_platform()) {
  413. p->set_runnable(current == p);
  414. }
  415. }
  416. } else {
  417. current->set_runnable(false);
  418. }
  419. _update_presets();
  420. }
  421. void ProjectExportDialog::_name_changed(const String &p_string) {
  422. if (updating) {
  423. return;
  424. }
  425. Ref<EditorExportPreset> current = get_current_preset();
  426. ERR_FAIL_COND(current.is_null());
  427. current->set_name(p_string);
  428. _update_presets();
  429. }
  430. void ProjectExportDialog::set_export_path(const String &p_value) {
  431. Ref<EditorExportPreset> current = get_current_preset();
  432. ERR_FAIL_COND(current.is_null());
  433. current->set_export_path(p_value);
  434. }
  435. String ProjectExportDialog::get_export_path() {
  436. Ref<EditorExportPreset> current = get_current_preset();
  437. ERR_FAIL_COND_V(current.is_null(), String(""));
  438. return current->get_export_path();
  439. }
  440. Ref<EditorExportPreset> ProjectExportDialog::get_current_preset() const {
  441. return EditorExport::get_singleton()->get_export_preset(presets->get_current());
  442. }
  443. void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  444. if (updating) {
  445. return;
  446. }
  447. Ref<EditorExportPreset> current = get_current_preset();
  448. ERR_FAIL_COND(current.is_null());
  449. current->set_export_path(p_value);
  450. _update_presets();
  451. _update_export_all();
  452. }
  453. void ProjectExportDialog::_enc_filters_changed(const String &p_filters) {
  454. if (updating) {
  455. return;
  456. }
  457. Ref<EditorExportPreset> current = get_current_preset();
  458. ERR_FAIL_COND(current.is_null());
  459. current->set_enc_in_filter(enc_in_filters->get_text());
  460. current->set_enc_ex_filter(enc_ex_filters->get_text());
  461. updating_enc_filters = true;
  462. _update_current_preset();
  463. updating_enc_filters = false;
  464. }
  465. void ProjectExportDialog::_open_key_help_link() {
  466. OS::get_singleton()->shell_open(vformat("%s/contributing/development/compiling/compiling_with_script_encryption_key.html", VERSION_DOCS_URL));
  467. }
  468. void ProjectExportDialog::_enc_pck_changed(bool p_pressed) {
  469. if (updating) {
  470. return;
  471. }
  472. Ref<EditorExportPreset> current = get_current_preset();
  473. ERR_FAIL_COND(current.is_null());
  474. current->set_enc_pck(p_pressed);
  475. enc_directory->set_disabled(!p_pressed);
  476. enc_in_filters->set_editable(p_pressed);
  477. enc_ex_filters->set_editable(p_pressed);
  478. script_key->set_editable(p_pressed);
  479. _update_current_preset();
  480. }
  481. void ProjectExportDialog::_enc_directory_changed(bool p_pressed) {
  482. if (updating) {
  483. return;
  484. }
  485. Ref<EditorExportPreset> current = get_current_preset();
  486. ERR_FAIL_COND(current.is_null());
  487. current->set_enc_directory(p_pressed);
  488. _update_current_preset();
  489. }
  490. void ProjectExportDialog::_script_encryption_key_changed(const String &p_key) {
  491. if (updating) {
  492. return;
  493. }
  494. Ref<EditorExportPreset> current = get_current_preset();
  495. ERR_FAIL_COND(current.is_null());
  496. current->set_script_encryption_key(p_key);
  497. updating_script_key = true;
  498. _update_current_preset();
  499. updating_script_key = false;
  500. }
  501. bool ProjectExportDialog::_validate_script_encryption_key(const String &p_key) {
  502. bool is_valid = false;
  503. if (!p_key.is_empty() && p_key.is_valid_hex_number(false) && p_key.length() == 64) {
  504. is_valid = true;
  505. }
  506. return is_valid;
  507. }
  508. void ProjectExportDialog::_script_export_mode_changed(int p_mode) {
  509. if (updating) {
  510. return;
  511. }
  512. Ref<EditorExportPreset> current = get_current_preset();
  513. ERR_FAIL_COND(current.is_null());
  514. current->set_script_export_mode(p_mode);
  515. _update_current_preset();
  516. }
  517. void ProjectExportDialog::_duplicate_preset() {
  518. Ref<EditorExportPreset> current = get_current_preset();
  519. if (current.is_null()) {
  520. return;
  521. }
  522. Ref<EditorExportPreset> preset = current->get_platform()->create_preset();
  523. ERR_FAIL_COND(!preset.is_valid());
  524. String preset_name = current->get_name() + " (copy)";
  525. bool make_runnable = true;
  526. while (true) {
  527. bool valid = true;
  528. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  529. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  530. if (p->get_platform() == preset->get_platform() && p->is_runnable()) {
  531. make_runnable = false;
  532. }
  533. if (p->get_name() == preset_name) {
  534. valid = false;
  535. break;
  536. }
  537. }
  538. if (valid) {
  539. break;
  540. }
  541. preset_name += " (copy)";
  542. }
  543. preset->set_name(preset_name);
  544. if (make_runnable) {
  545. preset->set_runnable(make_runnable);
  546. }
  547. preset->set_advanced_options_enabled(current->are_advanced_options_enabled());
  548. preset->set_dedicated_server(current->is_dedicated_server());
  549. preset->set_export_filter(current->get_export_filter());
  550. preset->set_include_filter(current->get_include_filter());
  551. preset->set_exclude_filter(current->get_exclude_filter());
  552. preset->set_custom_features(current->get_custom_features());
  553. for (const KeyValue<StringName, Variant> &E : current->get_values()) {
  554. preset->set(E.key, E.value);
  555. }
  556. EditorExport::get_singleton()->add_export_preset(preset);
  557. _update_presets();
  558. _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1);
  559. }
  560. void ProjectExportDialog::_delete_preset() {
  561. Ref<EditorExportPreset> current = get_current_preset();
  562. if (current.is_null()) {
  563. return;
  564. }
  565. delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"), current->get_name()));
  566. delete_confirm->popup_centered();
  567. }
  568. void ProjectExportDialog::_delete_preset_confirm() {
  569. int idx = presets->get_current();
  570. _edit_preset(-1);
  571. export_button->set_disabled(true);
  572. get_ok_button()->set_disabled(true);
  573. EditorExport::get_singleton()->remove_export_preset(idx);
  574. _update_presets();
  575. // The Export All button might become enabled (if all other presets have an export path defined),
  576. // or it could be disabled (if there are no presets anymore).
  577. _update_export_all();
  578. }
  579. Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  580. if (p_from == presets) {
  581. int pos = presets->get_item_at_position(p_point, true);
  582. if (pos >= 0) {
  583. Dictionary d;
  584. d["type"] = "export_preset";
  585. d["preset"] = pos;
  586. HBoxContainer *drag = memnew(HBoxContainer);
  587. TextureRect *tr = memnew(TextureRect);
  588. tr->set_texture(presets->get_item_icon(pos));
  589. drag->add_child(tr);
  590. Label *label = memnew(Label);
  591. label->set_text(presets->get_item_text(pos));
  592. drag->add_child(label);
  593. presets->set_drag_preview(drag);
  594. return d;
  595. }
  596. }
  597. return Variant();
  598. }
  599. bool ProjectExportDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  600. if (p_from == presets) {
  601. Dictionary d = p_data;
  602. if (!d.has("type") || String(d["type"]) != "export_preset") {
  603. return false;
  604. }
  605. if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point)) {
  606. return false;
  607. }
  608. }
  609. return true;
  610. }
  611. void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  612. if (p_from == presets) {
  613. Dictionary d = p_data;
  614. int from_pos = d["preset"];
  615. int to_pos = -1;
  616. if (presets->get_item_at_position(p_point, true) >= 0) {
  617. to_pos = presets->get_item_at_position(p_point, true);
  618. }
  619. if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point)) {
  620. return;
  621. }
  622. if (to_pos == from_pos) {
  623. return;
  624. } else if (to_pos > from_pos) {
  625. to_pos--;
  626. }
  627. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(from_pos);
  628. EditorExport::get_singleton()->remove_export_preset(from_pos);
  629. EditorExport::get_singleton()->add_export_preset(preset, to_pos);
  630. _update_presets();
  631. if (to_pos >= 0) {
  632. _edit_preset(to_pos);
  633. } else {
  634. _edit_preset(presets->get_item_count() - 1);
  635. }
  636. }
  637. }
  638. void ProjectExportDialog::_export_type_changed(int p_which) {
  639. if (updating) {
  640. return;
  641. }
  642. Ref<EditorExportPreset> current = get_current_preset();
  643. if (current.is_null()) {
  644. return;
  645. }
  646. EditorExportPreset::ExportFilter filter_type = (EditorExportPreset::ExportFilter)p_which;
  647. current->set_export_filter(filter_type);
  648. current->set_dedicated_server(filter_type == EditorExportPreset::EXPORT_CUSTOMIZED);
  649. server_strip_message->set_visible(filter_type == EditorExportPreset::EXPORT_CUSTOMIZED);
  650. // Default to stripping everything when first switching to server build.
  651. if (filter_type == EditorExportPreset::EXPORT_CUSTOMIZED && current->get_customized_files_count() == 0) {
  652. current->set_file_export_mode("res://", EditorExportPreset::MODE_FILE_STRIP);
  653. }
  654. include_label->set_text(_get_resource_export_header(current->get_export_filter()));
  655. updating = true;
  656. _fill_resource_tree();
  657. updating = false;
  658. }
  659. String ProjectExportDialog::_get_resource_export_header(EditorExportPreset::ExportFilter p_filter) const {
  660. switch (p_filter) {
  661. case EditorExportPreset::EXCLUDE_SELECTED_RESOURCES:
  662. return TTR("Resources to exclude:");
  663. case EditorExportPreset::EXPORT_CUSTOMIZED:
  664. return TTR("Resources to override export behavior:");
  665. default:
  666. return TTR("Resources to export:");
  667. }
  668. }
  669. void ProjectExportDialog::_filter_changed(const String &p_filter) {
  670. if (updating) {
  671. return;
  672. }
  673. Ref<EditorExportPreset> current = get_current_preset();
  674. if (current.is_null()) {
  675. return;
  676. }
  677. current->set_include_filter(include_filters->get_text());
  678. current->set_exclude_filter(exclude_filters->get_text());
  679. }
  680. void ProjectExportDialog::_fill_resource_tree() {
  681. include_files->clear();
  682. include_label->hide();
  683. include_margin->hide();
  684. Ref<EditorExportPreset> current = get_current_preset();
  685. if (current.is_null()) {
  686. return;
  687. }
  688. EditorExportPreset::ExportFilter f = current->get_export_filter();
  689. if (f == EditorExportPreset::EXPORT_ALL_RESOURCES) {
  690. return;
  691. }
  692. TreeItem *root = include_files->create_item();
  693. if (f == EditorExportPreset::EXPORT_CUSTOMIZED) {
  694. include_files->set_columns(2);
  695. include_files->set_column_expand(1, false);
  696. include_files->set_column_custom_minimum_width(1, 250 * EDSCALE);
  697. } else {
  698. include_files->set_columns(1);
  699. }
  700. include_label->show();
  701. include_margin->show();
  702. _fill_tree(EditorFileSystem::get_singleton()->get_filesystem(), root, current, f);
  703. if (f == EditorExportPreset::EXPORT_CUSTOMIZED) {
  704. _propagate_file_export_mode(include_files->get_root(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED);
  705. }
  706. }
  707. void ProjectExportDialog::_setup_item_for_file_mode(TreeItem *p_item, EditorExportPreset::FileExportMode p_mode) {
  708. if (p_mode == EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {
  709. p_item->set_checked(0, false);
  710. p_item->set_cell_mode(1, TreeItem::CELL_MODE_STRING);
  711. p_item->set_editable(1, false);
  712. p_item->set_selectable(1, false);
  713. p_item->set_custom_color(1, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor)));
  714. } else {
  715. p_item->set_checked(0, true);
  716. p_item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM);
  717. p_item->set_editable(1, true);
  718. p_item->set_selectable(1, true);
  719. p_item->clear_custom_color(1);
  720. }
  721. p_item->set_metadata(1, p_mode);
  722. }
  723. bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem *p_item, Ref<EditorExportPreset> &current, EditorExportPreset::ExportFilter p_export_filter) {
  724. p_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  725. p_item->set_icon(0, presets->get_theme_icon(SNAME("folder"), SNAME("FileDialog")));
  726. p_item->set_text(0, p_dir->get_name() + "/");
  727. p_item->set_editable(0, true);
  728. p_item->set_metadata(0, p_dir->get_path());
  729. if (p_export_filter == EditorExportPreset::EXPORT_CUSTOMIZED) {
  730. _setup_item_for_file_mode(p_item, current->get_file_export_mode(p_dir->get_path()));
  731. }
  732. bool used = false;
  733. for (int i = 0; i < p_dir->get_subdir_count(); i++) {
  734. TreeItem *subdir = include_files->create_item(p_item);
  735. if (_fill_tree(p_dir->get_subdir(i), subdir, current, p_export_filter)) {
  736. used = true;
  737. } else {
  738. memdelete(subdir);
  739. }
  740. }
  741. for (int i = 0; i < p_dir->get_file_count(); i++) {
  742. String type = p_dir->get_file_type(i);
  743. if (p_export_filter == EditorExportPreset::EXPORT_SELECTED_SCENES && type != "PackedScene") {
  744. continue;
  745. }
  746. if (type == "TextFile") {
  747. continue;
  748. }
  749. TreeItem *file = include_files->create_item(p_item);
  750. file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  751. file->set_text(0, p_dir->get_file(i));
  752. String path = p_dir->get_file_path(i);
  753. file->set_icon(0, EditorNode::get_singleton()->get_class_icon(type));
  754. file->set_editable(0, true);
  755. file->set_metadata(0, path);
  756. if (p_export_filter == EditorExportPreset::EXPORT_CUSTOMIZED) {
  757. _setup_item_for_file_mode(file, current->get_file_export_mode(path));
  758. } else {
  759. file->set_checked(0, current->has_export_file(path));
  760. file->propagate_check(0);
  761. }
  762. used = true;
  763. }
  764. return used;
  765. }
  766. void ProjectExportDialog::_propagate_file_export_mode(TreeItem *p_item, EditorExportPreset::FileExportMode p_inherited_export_mode) {
  767. EditorExportPreset::FileExportMode file_export_mode = (EditorExportPreset::FileExportMode)(int)p_item->get_metadata(1);
  768. bool is_inherited = false;
  769. if (file_export_mode == EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {
  770. file_export_mode = p_inherited_export_mode;
  771. is_inherited = true;
  772. }
  773. if (file_export_mode == EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) {
  774. p_item->set_text(1, "");
  775. } else {
  776. String text = file_mode_popup->get_item_text(file_mode_popup->get_item_index(file_export_mode));
  777. if (is_inherited) {
  778. text += " " + TTR("(Inherited)");
  779. }
  780. p_item->set_text(1, text);
  781. }
  782. for (int i = 0; i < p_item->get_child_count(); i++) {
  783. _propagate_file_export_mode(p_item->get_child(i), file_export_mode);
  784. }
  785. }
  786. void ProjectExportDialog::_tree_changed() {
  787. if (updating) {
  788. return;
  789. }
  790. Ref<EditorExportPreset> current = get_current_preset();
  791. if (current.is_null()) {
  792. return;
  793. }
  794. TreeItem *item = include_files->get_edited();
  795. if (!item) {
  796. return;
  797. }
  798. if (current->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED) {
  799. EditorExportPreset::FileExportMode file_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED;
  800. String path = item->get_metadata(0);
  801. if (item->is_checked(0)) {
  802. file_mode = current->get_file_export_mode(path, EditorExportPreset::MODE_FILE_STRIP);
  803. }
  804. current->set_file_export_mode(path, file_mode);
  805. _setup_item_for_file_mode(item, file_mode);
  806. _propagate_file_export_mode(include_files->get_root(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED);
  807. } else {
  808. item->propagate_check(0);
  809. }
  810. }
  811. void ProjectExportDialog::_check_propagated_to_item(Object *p_obj, int column) {
  812. Ref<EditorExportPreset> current = get_current_preset();
  813. if (current.is_null()) {
  814. return;
  815. }
  816. TreeItem *item = Object::cast_to<TreeItem>(p_obj);
  817. String path = item->get_metadata(0);
  818. if (item && !path.ends_with("/")) {
  819. bool added = item->is_checked(0);
  820. if (added) {
  821. current->add_export_file(path);
  822. } else {
  823. current->remove_export_file(path);
  824. }
  825. }
  826. }
  827. void ProjectExportDialog::_tree_popup_edited(bool p_arrow_clicked) {
  828. Rect2 bounds = include_files->get_custom_popup_rect();
  829. bounds.position += get_global_canvas_transform().get_origin();
  830. bounds.size *= get_global_canvas_transform().get_scale();
  831. if (!is_embedding_subwindows()) {
  832. bounds.position += get_position();
  833. }
  834. file_mode_popup->popup(bounds);
  835. }
  836. void ProjectExportDialog::_set_file_export_mode(int p_id) {
  837. Ref<EditorExportPreset> current = get_current_preset();
  838. if (current.is_null()) {
  839. return;
  840. }
  841. TreeItem *item = include_files->get_edited();
  842. String path = item->get_metadata(0);
  843. EditorExportPreset::FileExportMode file_export_mode = (EditorExportPreset::FileExportMode)p_id;
  844. current->set_file_export_mode(path, file_export_mode);
  845. item->set_metadata(1, file_export_mode);
  846. _propagate_file_export_mode(include_files->get_root(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED);
  847. }
  848. void ProjectExportDialog::_export_pck_zip() {
  849. Ref<EditorExportPreset> current = get_current_preset();
  850. ERR_FAIL_COND(current.is_null());
  851. String dir = current->get_export_path().get_base_dir();
  852. export_pck_zip->set_current_dir(dir);
  853. export_pck_zip->popup_file_dialog();
  854. }
  855. void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {
  856. Ref<EditorExportPreset> current = get_current_preset();
  857. ERR_FAIL_COND(current.is_null());
  858. Ref<EditorExportPlatform> platform = current->get_platform();
  859. ERR_FAIL_COND(platform.is_null());
  860. const Dictionary &fd_option = export_pck_zip->get_selected_options();
  861. bool export_debug = fd_option.get(TTR("Export With Debug"), true);
  862. if (p_path.ends_with(".zip")) {
  863. platform->export_zip(current, export_debug, p_path);
  864. } else if (p_path.ends_with(".pck")) {
  865. platform->export_pack(current, export_debug, p_path);
  866. } else {
  867. ERR_FAIL_MSG("Path must end with .pck or .zip");
  868. }
  869. }
  870. void ProjectExportDialog::_open_export_template_manager() {
  871. hide();
  872. EditorNode::get_singleton()->open_export_template_manager();
  873. }
  874. void ProjectExportDialog::_validate_export_path(const String &p_path) {
  875. // Disable export via OK button or Enter key if LineEdit has an empty filename
  876. bool invalid_path = (p_path.get_file().get_basename().is_empty());
  877. // Check if state change before needlessly messing with signals
  878. if (invalid_path && export_project->get_ok_button()->is_disabled()) {
  879. return;
  880. }
  881. if (!invalid_path && !export_project->get_ok_button()->is_disabled()) {
  882. return;
  883. }
  884. if (invalid_path) {
  885. export_project->get_ok_button()->set_disabled(true);
  886. export_project->get_line_edit()->disconnect("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted));
  887. } else {
  888. export_project->get_ok_button()->set_disabled(false);
  889. export_project->get_line_edit()->connect("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted));
  890. }
  891. }
  892. void ProjectExportDialog::_export_project() {
  893. Ref<EditorExportPreset> current = get_current_preset();
  894. ERR_FAIL_COND(current.is_null());
  895. Ref<EditorExportPlatform> platform = current->get_platform();
  896. ERR_FAIL_COND(platform.is_null());
  897. export_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  898. export_project->clear_filters();
  899. List<String> extension_list = platform->get_binary_extensions(current);
  900. for (const String &extension : extension_list) {
  901. // TRANSLATORS: This is the name of a project export file format. %s will be replaced by the platform name.
  902. export_project->add_filter("*." + extension, vformat(TTR("%s Export"), platform->get_name()));
  903. }
  904. if (!current->get_export_path().is_empty()) {
  905. export_project->set_current_path(current->get_export_path());
  906. } else {
  907. if (extension_list.size() >= 1) {
  908. export_project->set_current_file(default_filename + "." + extension_list.front()->get());
  909. } else {
  910. export_project->set_current_file(default_filename);
  911. }
  912. }
  913. // Ensure that signal is connected if previous attempt left it disconnected
  914. // with _validate_export_path.
  915. // FIXME: This is a hack, we should instead change EditorFileDialog to allow
  916. // disabling validation by the "text_submitted" signal.
  917. if (!export_project->get_line_edit()->is_connected("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted))) {
  918. export_project->get_ok_button()->set_disabled(false);
  919. export_project->get_line_edit()->connect("text_submitted", callable_mp(export_project, &EditorFileDialog::_file_submitted));
  920. }
  921. export_project->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  922. export_project->popup_file_dialog();
  923. }
  924. void ProjectExportDialog::_export_project_to_path(const String &p_path) {
  925. // Save this name for use in future exports (but drop the file extension)
  926. default_filename = p_path.get_file().get_basename();
  927. EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename);
  928. Ref<EditorExportPreset> current = get_current_preset();
  929. ERR_FAIL_COND_MSG(current.is_null(), "Failed to start the export: current preset is invalid.");
  930. Ref<EditorExportPlatform> platform = current->get_platform();
  931. ERR_FAIL_COND_MSG(platform.is_null(), "Failed to start the export: current preset has no valid platform.");
  932. current->set_export_path(p_path);
  933. exporting = true;
  934. platform->clear_messages();
  935. current->update_value_overrides();
  936. Dictionary fd_option = export_project->get_selected_options();
  937. bool export_debug = fd_option.get(TTR("Export With Debug"), true);
  938. Error err = platform->export_project(current, export_debug, current->get_export_path(), 0);
  939. result_dialog_log->clear();
  940. if (err != ERR_SKIP) {
  941. if (platform->fill_log_messages(result_dialog_log, err)) {
  942. result_dialog->popup_centered_ratio(0.5);
  943. }
  944. }
  945. exporting = false;
  946. }
  947. void ProjectExportDialog::_export_all_dialog() {
  948. #ifndef ANDROID_ENABLED
  949. export_all_dialog->show();
  950. export_all_dialog->popup_centered(Size2(300, 80));
  951. #endif
  952. }
  953. void ProjectExportDialog::_export_all_dialog_action(const String &p_str) {
  954. export_all_dialog->hide();
  955. _export_all(p_str != "release");
  956. }
  957. void ProjectExportDialog::_export_all(bool p_debug) {
  958. exporting = true;
  959. bool show_dialog = false;
  960. { // Scope for the editor progress, we must free it before showing the dialog at the end.
  961. String export_target = p_debug ? TTR("Debug") : TTR("Release");
  962. EditorProgress ep("exportall", TTR("Exporting All") + " " + export_target, EditorExport::get_singleton()->get_export_preset_count(), true);
  963. result_dialog_log->clear();
  964. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  965. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  966. if (preset.is_null()) {
  967. exporting = false;
  968. ERR_FAIL_MSG("Failed to start the export: one of the presets is invalid.");
  969. }
  970. Ref<EditorExportPlatform> platform = preset->get_platform();
  971. if (platform.is_null()) {
  972. exporting = false;
  973. ERR_FAIL_MSG("Failed to start the export: one of the presets has no valid platform.");
  974. }
  975. ep.step(preset->get_name(), i);
  976. platform->clear_messages();
  977. preset->update_value_overrides();
  978. Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0);
  979. if (err == ERR_SKIP) {
  980. exporting = false;
  981. return;
  982. }
  983. bool has_messages = platform->fill_log_messages(result_dialog_log, err);
  984. show_dialog = show_dialog || has_messages;
  985. }
  986. }
  987. if (show_dialog) {
  988. result_dialog->popup_centered_ratio(0.5);
  989. }
  990. exporting = false;
  991. }
  992. void ProjectExportDialog::_bind_methods() {
  993. ClassDB::bind_method("set_export_path", &ProjectExportDialog::set_export_path);
  994. ClassDB::bind_method("get_export_path", &ProjectExportDialog::get_export_path);
  995. ClassDB::bind_method("get_current_preset", &ProjectExportDialog::get_current_preset);
  996. ADD_PROPERTY(PropertyInfo(Variant::STRING, "export_path"), "set_export_path", "get_export_path");
  997. }
  998. ProjectExportDialog::ProjectExportDialog() {
  999. set_title(TTR("Export"));
  1000. set_clamp_to_embedder(true);
  1001. VBoxContainer *main_vb = memnew(VBoxContainer);
  1002. add_child(main_vb);
  1003. HSplitContainer *hbox = memnew(HSplitContainer);
  1004. main_vb->add_child(hbox);
  1005. hbox->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1006. // Presets list.
  1007. VBoxContainer *preset_vb = memnew(VBoxContainer);
  1008. preset_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1009. hbox->add_child(preset_vb);
  1010. Label *l = memnew(Label(TTR("Presets")));
  1011. l->set_theme_type_variation("HeaderSmall");
  1012. HBoxContainer *preset_hb = memnew(HBoxContainer);
  1013. preset_hb->add_child(l);
  1014. preset_hb->add_spacer();
  1015. preset_vb->add_child(preset_hb);
  1016. add_preset = memnew(MenuButton);
  1017. add_preset->set_text(TTR("Add..."));
  1018. add_preset->get_popup()->connect("index_pressed", callable_mp(this, &ProjectExportDialog::_add_preset));
  1019. preset_hb->add_child(add_preset);
  1020. MarginContainer *mc = memnew(MarginContainer);
  1021. preset_vb->add_child(mc);
  1022. mc->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1023. presets = memnew(ItemList);
  1024. presets->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1025. SET_DRAG_FORWARDING_GCD(presets, ProjectExportDialog);
  1026. mc->add_child(presets);
  1027. presets->connect("item_selected", callable_mp(this, &ProjectExportDialog::_edit_preset));
  1028. duplicate_preset = memnew(Button);
  1029. duplicate_preset->set_tooltip_text(TTR("Duplicate"));
  1030. duplicate_preset->set_flat(true);
  1031. preset_hb->add_child(duplicate_preset);
  1032. duplicate_preset->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_duplicate_preset));
  1033. delete_preset = memnew(Button);
  1034. delete_preset->set_tooltip_text(TTR("Delete"));
  1035. delete_preset->set_flat(true);
  1036. preset_hb->add_child(delete_preset);
  1037. delete_preset->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_delete_preset));
  1038. // Preset settings.
  1039. VBoxContainer *settings_vb = memnew(VBoxContainer);
  1040. settings_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  1041. hbox->add_child(settings_vb);
  1042. name = memnew(LineEdit);
  1043. settings_vb->add_margin_child(TTR("Name:"), name);
  1044. name->connect("text_changed", callable_mp(this, &ProjectExportDialog::_name_changed));
  1045. runnable = memnew(CheckButton);
  1046. runnable->set_text(TTR("Runnable"));
  1047. runnable->set_tooltip_text(TTR("If checked, the preset will be available for use in one-click deploy.\nOnly one preset per platform may be marked as runnable."));
  1048. runnable->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_runnable_pressed));
  1049. advanced_options = memnew(CheckButton);
  1050. advanced_options->set_text(TTR("Advanced Options"));
  1051. advanced_options->set_tooltip_text(TTR("If checked, the advanced options will be shown."));
  1052. advanced_options->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_advanced_options_pressed));
  1053. HBoxContainer *preset_configs_container = memnew(HBoxContainer);
  1054. preset_configs_container->add_spacer(true);
  1055. preset_configs_container->add_child(advanced_options);
  1056. preset_configs_container->add_child(runnable);
  1057. settings_vb->add_child(preset_configs_container);
  1058. export_path = memnew(EditorPropertyPath);
  1059. settings_vb->add_child(export_path);
  1060. export_path->set_label(TTR("Export Path"));
  1061. export_path->set_object_and_property(this, "export_path");
  1062. export_path->set_save_mode();
  1063. export_path->connect("property_changed", callable_mp(this, &ProjectExportDialog::_export_path_changed));
  1064. // Subsections.
  1065. sections = memnew(TabContainer);
  1066. sections->set_use_hidden_tabs_for_min_size(true);
  1067. sections->set_theme_type_variation("TabContainerOdd");
  1068. settings_vb->add_child(sections);
  1069. sections->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1070. // Main preset parameters.
  1071. parameters = memnew(EditorInspector);
  1072. sections->add_child(parameters);
  1073. parameters->set_name(TTR("Options"));
  1074. parameters->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1075. parameters->set_use_doc_hints(true);
  1076. parameters->connect("property_edited", callable_mp(this, &ProjectExportDialog::_update_parameters));
  1077. EditorExport::get_singleton()->connect("export_presets_updated", callable_mp(this, &ProjectExportDialog::_force_update_current_preset_parameters));
  1078. // Resources export parameters.
  1079. VBoxContainer *resources_vb = memnew(VBoxContainer);
  1080. sections->add_child(resources_vb);
  1081. resources_vb->set_name(TTR("Resources"));
  1082. export_filter = memnew(OptionButton);
  1083. export_filter->add_item(TTR("Export all resources in the project"));
  1084. export_filter->add_item(TTR("Export selected scenes (and dependencies)"));
  1085. export_filter->add_item(TTR("Export selected resources (and dependencies)"));
  1086. export_filter->add_item(TTR("Export all resources in the project except resources checked below"));
  1087. export_filter->add_item(TTR("Export as dedicated server"));
  1088. resources_vb->add_margin_child(TTR("Export Mode:"), export_filter);
  1089. export_filter->connect("item_selected", callable_mp(this, &ProjectExportDialog::_export_type_changed));
  1090. include_label = memnew(Label);
  1091. include_label->set_text(TTR("Resources to export:"));
  1092. resources_vb->add_child(include_label);
  1093. include_margin = memnew(MarginContainer);
  1094. include_margin->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1095. resources_vb->add_child(include_margin);
  1096. include_files = memnew(Tree);
  1097. include_margin->add_child(include_files);
  1098. include_files->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1099. include_files->connect("item_edited", callable_mp(this, &ProjectExportDialog::_tree_changed));
  1100. include_files->connect("check_propagated_to_item", callable_mp(this, &ProjectExportDialog::_check_propagated_to_item));
  1101. include_files->connect("custom_popup_edited", callable_mp(this, &ProjectExportDialog::_tree_popup_edited));
  1102. server_strip_message = memnew(Label);
  1103. server_strip_message->set_visible(false);
  1104. server_strip_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART);
  1105. server_strip_message->set_custom_minimum_size(Size2(300 * EDSCALE, 1));
  1106. resources_vb->add_child(server_strip_message);
  1107. {
  1108. List<StringName> resource_names;
  1109. ClassDB::get_inheriters_from_class("Resource", &resource_names);
  1110. PackedStringArray strippable;
  1111. for (const StringName &resource_name : resource_names) {
  1112. if (ClassDB::has_method(resource_name, "create_placeholder", true)) {
  1113. strippable.push_back(resource_name);
  1114. }
  1115. }
  1116. strippable.sort();
  1117. String message = TTR("\"Strip Visuals\" will replace the following resources with placeholders:") + " ";
  1118. message += String(", ").join(strippable);
  1119. server_strip_message->set_text(message);
  1120. }
  1121. file_mode_popup = memnew(PopupMenu);
  1122. add_child(file_mode_popup);
  1123. file_mode_popup->add_item(TTR("Strip Visuals"), EditorExportPreset::MODE_FILE_STRIP);
  1124. file_mode_popup->add_item(TTR("Keep"), EditorExportPreset::MODE_FILE_KEEP);
  1125. file_mode_popup->add_item(TTR("Remove"), EditorExportPreset::MODE_FILE_REMOVE);
  1126. file_mode_popup->connect("id_pressed", callable_mp(this, &ProjectExportDialog::_set_file_export_mode));
  1127. include_filters = memnew(LineEdit);
  1128. resources_vb->add_margin_child(
  1129. TTR("Filters to export non-resource files/folders\n(comma-separated, e.g: *.json, *.txt, docs/*)"),
  1130. include_filters);
  1131. include_filters->connect("text_changed", callable_mp(this, &ProjectExportDialog::_filter_changed));
  1132. exclude_filters = memnew(LineEdit);
  1133. resources_vb->add_margin_child(
  1134. TTR("Filters to exclude files/folders from project\n(comma-separated, e.g: *.json, *.txt, docs/*)"),
  1135. exclude_filters);
  1136. exclude_filters->connect("text_changed", callable_mp(this, &ProjectExportDialog::_filter_changed));
  1137. // Feature tags.
  1138. VBoxContainer *feature_vb = memnew(VBoxContainer);
  1139. feature_vb->set_name(TTR("Features"));
  1140. custom_features = memnew(LineEdit);
  1141. custom_features->connect("text_changed", callable_mp(this, &ProjectExportDialog::_custom_features_changed));
  1142. feature_vb->add_margin_child(TTR("Custom (comma-separated):"), custom_features);
  1143. custom_feature_display = memnew(RichTextLabel);
  1144. custom_feature_display->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  1145. feature_vb->add_margin_child(TTR("Feature List:"), custom_feature_display, true);
  1146. sections->add_child(feature_vb);
  1147. // Encryption export parameters.
  1148. VBoxContainer *sec_vb = memnew(VBoxContainer);
  1149. sec_vb->set_name(TTR("Encryption"));
  1150. enc_pck = memnew(CheckButton);
  1151. enc_pck->connect("toggled", callable_mp(this, &ProjectExportDialog::_enc_pck_changed));
  1152. enc_pck->set_text(TTR("Encrypt Exported PCK"));
  1153. sec_vb->add_child(enc_pck);
  1154. enc_directory = memnew(CheckButton);
  1155. enc_directory->connect("toggled", callable_mp(this, &ProjectExportDialog::_enc_directory_changed));
  1156. enc_directory->set_text(TTR("Encrypt Index (File Names and Info)"));
  1157. sec_vb->add_child(enc_directory);
  1158. enc_in_filters = memnew(LineEdit);
  1159. enc_in_filters->connect("text_changed", callable_mp(this, &ProjectExportDialog::_enc_filters_changed));
  1160. sec_vb->add_margin_child(
  1161. TTR("Filters to include files/folders\n(comma-separated, e.g: *.tscn, *.tres, scenes/*)"),
  1162. enc_in_filters);
  1163. enc_ex_filters = memnew(LineEdit);
  1164. enc_ex_filters->connect("text_changed", callable_mp(this, &ProjectExportDialog::_enc_filters_changed));
  1165. sec_vb->add_margin_child(
  1166. TTR("Filters to exclude files/folders\n(comma-separated, e.g: *.ctex, *.import, music/*)"),
  1167. enc_ex_filters);
  1168. script_key = memnew(LineEdit);
  1169. script_key->connect("text_changed", callable_mp(this, &ProjectExportDialog::_script_encryption_key_changed));
  1170. script_key_error = memnew(Label);
  1171. script_key_error->set_text(String::utf8("• ") + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)"));
  1172. script_key_error->add_theme_color_override("font_color", EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor)));
  1173. sec_vb->add_margin_child(TTR("Encryption Key (256-bits as hexadecimal):"), script_key);
  1174. sec_vb->add_child(script_key_error);
  1175. sections->add_child(sec_vb);
  1176. Label *sec_info = memnew(Label);
  1177. sec_info->set_text(TTR("Note: Encryption key needs to be stored in the binary,\nyou need to build the export templates from source."));
  1178. sec_vb->add_child(sec_info);
  1179. LinkButton *sec_more_info = memnew(LinkButton);
  1180. sec_more_info->set_text(TTR("More Info..."));
  1181. sec_more_info->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_open_key_help_link));
  1182. sec_vb->add_child(sec_more_info);
  1183. // Script export parameters.
  1184. VBoxContainer *script_vb = memnew(VBoxContainer);
  1185. script_vb->set_name(TTR("Scripts"));
  1186. script_mode = memnew(OptionButton);
  1187. script_vb->add_margin_child(TTR("GDScript Export Mode:"), script_mode);
  1188. script_mode->add_item(TTR("Text (easier debugging)"), (int)EditorExportPreset::MODE_SCRIPT_TEXT);
  1189. script_mode->add_item(TTR("Binary tokens (faster loading)"), (int)EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS);
  1190. script_mode->add_item(TTR("Compressed binary tokens (smaller files)"), (int)EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED);
  1191. script_mode->connect("item_selected", callable_mp(this, &ProjectExportDialog::_script_export_mode_changed));
  1192. sections->add_child(script_vb);
  1193. sections->connect("tab_changed", callable_mp(this, &ProjectExportDialog::_tab_changed));
  1194. // Disable by default.
  1195. name->set_editable(false);
  1196. export_path->hide();
  1197. advanced_options->set_disabled(true);
  1198. runnable->set_disabled(true);
  1199. duplicate_preset->set_disabled(true);
  1200. delete_preset->set_disabled(true);
  1201. script_key_error->hide();
  1202. sections->hide();
  1203. parameters->edit(nullptr);
  1204. // Deletion dialog.
  1205. delete_confirm = memnew(ConfirmationDialog);
  1206. add_child(delete_confirm);
  1207. delete_confirm->set_ok_button_text(TTR("Delete"));
  1208. delete_confirm->connect("confirmed", callable_mp(this, &ProjectExportDialog::_delete_preset_confirm));
  1209. // Export buttons, dialogs and errors.
  1210. set_cancel_button_text(TTR("Close"));
  1211. set_ok_button_text(TTR("Export PCK/ZIP..."));
  1212. get_ok_button()->set_tooltip_text(TTR("Export the project resources as a PCK or ZIP package. This is not a playable build, only the project data without a Godot executable."));
  1213. get_ok_button()->set_disabled(true);
  1214. #ifdef ANDROID_ENABLED
  1215. export_button = memnew(Button);
  1216. export_button->hide();
  1217. #else
  1218. export_button = add_button(TTR("Export Project..."), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export");
  1219. export_button->set_tooltip_text(TTR("Export the project as a playable build (Godot executable and project data) for the selected preset."));
  1220. #endif
  1221. export_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_export_project));
  1222. // Disable initially before we select a valid preset
  1223. export_button->set_disabled(true);
  1224. export_all_dialog = memnew(ConfirmationDialog);
  1225. add_child(export_all_dialog);
  1226. export_all_dialog->set_title(TTR("Export All"));
  1227. export_all_dialog->set_text(TTR("Choose an export mode:"));
  1228. export_all_dialog->get_ok_button()->hide();
  1229. export_all_dialog->add_button(TTR("Debug"), true, "debug");
  1230. export_all_dialog->add_button(TTR("Release"), true, "release");
  1231. export_all_dialog->connect("custom_action", callable_mp(this, &ProjectExportDialog::_export_all_dialog_action));
  1232. #ifdef ANDROID_ENABLED
  1233. export_all_dialog->hide();
  1234. export_all_button = memnew(Button);
  1235. export_all_button->hide();
  1236. #else
  1237. export_all_button = add_button(TTR("Export All..."), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export");
  1238. #endif
  1239. export_all_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_export_all_dialog));
  1240. export_all_button->set_disabled(true);
  1241. export_pck_zip = memnew(EditorFileDialog);
  1242. export_pck_zip->add_filter("*.zip", TTR("ZIP File"));
  1243. export_pck_zip->add_filter("*.pck", TTR("Godot Project Pack"));
  1244. export_pck_zip->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1245. export_pck_zip->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);
  1246. add_child(export_pck_zip);
  1247. export_pck_zip->connect("file_selected", callable_mp(this, &ProjectExportDialog::_export_pck_zip_selected));
  1248. // Export warnings and errors bottom section.
  1249. export_texture_format_error = memnew(ProjectExportTextureFormatError);
  1250. main_vb->add_child(export_texture_format_error);
  1251. export_texture_format_error->hide();
  1252. export_texture_format_error->connect("texture_format_enabled", callable_mp(this, &ProjectExportDialog::_update_current_preset));
  1253. export_error = memnew(Label);
  1254. main_vb->add_child(export_error);
  1255. export_error->hide();
  1256. export_error->add_theme_color_override("font_color", EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor)));
  1257. export_warning = memnew(Label);
  1258. main_vb->add_child(export_warning);
  1259. export_warning->hide();
  1260. export_warning->add_theme_color_override("font_color", EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("warning_color"), EditorStringName(Editor)));
  1261. export_templates_error = memnew(HBoxContainer);
  1262. main_vb->add_child(export_templates_error);
  1263. export_templates_error->hide();
  1264. Label *export_error2 = memnew(Label);
  1265. export_templates_error->add_child(export_error2);
  1266. export_error2->add_theme_color_override("font_color", EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor)));
  1267. export_error2->set_text(String::utf8("• ") + TTR("Export templates for this platform are missing:") + " ");
  1268. result_dialog = memnew(AcceptDialog);
  1269. result_dialog->set_title(TTR("Project Export"));
  1270. result_dialog_log = memnew(RichTextLabel);
  1271. result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE);
  1272. result_dialog->add_child(result_dialog_log);
  1273. main_vb->add_child(result_dialog);
  1274. result_dialog->hide();
  1275. LinkButton *download_templates = memnew(LinkButton);
  1276. download_templates->set_text(TTR("Manage Export Templates"));
  1277. download_templates->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
  1278. export_templates_error->add_child(download_templates);
  1279. download_templates->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_open_export_template_manager));
  1280. // Export project file dialog.
  1281. export_project = memnew(EditorFileDialog);
  1282. export_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1283. add_child(export_project);
  1284. export_project->connect("file_selected", callable_mp(this, &ProjectExportDialog::_export_project_to_path));
  1285. export_project->get_line_edit()->connect("text_changed", callable_mp(this, &ProjectExportDialog::_validate_export_path));
  1286. export_project->add_option(TTR("Export With Debug"), Vector<String>(), true);
  1287. export_pck_zip->add_option(TTR("Export With Debug"), Vector<String>(), true);
  1288. set_hide_on_ok(false);
  1289. default_filename = EditorSettings::get_singleton()->get_project_metadata("export_options", "default_filename", "");
  1290. // If no default set, use project name
  1291. if (default_filename.is_empty()) {
  1292. // If no project name defined, use a sane default
  1293. default_filename = GLOBAL_GET("application/config/name");
  1294. if (default_filename.is_empty()) {
  1295. default_filename = "UnnamedProject";
  1296. }
  1297. }
  1298. }
  1299. ProjectExportDialog::~ProjectExportDialog() {
  1300. }