project_export.cpp 63 KB

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