project_export.cpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264
  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/compressed_translation.h"
  32. #include "core/io/image_loader.h"
  33. #include "core/io/resource_loader.h"
  34. #include "core/io/resource_saver.h"
  35. #include "core/os/dir_access.h"
  36. #include "core/os/file_access.h"
  37. #include "core/os/os.h"
  38. #include "core/project_settings.h"
  39. #include "core/version_generated.gen.h"
  40. #include "editor_data.h"
  41. #include "editor_node.h"
  42. #include "editor_scale.h"
  43. #include "editor_settings.h"
  44. #include "scene/gui/box_container.h"
  45. #include "scene/gui/margin_container.h"
  46. #include "scene/gui/scroll_container.h"
  47. #include "scene/gui/tab_container.h"
  48. void ProjectExportDialog::_notification(int p_what) {
  49. switch (p_what) {
  50. case NOTIFICATION_ENTER_TREE:
  51. case NOTIFICATION_THEME_CHANGED: {
  52. duplicate_preset->set_icon(get_icon("Duplicate", "EditorIcons"));
  53. delete_preset->set_icon(get_icon("Remove", "EditorIcons"));
  54. } break;
  55. case NOTIFICATION_READY: {
  56. connect("confirmed", this, "_export_pck_zip");
  57. _update_export_all();
  58. } break;
  59. case NOTIFICATION_POPUP_HIDE: {
  60. EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "export", get_rect());
  61. } break;
  62. case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: {
  63. parameters->set_property_name_style(EditorPropertyNameProcessor::get_settings_style());
  64. } break;
  65. }
  66. }
  67. void ProjectExportDialog::popup_export() {
  68. add_preset->get_popup()->clear();
  69. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  70. Ref<EditorExportPlatform> plat = EditorExport::get_singleton()->get_export_platform(i);
  71. add_preset->get_popup()->add_icon_item(plat->get_logo(), plat->get_name());
  72. }
  73. _update_presets();
  74. if (presets->get_current() >= 0) {
  75. _update_current_preset(); // triggers rescan for templates if newly installed
  76. }
  77. // Restore valid window bounds or pop up at default size.
  78. Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "export", Rect2());
  79. if (saved_size != Rect2()) {
  80. popup(saved_size);
  81. } else {
  82. popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
  83. }
  84. }
  85. void ProjectExportDialog::_add_preset(int p_platform) {
  86. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_platform(p_platform)->create_preset();
  87. ERR_FAIL_COND(!preset.is_valid());
  88. String name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name();
  89. bool make_runnable = true;
  90. int attempt = 1;
  91. while (true) {
  92. bool valid = true;
  93. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  94. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  95. if (p->get_platform() == preset->get_platform() && p->is_runnable()) {
  96. make_runnable = false;
  97. }
  98. if (p->get_name() == name) {
  99. valid = false;
  100. break;
  101. }
  102. }
  103. if (valid) {
  104. break;
  105. }
  106. attempt++;
  107. name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name() + " " + itos(attempt);
  108. }
  109. preset->set_name(name);
  110. if (make_runnable) {
  111. preset->set_runnable(make_runnable);
  112. }
  113. EditorExport::get_singleton()->add_export_preset(preset);
  114. _update_presets();
  115. _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1);
  116. }
  117. void ProjectExportDialog::_force_update_current_preset_parameters() {
  118. // Force the parameters section to refresh its UI.
  119. parameters->edit(nullptr);
  120. _update_current_preset();
  121. }
  122. void ProjectExportDialog::_update_current_preset() {
  123. _edit_preset(presets->get_current());
  124. }
  125. void ProjectExportDialog::_update_presets() {
  126. updating = true;
  127. Ref<EditorExportPreset> current;
  128. if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count()) {
  129. current = get_current_preset();
  130. }
  131. int current_idx = -1;
  132. presets->clear();
  133. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  134. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  135. if (preset == current) {
  136. current_idx = i;
  137. }
  138. String name = preset->get_name();
  139. if (preset->is_runnable()) {
  140. name += " (" + TTR("Runnable") + ")";
  141. }
  142. preset->update_files_to_export();
  143. presets->add_item(name, preset->get_platform()->get_logo());
  144. }
  145. if (current_idx != -1) {
  146. presets->select(current_idx);
  147. }
  148. updating = false;
  149. }
  150. void ProjectExportDialog::_update_export_all() {
  151. bool can_export = EditorExport::get_singleton()->get_export_preset_count() > 0;
  152. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  153. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  154. bool needs_templates;
  155. String error;
  156. if (preset->get_export_path() == "" || !preset->get_platform()->can_export(preset, error, needs_templates)) {
  157. can_export = false;
  158. break;
  159. }
  160. }
  161. export_all_button->set_disabled(!can_export);
  162. if (can_export) {
  163. export_all_button->set_tooltip(TTR("Export the project for all the presets defined."));
  164. } else {
  165. export_all_button->set_tooltip(TTR("All presets must have an export path defined for Export All to work."));
  166. }
  167. }
  168. void ProjectExportDialog::_edit_preset(int p_index) {
  169. if (p_index < 0 || p_index >= presets->get_item_count()) {
  170. name->set_text("");
  171. name->set_editable(false);
  172. export_path->hide();
  173. runnable->set_disabled(true);
  174. parameters->edit(nullptr);
  175. presets->unselect_all();
  176. duplicate_preset->set_disabled(true);
  177. delete_preset->set_disabled(true);
  178. sections->hide();
  179. export_error->hide();
  180. export_templates_error->hide();
  181. return;
  182. }
  183. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index);
  184. ERR_FAIL_COND(current.is_null());
  185. updating = true;
  186. presets->select(p_index);
  187. sections->show();
  188. name->set_editable(true);
  189. export_path->show();
  190. duplicate_preset->set_disabled(false);
  191. delete_preset->set_disabled(false);
  192. get_ok()->set_disabled(false);
  193. name->set_text(current->get_name());
  194. List<String> extension_list = current->get_platform()->get_binary_extensions(current);
  195. Vector<String> extension_vector;
  196. for (int i = 0; i < extension_list.size(); i++) {
  197. extension_vector.push_back("*." + extension_list[i]);
  198. }
  199. export_path->setup(extension_vector, false, true);
  200. export_path->update_property();
  201. runnable->set_disabled(false);
  202. runnable->set_pressed(current->is_runnable());
  203. parameters->edit(current.ptr());
  204. export_filter->select(current->get_export_filter());
  205. include_filters->set_text(current->get_include_filter());
  206. exclude_filters->set_text(current->get_exclude_filter());
  207. _fill_resource_tree();
  208. bool needs_templates;
  209. String error;
  210. if (!current->get_platform()->can_export(current, error, needs_templates)) {
  211. if (error != String()) {
  212. Vector<String> items = error.split("\n", false);
  213. error = "";
  214. for (int i = 0; i < items.size(); i++) {
  215. if (i > 0) {
  216. error += "\n";
  217. }
  218. error += " - " + items[i];
  219. }
  220. export_error->set_text(error);
  221. export_error->show();
  222. } else {
  223. export_error->hide();
  224. }
  225. export_warning->hide();
  226. if (needs_templates) {
  227. export_templates_error->show();
  228. } else {
  229. export_templates_error->hide();
  230. }
  231. export_button->set_disabled(true);
  232. } else {
  233. if (error != String()) {
  234. Vector<String> items = error.split("\n", false);
  235. error = "";
  236. for (int i = 0; i < items.size(); i++) {
  237. if (i > 0) {
  238. error += "\n";
  239. }
  240. error += " - " + items[i];
  241. }
  242. export_warning->set_text(error);
  243. export_warning->show();
  244. } else {
  245. export_warning->hide();
  246. }
  247. export_error->hide();
  248. export_templates_error->hide();
  249. export_button->set_disabled(false);
  250. }
  251. custom_features->set_text(current->get_custom_features());
  252. _update_feature_list();
  253. _update_export_all();
  254. minimum_size_changed();
  255. int script_export_mode = current->get_script_export_mode();
  256. script_mode->select(script_export_mode);
  257. String key = current->get_script_encryption_key();
  258. if (!updating_script_key) {
  259. script_key->set_text(key);
  260. }
  261. if (script_export_mode == EditorExportPreset::MODE_SCRIPT_ENCRYPTED) {
  262. script_key->set_editable(true);
  263. bool key_valid = _validate_script_encryption_key(key);
  264. if (key_valid) {
  265. script_key_error->hide();
  266. } else {
  267. script_key_error->show();
  268. }
  269. } else {
  270. script_key->set_editable(false);
  271. script_key_error->hide();
  272. }
  273. updating = false;
  274. }
  275. void ProjectExportDialog::_update_feature_list() {
  276. Ref<EditorExportPreset> current = get_current_preset();
  277. ERR_FAIL_COND(current.is_null());
  278. Set<String> fset;
  279. List<String> features;
  280. current->get_platform()->get_platform_features(&features);
  281. current->get_platform()->get_preset_features(current, &features);
  282. String custom = current->get_custom_features();
  283. Vector<String> custom_list = custom.split(",");
  284. for (int i = 0; i < custom_list.size(); i++) {
  285. String f = custom_list[i].strip_edges();
  286. if (f != String()) {
  287. features.push_back(f);
  288. }
  289. }
  290. for (List<String>::Element *E = features.front(); E; E = E->next()) {
  291. fset.insert(E->get());
  292. }
  293. custom_feature_display->clear();
  294. for (Set<String>::Element *E = fset.front(); E; E = E->next()) {
  295. String f = E->get();
  296. if (E->next()) {
  297. f += ", ";
  298. }
  299. custom_feature_display->add_text(f);
  300. }
  301. }
  302. void ProjectExportDialog::_custom_features_changed(const String &p_text) {
  303. if (updating) {
  304. return;
  305. }
  306. Ref<EditorExportPreset> current = get_current_preset();
  307. ERR_FAIL_COND(current.is_null());
  308. current->set_custom_features(p_text);
  309. _update_feature_list();
  310. }
  311. void ProjectExportDialog::_tab_changed(int) {
  312. _update_feature_list();
  313. }
  314. void ProjectExportDialog::_update_parameters(const String &p_edited_property) {
  315. _update_current_preset();
  316. }
  317. void ProjectExportDialog::_runnable_pressed() {
  318. if (updating) {
  319. return;
  320. }
  321. Ref<EditorExportPreset> current = get_current_preset();
  322. ERR_FAIL_COND(current.is_null());
  323. if (runnable->is_pressed()) {
  324. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  325. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  326. if (p->get_platform() == current->get_platform()) {
  327. p->set_runnable(current == p);
  328. }
  329. }
  330. } else {
  331. current->set_runnable(false);
  332. }
  333. _update_presets();
  334. }
  335. void ProjectExportDialog::_name_changed(const String &p_string) {
  336. if (updating) {
  337. return;
  338. }
  339. Ref<EditorExportPreset> current = get_current_preset();
  340. ERR_FAIL_COND(current.is_null());
  341. current->set_name(p_string);
  342. _update_presets();
  343. }
  344. void ProjectExportDialog::set_export_path(const String &p_value) {
  345. Ref<EditorExportPreset> current = get_current_preset();
  346. ERR_FAIL_COND(current.is_null());
  347. current->set_export_path(p_value);
  348. }
  349. String ProjectExportDialog::get_export_path() {
  350. Ref<EditorExportPreset> current = get_current_preset();
  351. ERR_FAIL_COND_V(current.is_null(), String(""));
  352. return current->get_export_path();
  353. }
  354. Ref<EditorExportPreset> ProjectExportDialog::get_current_preset() const {
  355. return EditorExport::get_singleton()->get_export_preset(presets->get_current());
  356. }
  357. void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) {
  358. if (updating) {
  359. return;
  360. }
  361. Ref<EditorExportPreset> current = get_current_preset();
  362. ERR_FAIL_COND(current.is_null());
  363. current->set_export_path(p_value);
  364. _update_presets();
  365. _update_export_all();
  366. }
  367. void ProjectExportDialog::_open_key_help_link() {
  368. OS::get_singleton()->shell_open(vformat("%s/development/compiling/compiling_with_script_encryption_key.html", VERSION_DOCS_URL));
  369. }
  370. void ProjectExportDialog::_script_export_mode_changed(int p_mode) {
  371. if (updating) {
  372. return;
  373. }
  374. Ref<EditorExportPreset> current = get_current_preset();
  375. ERR_FAIL_COND(current.is_null());
  376. current->set_script_export_mode(p_mode);
  377. _update_current_preset();
  378. }
  379. void ProjectExportDialog::_script_encryption_key_changed(const String &p_key) {
  380. if (updating) {
  381. return;
  382. }
  383. Ref<EditorExportPreset> current = get_current_preset();
  384. ERR_FAIL_COND(current.is_null());
  385. current->set_script_encryption_key(p_key);
  386. updating_script_key = true;
  387. _update_current_preset();
  388. updating_script_key = false;
  389. }
  390. bool ProjectExportDialog::_validate_script_encryption_key(const String &p_key) {
  391. bool is_valid = false;
  392. if (!p_key.empty() && p_key.is_valid_hex_number(false) && p_key.length() == 64) {
  393. is_valid = true;
  394. }
  395. return is_valid;
  396. }
  397. void ProjectExportDialog::_duplicate_preset() {
  398. Ref<EditorExportPreset> current = get_current_preset();
  399. if (current.is_null()) {
  400. return;
  401. }
  402. Ref<EditorExportPreset> preset = current->get_platform()->create_preset();
  403. ERR_FAIL_COND(!preset.is_valid());
  404. String name = current->get_name() + " (copy)";
  405. bool make_runnable = true;
  406. while (true) {
  407. bool valid = true;
  408. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  409. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  410. if (p->get_platform() == preset->get_platform() && p->is_runnable()) {
  411. make_runnable = false;
  412. }
  413. if (p->get_name() == name) {
  414. valid = false;
  415. break;
  416. }
  417. }
  418. if (valid) {
  419. break;
  420. }
  421. name += " (copy)";
  422. }
  423. preset->set_name(name);
  424. if (make_runnable) {
  425. preset->set_runnable(make_runnable);
  426. }
  427. preset->set_export_filter(current->get_export_filter());
  428. preset->set_include_filter(current->get_include_filter());
  429. preset->set_exclude_filter(current->get_exclude_filter());
  430. preset->set_custom_features(current->get_custom_features());
  431. for (const List<PropertyInfo>::Element *E = current->get_properties().front(); E; E = E->next()) {
  432. preset->set(E->get().name, current->get(E->get().name));
  433. }
  434. EditorExport::get_singleton()->add_export_preset(preset);
  435. _update_presets();
  436. _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1);
  437. }
  438. void ProjectExportDialog::_delete_preset() {
  439. Ref<EditorExportPreset> current = get_current_preset();
  440. if (current.is_null()) {
  441. return;
  442. }
  443. delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"), current->get_name()));
  444. delete_confirm->popup_centered_minsize();
  445. }
  446. void ProjectExportDialog::_delete_preset_confirm() {
  447. int idx = presets->get_current();
  448. _edit_preset(-1);
  449. export_button->set_disabled(true);
  450. get_ok()->set_disabled(true);
  451. EditorExport::get_singleton()->remove_export_preset(idx);
  452. _update_presets();
  453. // The Export All button might become enabled (if all other presets have an export path defined),
  454. // or it could be disabled (if there are no presets anymore).
  455. _update_export_all();
  456. }
  457. Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  458. if (p_from == presets) {
  459. int pos = presets->get_item_at_position(p_point, true);
  460. if (pos >= 0) {
  461. Dictionary d;
  462. d["type"] = "export_preset";
  463. d["preset"] = pos;
  464. HBoxContainer *drag = memnew(HBoxContainer);
  465. TextureRect *tr = memnew(TextureRect);
  466. tr->set_texture(presets->get_item_icon(pos));
  467. drag->add_child(tr);
  468. Label *label = memnew(Label);
  469. label->set_text(presets->get_item_text(pos));
  470. drag->add_child(label);
  471. set_drag_preview(drag);
  472. return d;
  473. }
  474. }
  475. return Variant();
  476. }
  477. bool ProjectExportDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  478. if (p_from == presets) {
  479. Dictionary d = p_data;
  480. if (!d.has("type") || String(d["type"]) != "export_preset") {
  481. return false;
  482. }
  483. if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point)) {
  484. return false;
  485. }
  486. }
  487. return true;
  488. }
  489. void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  490. if (p_from == presets) {
  491. Dictionary d = p_data;
  492. int from_pos = d["preset"];
  493. int to_pos = -1;
  494. if (presets->get_item_at_position(p_point, true) >= 0) {
  495. to_pos = presets->get_item_at_position(p_point, true);
  496. }
  497. if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point)) {
  498. return;
  499. }
  500. if (to_pos == from_pos) {
  501. return;
  502. } else if (to_pos > from_pos) {
  503. to_pos--;
  504. }
  505. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(from_pos);
  506. EditorExport::get_singleton()->remove_export_preset(from_pos);
  507. EditorExport::get_singleton()->add_export_preset(preset, to_pos);
  508. _update_presets();
  509. if (to_pos >= 0) {
  510. _edit_preset(to_pos);
  511. } else {
  512. _edit_preset(presets->get_item_count() - 1);
  513. }
  514. }
  515. }
  516. void ProjectExportDialog::_export_type_changed(int p_which) {
  517. if (updating) {
  518. return;
  519. }
  520. Ref<EditorExportPreset> current = get_current_preset();
  521. if (current.is_null()) {
  522. return;
  523. }
  524. current->set_export_filter(EditorExportPreset::ExportFilter(p_which));
  525. updating = true;
  526. _fill_resource_tree();
  527. updating = false;
  528. }
  529. void ProjectExportDialog::_filter_changed(const String &p_filter) {
  530. if (updating) {
  531. return;
  532. }
  533. Ref<EditorExportPreset> current = get_current_preset();
  534. if (current.is_null()) {
  535. return;
  536. }
  537. current->set_include_filter(include_filters->get_text());
  538. current->set_exclude_filter(exclude_filters->get_text());
  539. }
  540. void ProjectExportDialog::_fill_resource_tree() {
  541. include_files->clear();
  542. include_label->hide();
  543. include_margin->hide();
  544. Ref<EditorExportPreset> current = get_current_preset();
  545. if (current.is_null()) {
  546. return;
  547. }
  548. EditorExportPreset::ExportFilter f = current->get_export_filter();
  549. if (f == EditorExportPreset::EXPORT_ALL_RESOURCES) {
  550. return;
  551. }
  552. include_label->show();
  553. include_margin->show();
  554. TreeItem *root = include_files->create_item();
  555. _fill_tree(EditorFileSystem::get_singleton()->get_filesystem(), root, current, f == EditorExportPreset::EXPORT_SELECTED_SCENES);
  556. }
  557. bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem *p_item, Ref<EditorExportPreset> &current, bool p_only_scenes) {
  558. p_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  559. p_item->set_icon(0, get_icon("folder", "FileDialog"));
  560. p_item->set_text(0, p_dir->get_name() + "/");
  561. p_item->set_editable(0, true);
  562. p_item->set_metadata(0, p_dir->get_path());
  563. bool used = false;
  564. bool checked = true;
  565. for (int i = 0; i < p_dir->get_subdir_count(); i++) {
  566. TreeItem *subdir = include_files->create_item(p_item);
  567. if (_fill_tree(p_dir->get_subdir(i), subdir, current, p_only_scenes)) {
  568. used = true;
  569. checked = checked && subdir->is_checked(0);
  570. } else {
  571. memdelete(subdir);
  572. }
  573. }
  574. for (int i = 0; i < p_dir->get_file_count(); i++) {
  575. String type = p_dir->get_file_type(i);
  576. if (p_only_scenes && type != "PackedScene") {
  577. continue;
  578. }
  579. TreeItem *file = include_files->create_item(p_item);
  580. file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  581. file->set_text(0, p_dir->get_file(i));
  582. String path = p_dir->get_file_path(i);
  583. file->set_icon(0, EditorNode::get_singleton()->get_class_icon(type));
  584. file->set_editable(0, true);
  585. file->set_checked(0, current->has_export_file(path));
  586. file->set_metadata(0, path);
  587. checked = checked && file->is_checked(0);
  588. used = true;
  589. }
  590. p_item->set_checked(0, checked);
  591. return used;
  592. }
  593. void ProjectExportDialog::_tree_changed() {
  594. if (updating) {
  595. return;
  596. }
  597. Ref<EditorExportPreset> current = get_current_preset();
  598. if (current.is_null()) {
  599. return;
  600. }
  601. TreeItem *item = include_files->get_edited();
  602. if (!item) {
  603. return;
  604. }
  605. String path = item->get_metadata(0);
  606. bool added = item->is_checked(0);
  607. if (path.ends_with("/")) {
  608. _check_dir_recursive(item, added);
  609. } else {
  610. if (added) {
  611. current->add_export_file(path);
  612. } else {
  613. current->remove_export_file(path);
  614. }
  615. }
  616. _refresh_parent_checks(item); // Makes parent folder checked if all files/folders are checked.
  617. }
  618. void ProjectExportDialog::_check_dir_recursive(TreeItem *p_dir, bool p_checked) {
  619. for (TreeItem *child = p_dir->get_children(); child; child = child->get_next()) {
  620. String path = child->get_metadata(0);
  621. child->set_checked(0, p_checked);
  622. if (path.ends_with("/")) {
  623. _check_dir_recursive(child, p_checked);
  624. } else {
  625. if (p_checked) {
  626. get_current_preset()->add_export_file(path);
  627. } else {
  628. get_current_preset()->remove_export_file(path);
  629. }
  630. }
  631. }
  632. }
  633. void ProjectExportDialog::_refresh_parent_checks(TreeItem *p_item) {
  634. TreeItem *parent = p_item->get_parent();
  635. if (!parent) {
  636. return;
  637. }
  638. bool checked = true;
  639. for (TreeItem *child = parent->get_children(); child; child = child->get_next()) {
  640. checked = checked && child->is_checked(0);
  641. if (!checked) {
  642. break;
  643. }
  644. }
  645. parent->set_checked(0, checked);
  646. _refresh_parent_checks(parent);
  647. }
  648. void ProjectExportDialog::_export_pck_zip() {
  649. Ref<EditorExportPreset> current = get_current_preset();
  650. ERR_FAIL_COND(current.is_null());
  651. String dir = current->get_export_path().get_base_dir();
  652. export_pck_zip->set_current_dir(dir);
  653. export_pck_zip->popup_centered_ratio();
  654. }
  655. void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {
  656. Ref<EditorExportPreset> current = get_current_preset();
  657. ERR_FAIL_COND(current.is_null());
  658. Ref<EditorExportPlatform> platform = current->get_platform();
  659. ERR_FAIL_COND(platform.is_null());
  660. if (p_path.ends_with(".zip")) {
  661. platform->export_zip(current, export_pck_zip_debug->is_pressed(), p_path);
  662. } else if (p_path.ends_with(".pck")) {
  663. platform->export_pack(current, export_pck_zip_debug->is_pressed(), p_path);
  664. }
  665. }
  666. void ProjectExportDialog::_open_export_template_manager() {
  667. EditorNode::get_singleton()->open_export_template_manager();
  668. hide();
  669. }
  670. void ProjectExportDialog::_validate_export_path(const String &p_path) {
  671. // Disable export via OK button or Enter key if LineEdit has an empty filename
  672. bool invalid_path = (p_path.get_file().get_basename() == "");
  673. // Check if state change before needlessly messing with signals
  674. if (invalid_path && export_project->get_ok()->is_disabled()) {
  675. return;
  676. }
  677. if (!invalid_path && !export_project->get_ok()->is_disabled()) {
  678. return;
  679. }
  680. if (invalid_path) {
  681. export_project->get_ok()->set_disabled(true);
  682. export_project->get_line_edit()->disconnect("text_entered", export_project, "_file_entered");
  683. } else {
  684. export_project->get_ok()->set_disabled(false);
  685. export_project->get_line_edit()->connect("text_entered", export_project, "_file_entered");
  686. }
  687. }
  688. void ProjectExportDialog::_export_project() {
  689. Ref<EditorExportPreset> current = get_current_preset();
  690. ERR_FAIL_COND(current.is_null());
  691. Ref<EditorExportPlatform> platform = current->get_platform();
  692. ERR_FAIL_COND(platform.is_null());
  693. export_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  694. export_project->clear_filters();
  695. List<String> extension_list = platform->get_binary_extensions(current);
  696. for (int i = 0; i < extension_list.size(); i++) {
  697. export_project->add_filter("*." + extension_list[i] + " ; " + platform->get_name() + " Export");
  698. }
  699. if (current->get_export_path() != "") {
  700. export_project->set_current_path(current->get_export_path());
  701. } else {
  702. if (extension_list.size() >= 1) {
  703. export_project->set_current_file(default_filename + "." + extension_list[0]);
  704. } else {
  705. export_project->set_current_file(default_filename);
  706. }
  707. }
  708. // Ensure that signal is connected if previous attempt left it disconnected with _validate_export_path
  709. if (!export_project->get_line_edit()->is_connected("text_entered", export_project, "_file_entered")) {
  710. export_project->get_ok()->set_disabled(false);
  711. export_project->get_line_edit()->connect("text_entered", export_project, "_file_entered");
  712. }
  713. export_project->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  714. export_project->popup_centered_ratio();
  715. }
  716. void ProjectExportDialog::_export_project_to_path(const String &p_path) {
  717. // Save this name for use in future exports (but drop the file extension)
  718. default_filename = p_path.get_file().get_basename();
  719. EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename);
  720. Ref<EditorExportPreset> current = get_current_preset();
  721. ERR_FAIL_COND(current.is_null());
  722. Ref<EditorExportPlatform> platform = current->get_platform();
  723. ERR_FAIL_COND(platform.is_null());
  724. current->set_export_path(p_path);
  725. platform->clear_messages();
  726. Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0);
  727. result_dialog_log->clear();
  728. if (err != ERR_SKIP) {
  729. if (platform->fill_log_messages(result_dialog_log, err)) {
  730. result_dialog->popup_centered_ratio(0.5);
  731. }
  732. }
  733. }
  734. void ProjectExportDialog::_export_all_dialog() {
  735. #ifndef ANDROID_ENABLED
  736. export_all_dialog->show();
  737. export_all_dialog->popup_centered_minsize(Size2(300, 80));
  738. #endif
  739. }
  740. void ProjectExportDialog::_export_all_dialog_action(const String &p_str) {
  741. export_all_dialog->hide();
  742. _export_all(p_str != "release");
  743. }
  744. void ProjectExportDialog::_export_all(bool p_debug) {
  745. String mode = p_debug ? TTR("Debug") : TTR("Release");
  746. EditorProgress ep("exportall", TTR("Exporting All") + " " + mode, EditorExport::get_singleton()->get_export_preset_count(), true);
  747. bool show_dialog = false;
  748. result_dialog_log->clear();
  749. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  750. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  751. ERR_FAIL_COND(preset.is_null());
  752. Ref<EditorExportPlatform> platform = preset->get_platform();
  753. ERR_FAIL_COND(platform.is_null());
  754. ep.step(preset->get_name(), i);
  755. platform->clear_messages();
  756. Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0);
  757. if (err == ERR_SKIP) {
  758. return;
  759. }
  760. bool has_messages = platform->fill_log_messages(result_dialog_log, err);
  761. show_dialog = show_dialog || has_messages;
  762. }
  763. if (show_dialog) {
  764. result_dialog->popup_centered_ratio(0.5);
  765. }
  766. }
  767. void ProjectExportDialog::_bind_methods() {
  768. ClassDB::bind_method("_add_preset", &ProjectExportDialog::_add_preset);
  769. ClassDB::bind_method("_edit_preset", &ProjectExportDialog::_edit_preset);
  770. ClassDB::bind_method("_update_parameters", &ProjectExportDialog::_update_parameters);
  771. ClassDB::bind_method("_runnable_pressed", &ProjectExportDialog::_runnable_pressed);
  772. ClassDB::bind_method("_name_changed", &ProjectExportDialog::_name_changed);
  773. ClassDB::bind_method("_duplicate_preset", &ProjectExportDialog::_duplicate_preset);
  774. ClassDB::bind_method("_delete_preset", &ProjectExportDialog::_delete_preset);
  775. ClassDB::bind_method("_delete_preset_confirm", &ProjectExportDialog::_delete_preset_confirm);
  776. ClassDB::bind_method("get_drag_data_fw", &ProjectExportDialog::get_drag_data_fw);
  777. ClassDB::bind_method("can_drop_data_fw", &ProjectExportDialog::can_drop_data_fw);
  778. ClassDB::bind_method("drop_data_fw", &ProjectExportDialog::drop_data_fw);
  779. ClassDB::bind_method("_export_type_changed", &ProjectExportDialog::_export_type_changed);
  780. ClassDB::bind_method("_filter_changed", &ProjectExportDialog::_filter_changed);
  781. ClassDB::bind_method("_tree_changed", &ProjectExportDialog::_tree_changed);
  782. ClassDB::bind_method("_export_pck_zip", &ProjectExportDialog::_export_pck_zip);
  783. ClassDB::bind_method("_export_pck_zip_selected", &ProjectExportDialog::_export_pck_zip_selected);
  784. ClassDB::bind_method("_open_export_template_manager", &ProjectExportDialog::_open_export_template_manager);
  785. ClassDB::bind_method("_validate_export_path", &ProjectExportDialog::_validate_export_path);
  786. ClassDB::bind_method("_export_path_changed", &ProjectExportDialog::_export_path_changed);
  787. ClassDB::bind_method("_open_key_help_link", &ProjectExportDialog::_open_key_help_link);
  788. ClassDB::bind_method("_script_export_mode_changed", &ProjectExportDialog::_script_export_mode_changed);
  789. ClassDB::bind_method("_script_encryption_key_changed", &ProjectExportDialog::_script_encryption_key_changed);
  790. ClassDB::bind_method("_export_project", &ProjectExportDialog::_export_project);
  791. ClassDB::bind_method("_export_project_to_path", &ProjectExportDialog::_export_project_to_path);
  792. ClassDB::bind_method("_export_all", &ProjectExportDialog::_export_all);
  793. ClassDB::bind_method("_export_all_dialog", &ProjectExportDialog::_export_all_dialog);
  794. ClassDB::bind_method("_export_all_dialog_action", &ProjectExportDialog::_export_all_dialog_action);
  795. ClassDB::bind_method("_custom_features_changed", &ProjectExportDialog::_custom_features_changed);
  796. ClassDB::bind_method("_tab_changed", &ProjectExportDialog::_tab_changed);
  797. ClassDB::bind_method("set_export_path", &ProjectExportDialog::set_export_path);
  798. ClassDB::bind_method("get_export_path", &ProjectExportDialog::get_export_path);
  799. ClassDB::bind_method("get_current_preset", &ProjectExportDialog::get_current_preset);
  800. ClassDB::bind_method("_force_update_current_preset_parameters", &ProjectExportDialog::_force_update_current_preset_parameters);
  801. ADD_PROPERTY(PropertyInfo(Variant::STRING, "export_path"), "set_export_path", "get_export_path");
  802. }
  803. ProjectExportDialog::ProjectExportDialog() {
  804. set_title(TTR("Export"));
  805. set_resizable(true);
  806. VBoxContainer *main_vb = memnew(VBoxContainer);
  807. add_child(main_vb);
  808. HSplitContainer *hbox = memnew(HSplitContainer);
  809. main_vb->add_child(hbox);
  810. hbox->set_v_size_flags(SIZE_EXPAND_FILL);
  811. // Presets list.
  812. VBoxContainer *preset_vb = memnew(VBoxContainer);
  813. preset_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  814. hbox->add_child(preset_vb);
  815. HBoxContainer *preset_hb = memnew(HBoxContainer);
  816. preset_hb->add_child(memnew(Label(TTR("Presets"))));
  817. preset_hb->add_spacer();
  818. preset_vb->add_child(preset_hb);
  819. add_preset = memnew(MenuButton);
  820. add_preset->set_text(TTR("Add..."));
  821. add_preset->get_popup()->connect("index_pressed", this, "_add_preset");
  822. preset_hb->add_child(add_preset);
  823. MarginContainer *mc = memnew(MarginContainer);
  824. preset_vb->add_child(mc);
  825. mc->set_v_size_flags(SIZE_EXPAND_FILL);
  826. presets = memnew(ItemList);
  827. presets->set_drag_forwarding(this);
  828. mc->add_child(presets);
  829. presets->connect("item_selected", this, "_edit_preset");
  830. duplicate_preset = memnew(ToolButton);
  831. duplicate_preset->set_tooltip(TTR("Duplicate"));
  832. preset_hb->add_child(duplicate_preset);
  833. duplicate_preset->connect("pressed", this, "_duplicate_preset");
  834. delete_preset = memnew(ToolButton);
  835. delete_preset->set_tooltip(TTR("Delete"));
  836. preset_hb->add_child(delete_preset);
  837. delete_preset->connect("pressed", this, "_delete_preset");
  838. // Preset settings.
  839. VBoxContainer *settings_vb = memnew(VBoxContainer);
  840. settings_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  841. hbox->add_child(settings_vb);
  842. name = memnew(LineEdit);
  843. settings_vb->add_margin_child(TTR("Name:"), name);
  844. name->connect("text_changed", this, "_name_changed");
  845. runnable = memnew(CheckButton);
  846. runnable->set_text(TTR("Runnable"));
  847. runnable->set_tooltip(TTR("If checked, the preset will be available for use in one-click deploy.\nOnly one preset per platform may be marked as runnable."));
  848. runnable->connect("pressed", this, "_runnable_pressed");
  849. settings_vb->add_child(runnable);
  850. export_path = memnew(EditorPropertyPath);
  851. settings_vb->add_child(export_path);
  852. export_path->set_label(TTR("Export Path"));
  853. export_path->set_object_and_property(this, "export_path");
  854. export_path->set_save_mode();
  855. export_path->connect("property_changed", this, "_export_path_changed");
  856. // Subsections.
  857. sections = memnew(TabContainer);
  858. sections->set_tab_align(TabContainer::ALIGN_LEFT);
  859. sections->set_use_hidden_tabs_for_min_size(true);
  860. settings_vb->add_child(sections);
  861. sections->set_v_size_flags(SIZE_EXPAND_FILL);
  862. // Main preset parameters.
  863. parameters = memnew(EditorInspector);
  864. sections->add_child(parameters);
  865. parameters->set_name(TTR("Options"));
  866. parameters->set_v_size_flags(SIZE_EXPAND_FILL);
  867. parameters->set_property_name_style(EditorPropertyNameProcessor::get_settings_style());
  868. parameters->connect("property_edited", this, "_update_parameters");
  869. EditorExport::get_singleton()->connect("export_presets_updated", this, "_force_update_current_preset_parameters");
  870. // Resources export parameters.
  871. VBoxContainer *resources_vb = memnew(VBoxContainer);
  872. sections->add_child(resources_vb);
  873. resources_vb->set_name(TTR("Resources"));
  874. export_filter = memnew(OptionButton);
  875. export_filter->add_item(TTR("Export all resources in the project"));
  876. export_filter->add_item(TTR("Export selected scenes (and dependencies)"));
  877. export_filter->add_item(TTR("Export selected resources (and dependencies)"));
  878. resources_vb->add_margin_child(TTR("Export Mode:"), export_filter);
  879. export_filter->connect("item_selected", this, "_export_type_changed");
  880. include_label = memnew(Label);
  881. include_label->set_text(TTR("Resources to export:"));
  882. resources_vb->add_child(include_label);
  883. include_margin = memnew(MarginContainer);
  884. include_margin->set_v_size_flags(SIZE_EXPAND_FILL);
  885. resources_vb->add_child(include_margin);
  886. include_files = memnew(Tree);
  887. include_margin->add_child(include_files);
  888. include_files->connect("item_edited", this, "_tree_changed");
  889. include_filters = memnew(LineEdit);
  890. resources_vb->add_margin_child(
  891. TTR("Filters to export non-resource files/folders\n(comma-separated, e.g: *.json, *.txt, docs/*)"),
  892. include_filters);
  893. include_filters->connect("text_changed", this, "_filter_changed");
  894. exclude_filters = memnew(LineEdit);
  895. resources_vb->add_margin_child(
  896. TTR("Filters to exclude files/folders from project\n(comma-separated, e.g: *.json, *.txt, docs/*)"),
  897. exclude_filters);
  898. exclude_filters->connect("text_changed", this, "_filter_changed");
  899. // Feature tags.
  900. VBoxContainer *feature_vb = memnew(VBoxContainer);
  901. feature_vb->set_name(TTR("Features"));
  902. custom_features = memnew(LineEdit);
  903. custom_features->connect("text_changed", this, "_custom_features_changed");
  904. feature_vb->add_margin_child(TTR("Custom (comma-separated):"), custom_features);
  905. custom_feature_display = memnew(RichTextLabel);
  906. custom_feature_display->set_v_size_flags(Control::SIZE_EXPAND_FILL);
  907. feature_vb->add_margin_child(TTR("Feature List:"), custom_feature_display, true);
  908. sections->add_child(feature_vb);
  909. // Script export parameters.
  910. updating_script_key = false;
  911. VBoxContainer *script_vb = memnew(VBoxContainer);
  912. script_vb->set_name(TTR("Script"));
  913. script_mode = memnew(OptionButton);
  914. script_vb->add_margin_child(TTR("GDScript Export Mode:"), script_mode);
  915. script_mode->add_item(TTR("Text"), (int)EditorExportPreset::MODE_SCRIPT_TEXT);
  916. script_mode->add_item(TTR("Compiled Bytecode (Faster Loading)"), (int)EditorExportPreset::MODE_SCRIPT_COMPILED);
  917. script_mode->add_item(TTR("Encrypted (Provide Key Below)"), (int)EditorExportPreset::MODE_SCRIPT_ENCRYPTED);
  918. script_mode->connect("item_selected", this, "_script_export_mode_changed");
  919. script_key = memnew(LineEdit);
  920. script_key->connect("text_changed", this, "_script_encryption_key_changed");
  921. script_key_error = memnew(Label);
  922. script_key_error->set_text(String::utf8("• ") + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)"));
  923. script_key_error->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  924. script_vb->add_margin_child(TTR("GDScript Encryption Key (256-bits as hexadecimal):"), script_key);
  925. script_vb->add_child(script_key_error);
  926. sections->add_child(script_vb);
  927. Label *sec_info = memnew(Label);
  928. sec_info->set_text(TTR("Note: Encryption key needs to be stored in the binary,\nyou need to build the export templates from source."));
  929. script_vb->add_child(sec_info);
  930. LinkButton *sec_more_info = memnew(LinkButton);
  931. sec_more_info->set_text(TTR("More Info..."));
  932. sec_more_info->connect("pressed", this, "_open_key_help_link");
  933. script_vb->add_child(sec_more_info);
  934. sections->connect("tab_changed", this, "_tab_changed");
  935. // Disable by default.
  936. name->set_editable(false);
  937. export_path->hide();
  938. runnable->set_disabled(true);
  939. duplicate_preset->set_disabled(true);
  940. delete_preset->set_disabled(true);
  941. script_key_error->hide();
  942. sections->hide();
  943. parameters->edit(nullptr);
  944. // Deletion dialog.
  945. delete_confirm = memnew(ConfirmationDialog);
  946. add_child(delete_confirm);
  947. delete_confirm->get_ok()->set_text(TTR("Delete"));
  948. delete_confirm->connect("confirmed", this, "_delete_preset_confirm");
  949. // Export buttons, dialogs and errors.
  950. updating = false;
  951. get_cancel()->set_text(TTR("Close"));
  952. get_ok()->set_text(TTR("Export PCK/Zip..."));
  953. get_ok()->set_disabled(true);
  954. #ifdef ANDROID_ENABLED
  955. export_button = memnew(Button);
  956. export_button->hide();
  957. #else
  958. export_button = add_button(TTR("Export Project..."), !OS::get_singleton()->get_swap_ok_cancel(), "export");
  959. #endif
  960. export_button->connect("pressed", this, "_export_project");
  961. // Disable initially before we select a valid preset
  962. export_button->set_disabled(true);
  963. export_all_dialog = memnew(ConfirmationDialog);
  964. add_child(export_all_dialog);
  965. export_all_dialog->set_title(TTR("Export All"));
  966. export_all_dialog->set_text(TTR("Choose an export mode:"));
  967. export_all_dialog->get_ok()->hide();
  968. export_all_dialog->add_button(TTR("Debug"), true, "debug");
  969. export_all_dialog->add_button(TTR("Release"), true, "release");
  970. export_all_dialog->connect("custom_action", this, "_export_all_dialog_action");
  971. #ifdef ANDROID_ENABLED
  972. export_all_dialog->hide();
  973. export_all_button = memnew(Button);
  974. export_all_button->hide();
  975. #else
  976. export_all_button = add_button(TTR("Export All..."), !OS::get_singleton()->get_swap_ok_cancel(), "export");
  977. #endif
  978. export_all_button->connect("pressed", this, "_export_all_dialog");
  979. export_all_button->set_disabled(true);
  980. export_pck_zip = memnew(EditorFileDialog);
  981. export_pck_zip->add_filter("*.zip ; " + TTR("ZIP File"));
  982. export_pck_zip->add_filter("*.pck ; " + TTR("Godot Project Pack"));
  983. export_pck_zip->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  984. export_pck_zip->set_mode(EditorFileDialog::MODE_SAVE_FILE);
  985. add_child(export_pck_zip);
  986. export_pck_zip->connect("file_selected", this, "_export_pck_zip_selected");
  987. export_error = memnew(Label);
  988. main_vb->add_child(export_error);
  989. export_error->hide();
  990. export_error->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  991. export_warning = memnew(Label);
  992. main_vb->add_child(export_warning);
  993. export_warning->hide();
  994. export_warning->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("warning_color", "Editor"));
  995. export_templates_error = memnew(HBoxContainer);
  996. main_vb->add_child(export_templates_error);
  997. export_templates_error->hide();
  998. Label *export_error2 = memnew(Label);
  999. export_templates_error->add_child(export_error2);
  1000. export_error2->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"));
  1001. export_error2->set_text(" - " + TTR("Export templates for this platform are missing:") + " ");
  1002. result_dialog = memnew(AcceptDialog);
  1003. result_dialog->set_title(TTR("Project Export"));
  1004. result_dialog_log = memnew(RichTextLabel);
  1005. result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE);
  1006. result_dialog->add_child(result_dialog_log);
  1007. main_vb->add_child(result_dialog);
  1008. result_dialog->hide();
  1009. LinkButton *download_templates = memnew(LinkButton);
  1010. download_templates->set_text(TTR("Manage Export Templates"));
  1011. download_templates->set_v_size_flags(SIZE_SHRINK_CENTER);
  1012. export_templates_error->add_child(download_templates);
  1013. download_templates->connect("pressed", this, "_open_export_template_manager");
  1014. export_project = memnew(EditorFileDialog);
  1015. export_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM);
  1016. add_child(export_project);
  1017. export_project->connect("file_selected", this, "_export_project_to_path");
  1018. export_project->get_line_edit()->connect("text_changed", this, "_validate_export_path");
  1019. export_debug = memnew(CheckBox);
  1020. export_debug->set_text(TTR("Export With Debug"));
  1021. export_debug->set_pressed(true);
  1022. export_debug->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  1023. export_project->get_vbox()->add_child(export_debug);
  1024. export_pck_zip_debug = memnew(CheckBox);
  1025. export_pck_zip_debug->set_text(TTR("Export With Debug"));
  1026. export_pck_zip_debug->set_pressed(true);
  1027. export_pck_zip_debug->set_h_size_flags(Control::SIZE_SHRINK_CENTER);
  1028. export_pck_zip->get_vbox()->add_child(export_pck_zip_debug);
  1029. set_hide_on_ok(false);
  1030. editor_icons = "EditorIcons";
  1031. default_filename = EditorSettings::get_singleton()->get_project_metadata("export_options", "default_filename", "");
  1032. // If no default set, use project name
  1033. if (default_filename == "") {
  1034. // If no project name defined, use a sane default
  1035. default_filename = ProjectSettings::get_singleton()->get("application/config/name");
  1036. if (default_filename == "") {
  1037. default_filename = "UnnamedProject";
  1038. }
  1039. }
  1040. }
  1041. ProjectExportDialog::~ProjectExportDialog() {
  1042. }