project_export.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  1. /*************************************************************************/
  2. /* project_export.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
  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 "compressed_translation.h"
  32. #include "editor_data.h"
  33. #include "editor_node.h"
  34. #include "editor_settings.h"
  35. #include "io/image_loader.h"
  36. #include "io/resource_loader.h"
  37. #include "io/resource_saver.h"
  38. #include "os/dir_access.h"
  39. #include "os/file_access.h"
  40. #include "os/os.h"
  41. #include "project_settings.h"
  42. #include "scene/gui/box_container.h"
  43. #include "scene/gui/margin_container.h"
  44. #include "scene/gui/scroll_container.h"
  45. #include "scene/gui/tab_container.h"
  46. void ProjectExportDialog::_notification(int p_what) {
  47. switch (p_what) {
  48. case NOTIFICATION_READY: {
  49. delete_preset->set_icon(get_icon("Remove", "EditorIcons"));
  50. connect("confirmed", this, "_export_pck_zip");
  51. custom_feature_display->get_parent_control()->add_style_override("panel", get_stylebox("bg", "Tree"));
  52. } break;
  53. case NOTIFICATION_POPUP_HIDE: {
  54. EditorSettings::get_singleton()->set("interface/dialogs/export_bounds", get_rect());
  55. } break;
  56. }
  57. }
  58. void ProjectExportDialog::popup_export() {
  59. add_preset->get_popup()->clear();
  60. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  61. Ref<EditorExportPlatform> plat = EditorExport::get_singleton()->get_export_platform(i);
  62. add_preset->get_popup()->add_icon_item(plat->get_logo(), plat->get_name());
  63. }
  64. _update_presets();
  65. // Restore valid window bounds or pop up at default size.
  66. if (EditorSettings::get_singleton()->has_setting("interface/dialogs/export_bounds")) {
  67. popup(EditorSettings::get_singleton()->get("interface/dialogs/export_bounds"));
  68. } else {
  69. popup_centered_ratio();
  70. }
  71. }
  72. void ProjectExportDialog::_add_preset(int p_platform) {
  73. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_platform(p_platform)->create_preset();
  74. ERR_FAIL_COND(!preset.is_valid());
  75. String name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name();
  76. bool make_runnable = true;
  77. int attempt = 1;
  78. while (true) {
  79. bool valid = true;
  80. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  81. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  82. if (p->get_platform() == preset->get_platform() && p->is_runnable()) {
  83. make_runnable = false;
  84. }
  85. if (p->get_name() == name) {
  86. valid = false;
  87. break;
  88. }
  89. }
  90. if (valid)
  91. break;
  92. attempt++;
  93. name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name() + " " + itos(attempt);
  94. }
  95. preset->set_name(name);
  96. if (make_runnable)
  97. preset->set_runnable(make_runnable);
  98. EditorExport::get_singleton()->add_export_preset(preset);
  99. _update_presets();
  100. _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1);
  101. }
  102. void ProjectExportDialog::_update_presets() {
  103. updating = true;
  104. Ref<EditorExportPreset> current;
  105. if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count())
  106. current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  107. int current_idx = -1;
  108. presets->clear();
  109. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  110. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
  111. if (preset == current) {
  112. current_idx = i;
  113. }
  114. String name = preset->get_name();
  115. if (preset->is_runnable())
  116. name += " (" + TTR("Runnable") + ")";
  117. presets->add_item(name, preset->get_platform()->get_logo());
  118. }
  119. if (current_idx != -1) {
  120. presets->select(current_idx);
  121. //_edit_preset(current_idx);
  122. }
  123. updating = false;
  124. }
  125. void ProjectExportDialog::_edit_preset(int p_index) {
  126. if (p_index < 0 || p_index >= presets->get_item_count()) {
  127. name->set_text("");
  128. name->set_editable(false);
  129. runnable->set_disabled(true);
  130. parameters->edit(NULL);
  131. delete_preset->set_disabled(true);
  132. sections->hide();
  133. patches->clear();
  134. export_error->hide();
  135. export_templates_error->hide();
  136. return;
  137. }
  138. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index);
  139. ERR_FAIL_COND(current.is_null());
  140. updating = true;
  141. presets->select(p_index);
  142. sections->show();
  143. name->set_editable(true);
  144. delete_preset->set_disabled(false);
  145. name->set_text(current->get_name());
  146. runnable->set_disabled(false);
  147. runnable->set_pressed(current->is_runnable());
  148. parameters->edit(current.ptr());
  149. export_filter->select(current->get_export_filter());
  150. include_filters->set_text(current->get_include_filter());
  151. exclude_filters->set_text(current->get_exclude_filter());
  152. patches->clear();
  153. TreeItem *patch_root = patches->create_item();
  154. Vector<String> patchlist = current->get_patches();
  155. for (int i = 0; i < patchlist.size(); i++) {
  156. TreeItem *patch = patches->create_item(patch_root);
  157. patch->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  158. String file = patchlist[i].get_file();
  159. patch->set_editable(0, true);
  160. patch->set_text(0, file.get_file().replace("*", ""));
  161. if (file.ends_with("*"))
  162. patch->set_checked(0, true);
  163. patch->set_tooltip(0, patchlist[i]);
  164. patch->set_metadata(0, i);
  165. patch->add_button(0, get_icon("Remove", "EditorIcons"), 0);
  166. patch->add_button(0, get_icon("folder", "FileDialog"), 1);
  167. }
  168. TreeItem *patch_add = patches->create_item(patch_root);
  169. patch_add->set_metadata(0, patchlist.size());
  170. if (patchlist.size() == 0)
  171. patch_add->set_text(0, "Add initial export..");
  172. else
  173. patch_add->set_text(0, "Add previous patches..");
  174. patch_add->add_button(0, get_icon("folder", "FileDialog"), 1);
  175. _fill_resource_tree();
  176. bool needs_templates;
  177. String error;
  178. if (!current->get_platform()->can_export(current, error, needs_templates)) {
  179. if (error != String()) {
  180. Vector<String> items = error.split("\n");
  181. error = "";
  182. for (int i = 0; i < items.size(); i++) {
  183. if (i > 0)
  184. error += "\n";
  185. error += " - " + items[i];
  186. }
  187. export_error->set_text(error);
  188. export_error->show();
  189. } else {
  190. export_error->hide();
  191. }
  192. if (needs_templates)
  193. export_templates_error->show();
  194. else
  195. export_templates_error->hide();
  196. export_button->set_disabled(true);
  197. } else {
  198. export_error->hide();
  199. export_templates_error->hide();
  200. export_button->set_disabled(false);
  201. }
  202. custom_features->set_text(current->get_custom_features());
  203. _update_feature_list();
  204. updating = false;
  205. }
  206. void ProjectExportDialog::_update_feature_list() {
  207. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  208. ERR_FAIL_COND(current.is_null());
  209. Set<String> fset;
  210. List<String> features;
  211. current->get_platform()->get_platform_features(&features);
  212. current->get_platform()->get_preset_features(current, &features);
  213. String custom = current->get_custom_features();
  214. Vector<String> custom_list = custom.split(",");
  215. for (int i = 0; i < custom_list.size(); i++) {
  216. String f = custom_list[i].strip_edges();
  217. if (f != String()) {
  218. features.push_back(f);
  219. }
  220. }
  221. for (List<String>::Element *E = features.front(); E; E = E->next()) {
  222. fset.insert(E->get());
  223. }
  224. custom_feature_display->clear();
  225. for (Set<String>::Element *E = fset.front(); E; E = E->next()) {
  226. String f = E->get();
  227. if (E->next()) {
  228. f += ", ";
  229. }
  230. custom_feature_display->add_text(f);
  231. }
  232. }
  233. void ProjectExportDialog::_custom_features_changed(const String &p_text) {
  234. if (updating)
  235. return;
  236. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  237. ERR_FAIL_COND(current.is_null());
  238. current->set_custom_features(p_text);
  239. _update_feature_list();
  240. }
  241. void ProjectExportDialog::_tab_changed(int) {
  242. _update_feature_list();
  243. }
  244. void ProjectExportDialog::_patch_button_pressed(Object *p_item, int p_column, int p_id) {
  245. TreeItem *ti = (TreeItem *)p_item;
  246. patch_index = ti->get_metadata(0);
  247. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  248. ERR_FAIL_COND(current.is_null());
  249. if (p_id == 0) {
  250. Vector<String> patches = current->get_patches();
  251. ERR_FAIL_INDEX(patch_index, patches.size());
  252. patch_erase->set_text(vformat(TTR("Delete patch '" + patches[patch_index].get_file() + "' from list?")));
  253. patch_erase->popup_centered_minsize();
  254. } else {
  255. patch_dialog->popup_centered_ratio();
  256. }
  257. }
  258. void ProjectExportDialog::_patch_edited() {
  259. TreeItem *item = patches->get_edited();
  260. if (!item)
  261. return;
  262. int index = item->get_metadata(0);
  263. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  264. ERR_FAIL_COND(current.is_null());
  265. Vector<String> patches = current->get_patches();
  266. ERR_FAIL_INDEX(index, patches.size());
  267. String patch = patches[index].replace("*", "");
  268. if (item->is_checked(0)) {
  269. patch += "*";
  270. }
  271. current->set_patch(index, patch);
  272. }
  273. void ProjectExportDialog::_patch_selected(const String &p_path) {
  274. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  275. ERR_FAIL_COND(current.is_null());
  276. Vector<String> patches = current->get_patches();
  277. if (patch_index >= patches.size()) {
  278. current->add_patch(ProjectSettings::get_singleton()->get_resource_path().path_to(p_path) + "*");
  279. } else {
  280. String enabled = patches[patch_index].ends_with("*") ? String("*") : String();
  281. current->set_patch(patch_index, ProjectSettings::get_singleton()->get_resource_path().path_to(p_path) + enabled);
  282. }
  283. _edit_preset(presets->get_current());
  284. }
  285. void ProjectExportDialog::_patch_deleted() {
  286. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  287. ERR_FAIL_COND(current.is_null());
  288. Vector<String> patches = current->get_patches();
  289. if (patch_index < patches.size()) {
  290. current->remove_patch(patch_index);
  291. _edit_preset(presets->get_current());
  292. }
  293. }
  294. void ProjectExportDialog::_update_parameters(const String &p_edited_property) {
  295. _edit_preset(presets->get_current());
  296. parameters->update_tree();
  297. }
  298. void ProjectExportDialog::_runnable_pressed() {
  299. if (updating)
  300. return;
  301. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  302. ERR_FAIL_COND(current.is_null());
  303. if (runnable->is_pressed()) {
  304. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  305. Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i);
  306. if (p->get_platform() == current->get_platform()) {
  307. p->set_runnable(current == p);
  308. }
  309. }
  310. } else {
  311. current->set_runnable(false);
  312. }
  313. _update_presets();
  314. }
  315. void ProjectExportDialog::_name_changed(const String &p_string) {
  316. if (updating)
  317. return;
  318. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  319. ERR_FAIL_COND(current.is_null());
  320. current->set_name(p_string);
  321. _update_presets();
  322. }
  323. void ProjectExportDialog::_delete_preset() {
  324. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  325. if (current.is_null())
  326. return;
  327. delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"), current->get_name()));
  328. delete_confirm->popup_centered_minsize();
  329. }
  330. void ProjectExportDialog::_delete_preset_confirm() {
  331. int idx = presets->get_current();
  332. parameters->edit(NULL); //to avoid crash
  333. _edit_preset(-1);
  334. EditorExport::get_singleton()->remove_export_preset(idx);
  335. _update_presets();
  336. _edit_preset(presets->get_current());
  337. }
  338. Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) {
  339. if (p_from == presets) {
  340. int pos = presets->get_item_at_position(p_point, true);
  341. if (pos >= 0) {
  342. Dictionary d;
  343. d["type"] = "export_preset";
  344. d["preset"] = pos;
  345. HBoxContainer *drag = memnew(HBoxContainer);
  346. TextureRect *tr = memnew(TextureRect);
  347. tr->set_texture(presets->get_item_icon(pos));
  348. drag->add_child(tr);
  349. Label *label = memnew(Label);
  350. label->set_text(presets->get_item_text(pos));
  351. drag->add_child(label);
  352. set_drag_preview(drag);
  353. return d;
  354. }
  355. } else if (p_from == patches) {
  356. TreeItem *item = patches->get_item_at_position(p_point);
  357. if (item && item->get_cell_mode(0) == TreeItem::CELL_MODE_CHECK) {
  358. int metadata = item->get_metadata(0);
  359. Dictionary d;
  360. d["type"] = "export_patch";
  361. d["patch"] = metadata;
  362. Label *label = memnew(Label);
  363. label->set_text(item->get_text(0));
  364. set_drag_preview(label);
  365. return d;
  366. }
  367. }
  368. return Variant();
  369. }
  370. bool ProjectExportDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const {
  371. if (p_from == presets) {
  372. Dictionary d = p_data;
  373. if (!d.has("type") || String(d["type"]) != "export_preset")
  374. return false;
  375. if (presets->get_item_at_position(p_point, true) < 0 && !presets->is_pos_at_end_of_items(p_point))
  376. return false;
  377. } else if (p_from == patches) {
  378. Dictionary d = p_data;
  379. if (!d.has("type") || String(d["type"]) != "export_patch")
  380. return false;
  381. patches->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM);
  382. TreeItem *item = patches->get_item_at_position(p_point);
  383. if (!item) {
  384. return false;
  385. }
  386. }
  387. return true;
  388. }
  389. void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) {
  390. if (p_from == presets) {
  391. Dictionary d = p_data;
  392. int from_pos = d["preset"];
  393. int to_pos = -1;
  394. if (presets->get_item_at_position(p_point, true) >= 0) {
  395. to_pos = presets->get_item_at_position(p_point, true);
  396. }
  397. if (to_pos == -1 && !presets->is_pos_at_end_of_items(p_point))
  398. return;
  399. if (to_pos == from_pos)
  400. return;
  401. else if (to_pos > from_pos) {
  402. to_pos--;
  403. }
  404. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(from_pos);
  405. EditorExport::get_singleton()->remove_export_preset(from_pos);
  406. EditorExport::get_singleton()->add_export_preset(preset, to_pos);
  407. _update_presets();
  408. if (to_pos >= 0)
  409. _edit_preset(to_pos);
  410. else
  411. _edit_preset(presets->get_item_count() - 1);
  412. } else if (p_from == patches) {
  413. Dictionary d = p_data;
  414. if (!d.has("type") || String(d["type"]) != "export_patch")
  415. return;
  416. int from_pos = d["patch"];
  417. TreeItem *item = patches->get_item_at_position(p_point);
  418. if (!item)
  419. return;
  420. int to_pos = item->get_cell_mode(0) == TreeItem::CELL_MODE_CHECK ? int(item->get_metadata(0)) : -1;
  421. if (to_pos == from_pos)
  422. return;
  423. else if (to_pos > from_pos) {
  424. to_pos--;
  425. }
  426. Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  427. String patch = preset->get_patch(from_pos);
  428. preset->remove_patch(from_pos);
  429. preset->add_patch(patch, to_pos);
  430. _edit_preset(presets->get_current());
  431. }
  432. }
  433. void ProjectExportDialog::_export_type_changed(int p_which) {
  434. if (updating)
  435. return;
  436. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  437. if (current.is_null())
  438. return;
  439. current->set_export_filter(EditorExportPreset::ExportFilter(p_which));
  440. updating = true;
  441. _fill_resource_tree();
  442. updating = false;
  443. }
  444. void ProjectExportDialog::_filter_changed(const String &p_filter) {
  445. if (updating)
  446. return;
  447. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  448. if (current.is_null())
  449. return;
  450. current->set_include_filter(include_filters->get_text());
  451. current->set_exclude_filter(exclude_filters->get_text());
  452. }
  453. void ProjectExportDialog::_fill_resource_tree() {
  454. include_files->clear();
  455. include_label->hide();
  456. include_margin->hide();
  457. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  458. if (current.is_null())
  459. return;
  460. EditorExportPreset::ExportFilter f = current->get_export_filter();
  461. if (f == EditorExportPreset::EXPORT_ALL_RESOURCES) {
  462. return;
  463. }
  464. include_label->show();
  465. include_margin->show();
  466. TreeItem *root = include_files->create_item();
  467. _fill_tree(EditorFileSystem::get_singleton()->get_filesystem(), root, current, f == EditorExportPreset::EXPORT_SELECTED_SCENES);
  468. }
  469. bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem *p_item, Ref<EditorExportPreset> &current, bool p_only_scenes) {
  470. p_item->set_icon(0, get_icon("folder", "FileDialog"));
  471. p_item->set_text(0, p_dir->get_name() + "/");
  472. bool used = false;
  473. for (int i = 0; i < p_dir->get_subdir_count(); i++) {
  474. TreeItem *subdir = include_files->create_item(p_item);
  475. if (_fill_tree(p_dir->get_subdir(i), subdir, current, p_only_scenes) == false) {
  476. memdelete(subdir);
  477. } else {
  478. used = true;
  479. }
  480. }
  481. for (int i = 0; i < p_dir->get_file_count(); i++) {
  482. String type = p_dir->get_file_type(i);
  483. if (p_only_scenes && type != "PackedScene")
  484. continue;
  485. TreeItem *file = include_files->create_item(p_item);
  486. file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
  487. file->set_text(0, p_dir->get_file(i));
  488. Ref<Texture> tex;
  489. if (has_icon(type, editor_icons)) {
  490. tex = get_icon(type, editor_icons);
  491. } else {
  492. tex = get_icon("Object", editor_icons);
  493. }
  494. String path = p_dir->get_file_path(i);
  495. file->set_icon(0, tex);
  496. file->set_editable(0, true);
  497. file->set_checked(0, current->has_export_file(path));
  498. file->set_metadata(0, path);
  499. used = true;
  500. }
  501. return used;
  502. }
  503. void ProjectExportDialog::_tree_changed() {
  504. if (updating)
  505. return;
  506. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  507. if (current.is_null())
  508. return;
  509. TreeItem *item = include_files->get_edited();
  510. if (!item)
  511. return;
  512. String path = item->get_metadata(0);
  513. bool added = item->is_checked(0);
  514. if (added) {
  515. current->add_export_file(path);
  516. } else {
  517. current->remove_export_file(path);
  518. }
  519. }
  520. void ProjectExportDialog::_export_pck_zip() {
  521. export_pck_zip->popup_centered_ratio();
  522. }
  523. void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) {
  524. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  525. ERR_FAIL_COND(current.is_null());
  526. Ref<EditorExportPlatform> platform = current->get_platform();
  527. ERR_FAIL_COND(platform.is_null());
  528. if (p_path.ends_with(".zip")) {
  529. platform->save_zip(current, p_path);
  530. } else if (p_path.ends_with(".pck")) {
  531. platform->save_pack(current, p_path);
  532. }
  533. }
  534. void ProjectExportDialog::_open_export_template_manager() {
  535. EditorNode::get_singleton()->open_export_template_manager();
  536. hide();
  537. }
  538. void ProjectExportDialog::_export_project() {
  539. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  540. ERR_FAIL_COND(current.is_null());
  541. Ref<EditorExportPlatform> platform = current->get_platform();
  542. ERR_FAIL_COND(platform.is_null());
  543. export_project->set_access(FileDialog::ACCESS_FILESYSTEM);
  544. export_project->clear_filters();
  545. String extension = platform->get_binary_extension();
  546. if (extension != String()) {
  547. export_project->add_filter("*." + extension + " ; " + platform->get_name() + " Export");
  548. }
  549. export_project->popup_centered_ratio();
  550. }
  551. void ProjectExportDialog::_export_project_to_path(const String &p_path) {
  552. Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(presets->get_current());
  553. ERR_FAIL_COND(current.is_null());
  554. Ref<EditorExportPlatform> platform = current->get_platform();
  555. ERR_FAIL_COND(platform.is_null());
  556. Error err = platform->export_project(current, export_debug->is_pressed(), p_path, 0);
  557. if (err != OK) {
  558. error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted: ") + platform->get_name());
  559. error_dialog->show();
  560. error_dialog->popup_centered_minsize(Size2(300, 80));
  561. ERR_PRINT("Failed to export project");
  562. }
  563. }
  564. void ProjectExportDialog::_bind_methods() {
  565. ClassDB::bind_method("_add_preset", &ProjectExportDialog::_add_preset);
  566. ClassDB::bind_method("_edit_preset", &ProjectExportDialog::_edit_preset);
  567. ClassDB::bind_method("_update_parameters", &ProjectExportDialog::_update_parameters);
  568. ClassDB::bind_method("_runnable_pressed", &ProjectExportDialog::_runnable_pressed);
  569. ClassDB::bind_method("_name_changed", &ProjectExportDialog::_name_changed);
  570. ClassDB::bind_method("_delete_preset", &ProjectExportDialog::_delete_preset);
  571. ClassDB::bind_method("_delete_preset_confirm", &ProjectExportDialog::_delete_preset_confirm);
  572. ClassDB::bind_method("get_drag_data_fw", &ProjectExportDialog::get_drag_data_fw);
  573. ClassDB::bind_method("can_drop_data_fw", &ProjectExportDialog::can_drop_data_fw);
  574. ClassDB::bind_method("drop_data_fw", &ProjectExportDialog::drop_data_fw);
  575. ClassDB::bind_method("_export_type_changed", &ProjectExportDialog::_export_type_changed);
  576. ClassDB::bind_method("_filter_changed", &ProjectExportDialog::_filter_changed);
  577. ClassDB::bind_method("_tree_changed", &ProjectExportDialog::_tree_changed);
  578. ClassDB::bind_method("_patch_button_pressed", &ProjectExportDialog::_patch_button_pressed);
  579. ClassDB::bind_method("_patch_selected", &ProjectExportDialog::_patch_selected);
  580. ClassDB::bind_method("_patch_deleted", &ProjectExportDialog::_patch_deleted);
  581. ClassDB::bind_method("_patch_edited", &ProjectExportDialog::_patch_edited);
  582. ClassDB::bind_method("_export_pck_zip", &ProjectExportDialog::_export_pck_zip);
  583. ClassDB::bind_method("_export_pck_zip_selected", &ProjectExportDialog::_export_pck_zip_selected);
  584. ClassDB::bind_method("_open_export_template_manager", &ProjectExportDialog::_open_export_template_manager);
  585. ClassDB::bind_method("_export_project", &ProjectExportDialog::_export_project);
  586. ClassDB::bind_method("_export_project_to_path", &ProjectExportDialog::_export_project_to_path);
  587. ClassDB::bind_method("_custom_features_changed", &ProjectExportDialog::_custom_features_changed);
  588. ClassDB::bind_method("_tab_changed", &ProjectExportDialog::_tab_changed);
  589. }
  590. ProjectExportDialog::ProjectExportDialog() {
  591. set_title(TTR("Export"));
  592. set_resizable(true);
  593. VBoxContainer *main_vb = memnew(VBoxContainer);
  594. add_child(main_vb);
  595. HBoxContainer *hbox = memnew(HBoxContainer);
  596. main_vb->add_child(hbox);
  597. hbox->set_v_size_flags(SIZE_EXPAND_FILL);
  598. VBoxContainer *preset_vb = memnew(VBoxContainer);
  599. preset_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  600. hbox->add_child(preset_vb);
  601. HBoxContainer *preset_hb = memnew(HBoxContainer);
  602. preset_hb->add_child(memnew(Label(TTR("Presets"))));
  603. preset_hb->add_spacer();
  604. preset_vb->add_child(preset_hb);
  605. add_preset = memnew(MenuButton);
  606. add_preset->set_text(TTR("Add.."));
  607. add_preset->get_popup()->connect("index_pressed", this, "_add_preset");
  608. preset_hb->add_child(add_preset);
  609. MarginContainer *mc = memnew(MarginContainer);
  610. preset_vb->add_child(mc);
  611. mc->set_v_size_flags(SIZE_EXPAND_FILL);
  612. presets = memnew(ItemList);
  613. presets->set_drag_forwarding(this);
  614. mc->add_child(presets);
  615. presets->connect("item_selected", this, "_edit_preset");
  616. delete_preset = memnew(ToolButton);
  617. preset_hb->add_child(delete_preset);
  618. delete_preset->connect("pressed", this, "_delete_preset");
  619. VBoxContainer *settings_vb = memnew(VBoxContainer);
  620. settings_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
  621. hbox->add_child(settings_vb);
  622. name = memnew(LineEdit);
  623. settings_vb->add_margin_child(TTR("Name:"), name);
  624. name->connect("text_changed", this, "_name_changed");
  625. runnable = memnew(CheckButton);
  626. runnable->set_text(TTR("Runnable"));
  627. runnable->connect("pressed", this, "_runnable_pressed");
  628. settings_vb->add_child(runnable);
  629. sections = memnew(TabContainer);
  630. sections->set_tab_align(TabContainer::ALIGN_LEFT);
  631. settings_vb->add_child(sections);
  632. sections->set_v_size_flags(SIZE_EXPAND_FILL);
  633. parameters = memnew(PropertyEditor);
  634. sections->add_child(parameters);
  635. parameters->set_name(TTR("Options"));
  636. parameters->hide_top_label();
  637. parameters->set_v_size_flags(SIZE_EXPAND_FILL);
  638. parameters->connect("property_edited", this, "_update_parameters");
  639. VBoxContainer *resources_vb = memnew(VBoxContainer);
  640. sections->add_child(resources_vb);
  641. resources_vb->set_name(TTR("Resources"));
  642. export_filter = memnew(OptionButton);
  643. export_filter->add_item(TTR("Export all resources in the project"));
  644. export_filter->add_item(TTR("Export selected scenes (and dependencies)"));
  645. export_filter->add_item(TTR("Export selected resources (and dependencies)"));
  646. resources_vb->add_margin_child(TTR("Export Mode:"), export_filter);
  647. export_filter->connect("item_selected", this, "_export_type_changed");
  648. include_label = memnew(Label);
  649. include_label->set_text(TTR("Resources to export:"));
  650. resources_vb->add_child(include_label);
  651. include_margin = memnew(MarginContainer);
  652. include_margin->set_v_size_flags(SIZE_EXPAND_FILL);
  653. resources_vb->add_child(include_margin);
  654. include_files = memnew(Tree);
  655. include_margin->add_child(include_files);
  656. include_files->connect("item_edited", this, "_tree_changed");
  657. include_filters = memnew(LineEdit);
  658. resources_vb->add_margin_child(TTR("Filters to export non-resource files (comma separated, e.g: *.json, *.txt)"), include_filters);
  659. include_filters->connect("text_changed", this, "_filter_changed");
  660. exclude_filters = memnew(LineEdit);
  661. resources_vb->add_margin_child(TTR("Filters to exclude files from project (comma separated, e.g: *.json, *.txt)"), exclude_filters);
  662. exclude_filters->connect("text_changed", this, "_filter_changed");
  663. VBoxContainer *patch_vb = memnew(VBoxContainer);
  664. sections->add_child(patch_vb);
  665. patch_vb->set_name(TTR("Patches"));
  666. patches = memnew(Tree);
  667. patch_vb->add_child(patches);
  668. patches->set_v_size_flags(SIZE_EXPAND_FILL);
  669. patches->set_hide_root(true);
  670. patches->connect("button_pressed", this, "_patch_button_pressed");
  671. patches->connect("item_edited", this, "_patch_edited");
  672. patches->set_drag_forwarding(this);
  673. patches->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true);
  674. HBoxContainer *patches_hb = memnew(HBoxContainer);
  675. patch_vb->add_child(patches_hb);
  676. patches_hb->add_spacer();
  677. patch_export = memnew(Button);
  678. patch_export->set_text(TTR("Make Patch"));
  679. patches_hb->add_child(patch_export);
  680. patches_hb->add_spacer();
  681. patch_dialog = memnew(FileDialog);
  682. patch_dialog->add_filter("*.pck ; Pack File");
  683. patch_dialog->set_mode(FileDialog::MODE_OPEN_FILE);
  684. patch_dialog->connect("file_selected", this, "_patch_selected");
  685. add_child(patch_dialog);
  686. patch_erase = memnew(ConfirmationDialog);
  687. patch_erase->get_ok()->set_text(TTR("Delete"));
  688. patch_erase->connect("confirmed", this, "_patch_deleted");
  689. add_child(patch_erase);
  690. VBoxContainer *feature_vb = memnew(VBoxContainer);
  691. feature_vb->set_name(TTR("Features"));
  692. custom_features = memnew(LineEdit);
  693. custom_features->connect("text_changed", this, "_custom_features_changed");
  694. feature_vb->add_margin_child(TTR("Custom (comma-separated):"), custom_features);
  695. Panel *features_panel = memnew(Panel);
  696. custom_feature_display = memnew(RichTextLabel);
  697. features_panel->add_child(custom_feature_display);
  698. custom_feature_display->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 10 * EDSCALE);
  699. custom_feature_display->set_v_size_flags(SIZE_EXPAND_FILL);
  700. feature_vb->add_margin_child(TTR("Feature List:"), features_panel, true);
  701. sections->add_child(feature_vb);
  702. sections->connect("tab_changed", this, "_tab_changed");
  703. //disable by default
  704. name->set_editable(false);
  705. runnable->set_disabled(true);
  706. delete_preset->set_disabled(true);
  707. sections->hide();
  708. parameters->edit(NULL);
  709. delete_confirm = memnew(ConfirmationDialog);
  710. add_child(delete_confirm);
  711. delete_confirm->get_ok()->set_text(TTR("Delete"));
  712. delete_confirm->connect("confirmed", this, "_delete_preset_confirm");
  713. updating = false;
  714. get_cancel()->set_text(TTR("Close"));
  715. get_ok()->set_text(TTR("Export PCK/Zip"));
  716. export_button = add_button(TTR("Export Project"), !OS::get_singleton()->get_swap_ok_cancel(), "export");
  717. export_pck_zip = memnew(FileDialog);
  718. export_pck_zip->add_filter("*.zip ; ZIP File");
  719. export_pck_zip->add_filter("*.pck ; Godot Game Pack");
  720. export_pck_zip->set_access(FileDialog::ACCESS_FILESYSTEM);
  721. export_pck_zip->set_mode(FileDialog::MODE_SAVE_FILE);
  722. add_child(export_pck_zip);
  723. export_pck_zip->connect("file_selected", this, "_export_pck_zip_selected");
  724. export_error = memnew(Label);
  725. main_vb->add_child(export_error);
  726. export_error->hide();
  727. export_error->add_color_override("font_color", get_color("error_color", "Editor"));
  728. export_templates_error = memnew(HBoxContainer);
  729. main_vb->add_child(export_templates_error);
  730. export_templates_error->hide();
  731. Label *export_error2 = memnew(Label);
  732. export_templates_error->add_child(export_error2);
  733. export_error2->add_color_override("font_color", get_color("error_color", "Editor"));
  734. export_error2->set_text(" - " + TTR("Export templates for this platform are missing:") + " ");
  735. error_dialog = memnew(AcceptDialog);
  736. error_dialog->set_title("Error");
  737. error_dialog->set_text(TTR("Export templates for this platform are missing/corrupted:") + " ");
  738. main_vb->add_child(error_dialog);
  739. error_dialog->hide();
  740. LinkButton *download_templates = memnew(LinkButton);
  741. download_templates->set_text(TTR("Manage Export Templates"));
  742. export_templates_error->add_child(download_templates);
  743. download_templates->connect("pressed", this, "_open_export_template_manager");
  744. export_project = memnew(FileDialog);
  745. export_project->set_access(FileDialog::ACCESS_FILESYSTEM);
  746. add_child(export_project);
  747. export_project->connect("file_selected", this, "_export_project_to_path");
  748. export_button->connect("pressed", this, "_export_project");
  749. export_debug = memnew(CheckButton);
  750. export_debug->set_text(TTR("Export With Debug"));
  751. export_debug->set_pressed(true);
  752. export_project->get_vbox()->add_child(export_debug);
  753. set_hide_on_ok(false);
  754. editor_icons = "EditorIcons";
  755. }
  756. ProjectExportDialog::~ProjectExportDialog() {
  757. }