| 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 | |
| 31 | #include "project_export.h" |
| 32 | |
| 33 | #include "core/config/project_settings.h" |
| 34 | #include "core/version.h" |
| 35 | #include "editor/editor_node.h" |
| 36 | #include "editor/editor_string_names.h" |
| 37 | #include "editor/export/editor_export.h" |
| 38 | #include "editor/file_system/editor_file_system.h" |
| 39 | #include "editor/gui/editor_file_dialog.h" |
| 40 | #include "editor/import/resource_importer_texture_settings.h" |
| 41 | #include "editor/inspector/editor_properties.h" |
| 42 | #include "editor/settings/editor_settings.h" |
| 43 | #include "editor/settings/project_settings_editor.h" |
| 44 | #include "editor/themes/editor_scale.h" |
| 45 | #include "scene/gui/check_button.h" |
| 46 | #include "scene/gui/item_list.h" |
| 47 | #include "scene/gui/line_edit.h" |
| 48 | #include "scene/gui/link_button.h" |
| 49 | #include "scene/gui/margin_container.h" |
| 50 | #include "scene/gui/menu_button.h" |
| 51 | #include "scene/gui/option_button.h" |
| 52 | #include "scene/gui/popup_menu.h" |
| 53 | #include "scene/gui/rich_text_label.h" |
| 54 | #include "scene/gui/spin_box.h" |
| 55 | #include "scene/gui/split_container.h" |
| 56 | #include "scene/gui/tab_container.h" |
| 57 | #include "scene/gui/texture_rect.h" |
| 58 | #include "scene/gui/tree.h" |
| 59 | |
| 60 | #include <zstd.h> |
| 61 | |
| 62 | void ProjectExportTextureFormatError::_on_fix_texture_format_pressed() { |
| 63 | export_dialog->hide(); |
| 64 | ProjectSettingsEditor *project_settings = EditorNode::get_singleton()->get_project_settings(); |
| 65 | project_settings->set_general_page("rendering/textures"); |
| 66 | project_settings->set_filter(setting_identifier); |
| 67 | project_settings->popup_project_settings(false); |
| 68 | } |
| 69 | |
| 70 | void ProjectExportTextureFormatError::_bind_methods() { |
| 71 | } |
| 72 | |
| 73 | void ProjectExportTextureFormatError::_notification(int p_what) { |
| 74 | switch (p_what) { |
| 75 | case NOTIFICATION_THEME_CHANGED: { |
| 76 | texture_format_error_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor))); |
| 77 | } break; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | void ProjectExportTextureFormatError::show_for_texture_format(const String &p_friendly_name, const String &p_setting_identifier) { |
| 82 | 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_char('/', ' '))); |
| 83 | setting_identifier = p_setting_identifier; |
| 84 | show(); |
| 85 | } |
| 86 | |
| 87 | ProjectExportTextureFormatError::ProjectExportTextureFormatError(ProjectExportDialog *p_export_dialog) { |
| 88 | export_dialog = p_export_dialog; |
| 89 | // Set up the label. |
| 90 | texture_format_error_label = memnew(Label); |
| 91 | texture_format_error_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 92 | add_child(texture_format_error_label); |
| 93 | // Set up the fix button. |
| 94 | fix_texture_format_button = memnew(LinkButton); |
| 95 | fix_texture_format_button->set_v_size_flags(Control::SIZE_SHRINK_CENTER); |
| 96 | fix_texture_format_button->set_text(TTR("Show Project Setting")); |
| 97 | add_child(fix_texture_format_button); |
| 98 | fix_texture_format_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportTextureFormatError::_on_fix_texture_format_pressed)); |
| 99 | } |
| 100 | |
| 101 | void ProjectExportDialog::_notification(int p_what) { |
| 102 | switch (p_what) { |
| 103 | case NOTIFICATION_VISIBILITY_CHANGED: { |
| 104 | if (!is_visible()) { |
| 105 | EditorSettings::get_singleton()->set_project_metadata("dialog_bounds", "export", Rect2(get_position(), get_size())); |
| 106 | show_script_key->set_pressed(false); |
| 107 | } |
| 108 | } break; |
| 109 | |
| 110 | case NOTIFICATION_THEME_CHANGED: { |
| 111 | _script_encryption_key_visibility_changed(show_script_key->is_pressed()); |
| 112 | duplicate_preset->set_button_icon(presets->get_editor_theme_icon(SNAME("Duplicate"))); |
| 113 | delete_preset->set_button_icon(presets->get_editor_theme_icon(SNAME("Remove"))); |
| 114 | patch_add_btn->set_button_icon(get_editor_theme_icon(SNAME("Add"))); |
| 115 | } break; |
| 116 | |
| 117 | case NOTIFICATION_READY: { |
| 118 | duplicate_preset->set_button_icon(presets->get_editor_theme_icon(SNAME("Duplicate"))); |
| 119 | delete_preset->set_button_icon(presets->get_editor_theme_icon(SNAME("Remove"))); |
| 120 | patch_add_btn->set_button_icon(get_editor_theme_icon(SNAME("Add"))); |
| 121 | connect(SceneStringName(confirmed), callable_mp(this, &ProjectExportDialog::_export_pck_zip)); |
| 122 | _update_export_all(); |
| 123 | } break; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | void ProjectExportDialog::popup_export() { |
| 128 | add_preset->get_popup()->clear(); |
| 129 | for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) { |
| 130 | Ref<EditorExportPlatform> plat = EditorExport::get_singleton()->get_export_platform(i); |
| 131 | |
| 132 | add_preset->get_popup()->add_icon_item(plat->get_logo(), plat->get_name()); |
| 133 | } |
| 134 | |
| 135 | _update_presets(); |
| 136 | if (presets->get_current() >= 0) { |
| 137 | _update_current_preset(); // triggers rescan for templates if newly installed |
| 138 | } |
| 139 | |
| 140 | // Restore valid window bounds or pop up at default size. |
| 141 | Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "export", Rect2()); |
| 142 | if (saved_size != Rect2()) { |
| 143 | popup(saved_size); |
| 144 | } else { |
| 145 | popup_centered_clamped(Size2(900, 500) * EDSCALE, 0.7); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void ProjectExportDialog::_add_preset(int p_platform) { |
| 150 | Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_platform(p_platform)->create_preset(); |
| 151 | ERR_FAIL_COND(preset.is_null()); |
| 152 | |
| 153 | String preset_name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name(); |
| 154 | bool make_runnable = true; |
| 155 | int attempt = 1; |
| 156 | while (true) { |
| 157 | bool valid = true; |
| 158 | |
| 159 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 160 | Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i); |
| 161 | if (p->get_platform() == preset->get_platform() && p->is_runnable()) { |
| 162 | make_runnable = false; |
| 163 | } |
| 164 | if (p->get_name() == preset_name) { |
| 165 | valid = false; |
| 166 | break; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | if (valid) { |
| 171 | break; |
| 172 | } |
| 173 | |
| 174 | attempt++; |
| 175 | preset_name = EditorExport::get_singleton()->get_export_platform(p_platform)->get_name() + " " + itos(attempt); |
| 176 | } |
| 177 | |
| 178 | preset->set_name(preset_name); |
| 179 | if (make_runnable) { |
| 180 | preset->set_runnable(make_runnable); |
| 181 | } |
| 182 | EditorExport::get_singleton()->add_export_preset(preset); |
| 183 | _update_presets(); |
| 184 | _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1); |
| 185 | } |
| 186 | |
| 187 | void ProjectExportDialog::_force_update_current_preset_parameters() { |
| 188 | // Force the parameters section to refresh its UI. |
| 189 | parameters->edit(nullptr); |
| 190 | _update_current_preset(); |
| 191 | } |
| 192 | |
| 193 | void ProjectExportDialog::_update_current_preset() { |
| 194 | _edit_preset(presets->get_current()); |
| 195 | } |
| 196 | |
| 197 | void ProjectExportDialog::_update_presets() { |
| 198 | updating = true; |
| 199 | |
| 200 | Ref<EditorExportPreset> current; |
| 201 | if (presets->get_current() >= 0 && presets->get_current() < presets->get_item_count()) { |
| 202 | current = get_current_preset(); |
| 203 | } |
| 204 | |
| 205 | int current_idx = -1; |
| 206 | int preset_count = EditorExport::get_singleton()->get_export_preset_count(); |
| 207 | presets->clear(); |
| 208 | for (int i = 0; i < preset_count; i++) { |
| 209 | Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i); |
| 210 | if (preset == current) { |
| 211 | current_idx = i; |
| 212 | } else if (current.is_null()) { |
| 213 | current_idx = i; |
| 214 | _edit_preset(i); |
| 215 | } |
| 216 | |
| 217 | String preset_name = preset->get_name(); |
| 218 | if (preset->is_runnable()) { |
| 219 | preset_name += " (" + TTR("Runnable") + ")"; |
| 220 | } |
| 221 | preset->update_files(); |
| 222 | presets->add_item(preset_name, preset->get_platform()->get_logo()); |
| 223 | } |
| 224 | |
| 225 | settings_vb->set_visible(current_idx != -1); |
| 226 | empty_label->set_visible(current_idx == -1); |
| 227 | |
| 228 | if (current_idx != -1) { |
| 229 | presets->select(current_idx); |
| 230 | } |
| 231 | |
| 232 | updating = false; |
| 233 | } |
| 234 | |
| 235 | void ProjectExportDialog::_update_export_all() { |
| 236 | bool can_export = EditorExport::get_singleton()->get_export_preset_count() > 0; |
| 237 | |
| 238 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 239 | Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i); |
| 240 | bool needs_templates; |
| 241 | String error; |
| 242 | if (preset->get_export_path().is_empty() || !preset->get_platform()->can_export(preset, error, needs_templates)) { |
| 243 | can_export = false; |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | export_all_button->set_disabled(!can_export); |
| 249 | |
| 250 | if (can_export) { |
| 251 | export_all_button->set_tooltip_text(TTR("Export the project for all the presets defined.")); |
| 252 | } else { |
| 253 | export_all_button->set_tooltip_text(TTR("All presets must have an export path defined for Export All to work.")); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | void ProjectExportDialog::_edit_preset(int p_index) { |
| 258 | if (p_index < 0 || p_index >= presets->get_item_count()) { |
| 259 | parameters->edit(nullptr); |
| 260 | presets->deselect_all(); |
| 261 | duplicate_preset->set_disabled(true); |
| 262 | delete_preset->set_disabled(true); |
| 263 | patches->clear(); |
| 264 | export_error->hide(); |
| 265 | export_templates_error->hide(); |
| 266 | export_texture_format_error->hide(); |
| 267 | return; |
| 268 | } |
| 269 | |
| 270 | Ref<EditorExportPreset> current = EditorExport::get_singleton()->get_export_preset(p_index); |
| 271 | ERR_FAIL_COND(current.is_null()); |
| 272 | |
| 273 | updating = true; |
| 274 | |
| 275 | presets->select(p_index); |
| 276 | duplicate_preset->set_disabled(false); |
| 277 | delete_preset->set_disabled(false); |
| 278 | get_ok_button()->set_disabled(false); |
| 279 | name->set_text(current->get_name()); |
| 280 | |
| 281 | List<String> extension_list = current->get_platform()->get_binary_extensions(current); |
| 282 | Vector<String> extension_vector; |
| 283 | for (const String &extension : extension_list) { |
| 284 | extension_vector.push_back("*." + extension); |
| 285 | } |
| 286 | |
| 287 | export_path->get_path_edit()->clear(); |
| 288 | export_path->setup(extension_vector, false, true, false); |
| 289 | export_path->update_property(); |
| 290 | runnable->set_pressed(current->is_runnable()); |
| 291 | if (parameters->get_edited_object() != current.ptr()) { |
| 292 | current->update_value_overrides(); |
| 293 | } |
| 294 | parameters->set_object_class(current->get_platform()->get_class_name()); |
| 295 | parameters->edit(current.ptr()); |
| 296 | |
| 297 | export_filter->select(current->get_export_filter()); |
| 298 | include_filters->set_text(current->get_include_filter()); |
| 299 | include_label->set_text(_get_resource_export_header(current->get_export_filter())); |
| 300 | exclude_filters->set_text(current->get_exclude_filter()); |
| 301 | server_strip_message->set_visible(current->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED); |
| 302 | |
| 303 | bool patch_delta_encoding_enabled = current->is_patch_delta_encoding_enabled(); |
| 304 | patch_delta_encoding->set_pressed(patch_delta_encoding_enabled); |
| 305 | patch_delta_zstd_level->set_editable(patch_delta_encoding_enabled); |
| 306 | patch_delta_zstd_level->set_value(current->get_patch_delta_zstd_level()); |
| 307 | patch_delta_min_reduction->set_editable(patch_delta_encoding_enabled); |
| 308 | patch_delta_min_reduction->set_value(current->get_patch_delta_min_reduction() * 100); |
| 309 | patch_delta_include_filter->set_editable(patch_delta_encoding_enabled); |
| 310 | patch_delta_exclude_filter->set_editable(patch_delta_encoding_enabled); |
| 311 | if (!updating_patch_delta_filters) { |
| 312 | patch_delta_include_filter->set_text(current->get_patch_delta_include_filter()); |
| 313 | patch_delta_exclude_filter->set_text(current->get_patch_delta_exclude_filter()); |
| 314 | } |
| 315 | |
| 316 | patches->clear(); |
| 317 | TreeItem *patch_root = patches->create_item(); |
| 318 | Vector<String> patch_list = current->get_patches(); |
| 319 | for (int i = 0; i < patch_list.size(); i++) { |
| 320 | TreeItem *patch = patches->create_item(patch_root); |
| 321 | const String &patch_path = patch_list[i]; |
| 322 | patch->set_cell_mode(0, TreeItem::CELL_MODE_STRING); |
| 323 | patch->set_editable(0, true); |
| 324 | patch->set_text(0, patch_path.get_file()); |
| 325 | patch->set_tooltip_text(0, patch_path); |
| 326 | patch->set_metadata(0, i); |
| 327 | patch->add_button(0, get_editor_theme_icon(SNAME("Remove")), 0); |
| 328 | patch->add_button(0, get_editor_theme_icon(SNAME("FileBrowse")), 1); |
| 329 | } |
| 330 | |
| 331 | _fill_resource_tree(); |
| 332 | |
| 333 | bool needs_templates; |
| 334 | String error; |
| 335 | if (!current->get_platform()->can_export(current, error, needs_templates)) { |
| 336 | if (!error.is_empty()) { |
| 337 | Vector<String> items = error.split("\n", false); |
| 338 | error = ""; |
| 339 | for (int i = 0; i < items.size(); i++) { |
| 340 | if (i > 0) { |
| 341 | error += "\n"; |
| 342 | } |
| 343 | error += " - " + items[i]; |
| 344 | } |
| 345 | |
| 346 | export_error->set_text(error); |
| 347 | export_error->show(); |
| 348 | } else { |
| 349 | export_error->hide(); |
| 350 | } |
| 351 | if (needs_templates) { |
| 352 | export_templates_error->show(); |
| 353 | } else { |
| 354 | export_templates_error->hide(); |
| 355 | } |
| 356 | |
| 357 | export_warning->hide(); |
| 358 | export_button->set_disabled(true); |
| 359 | } else { |
| 360 | if (error != String()) { |
| 361 | Vector<String> items = error.split("\n", false); |
| 362 | error = ""; |
| 363 | for (int i = 0; i < items.size(); i++) { |
| 364 | if (i > 0) { |
| 365 | error += "\n"; |
| 366 | } |
| 367 | error += " - " + items[i]; |
| 368 | } |
| 369 | export_warning->set_text(error); |
| 370 | export_warning->show(); |
| 371 | } else { |
| 372 | export_warning->hide(); |
| 373 | } |
| 374 | |
| 375 | export_error->hide(); |
| 376 | export_templates_error->hide(); |
| 377 | export_button->set_disabled(false); |
| 378 | } |
| 379 | |
| 380 | custom_features->set_text(current->get_custom_features()); |
| 381 | _update_feature_list(); |
| 382 | _update_export_all(); |
| 383 | child_controls_changed(); |
| 384 | |
| 385 | if ((feature_set.has("s3tc") || feature_set.has("bptc")) && !ResourceImporterTextureSettings::should_import_s3tc_bptc()) { |
| 386 | export_texture_format_error->show_for_texture_format("S3TC/BPTC", "rendering/textures/vram_compression/import_s3tc_bptc"); |
| 387 | } else if ((feature_set.has("etc2") || feature_set.has("astc")) && !ResourceImporterTextureSettings::should_import_etc2_astc()) { |
| 388 | export_texture_format_error->show_for_texture_format("ETC2/ASTC", "rendering/textures/vram_compression/import_etc2_astc"); |
| 389 | } else { |
| 390 | export_texture_format_error->hide(); |
| 391 | } |
| 392 | |
| 393 | String enc_in_filters_str = current->get_enc_in_filter(); |
| 394 | String enc_ex_filters_str = current->get_enc_ex_filter(); |
| 395 | if (!updating_enc_filters) { |
| 396 | enc_in_filters->set_text(enc_in_filters_str); |
| 397 | enc_ex_filters->set_text(enc_ex_filters_str); |
| 398 | } |
| 399 | |
| 400 | bool enc_pck_mode = current->get_enc_pck(); |
| 401 | enc_pck->set_pressed(enc_pck_mode); |
| 402 | |
| 403 | uint64_t seed = current->get_seed(); |
| 404 | if (!updating_seed) { |
| 405 | seed_input->set_text(itos(seed)); |
| 406 | } |
| 407 | |
| 408 | enc_directory->set_disabled(!enc_pck_mode); |
| 409 | enc_in_filters->set_editable(enc_pck_mode); |
| 410 | enc_ex_filters->set_editable(enc_pck_mode); |
| 411 | script_key->set_editable(enc_pck_mode); |
| 412 | show_script_key->set_disabled(!enc_pck_mode); |
| 413 | seed_input->set_editable(enc_pck_mode); |
| 414 | |
| 415 | bool enc_directory_mode = current->get_enc_directory(); |
| 416 | enc_directory->set_pressed(enc_directory_mode); |
| 417 | |
| 418 | String key = current->get_script_encryption_key(); |
| 419 | if (!updating_script_key) { |
| 420 | script_key->set_text(key); |
| 421 | } |
| 422 | if (enc_pck_mode) { |
| 423 | script_key->set_editable(true); |
| 424 | |
| 425 | bool key_valid = _validate_script_encryption_key(key); |
| 426 | if (key_valid) { |
| 427 | script_key_error->hide(); |
| 428 | } else { |
| 429 | script_key_error->show(); |
| 430 | } |
| 431 | } else { |
| 432 | script_key->set_editable(false); |
| 433 | script_key_error->hide(); |
| 434 | } |
| 435 | |
| 436 | int script_export_mode = int(current->get_script_export_mode()); |
| 437 | script_mode->select(script_export_mode); |
| 438 | |
| 439 | updating = false; |
| 440 | } |
| 441 | |
| 442 | void ProjectExportDialog::_update_feature_list() { |
| 443 | Ref<EditorExportPreset> current = get_current_preset(); |
| 444 | ERR_FAIL_COND(current.is_null()); |
| 445 | |
| 446 | List<String> features_list; |
| 447 | |
| 448 | current->get_platform()->get_platform_features(&features_list); |
| 449 | current->get_platform()->get_preset_features(current, &features_list); |
| 450 | |
| 451 | String custom = current->get_custom_features(); |
| 452 | Vector<String> custom_list = custom.split(","); |
| 453 | for (int i = 0; i < custom_list.size(); i++) { |
| 454 | String f = custom_list[i].strip_edges(); |
| 455 | if (!f.is_empty()) { |
| 456 | features_list.push_back(f); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | feature_set.clear(); |
| 461 | for (const String &E : features_list) { |
| 462 | feature_set.insert(E); |
| 463 | } |
| 464 | |
| 465 | #ifdef REAL_T_IS_DOUBLE |
| 466 | feature_set.insert("double"); |
| 467 | #else |
| 468 | feature_set.insert("single"); |
| 469 | #endif // REAL_T_IS_DOUBLE |
| 470 | |
| 471 | custom_feature_display->clear(); |
| 472 | String text; |
| 473 | bool first = true; |
| 474 | for (const String &E : feature_set) { |
| 475 | if (!first) { |
| 476 | text += ", "; |
| 477 | } else { |
| 478 | first = false; |
| 479 | } |
| 480 | text += E; |
| 481 | } |
| 482 | custom_feature_display->add_text(text); |
| 483 | } |
| 484 | |
| 485 | void ProjectExportDialog::_custom_features_changed(const String &p_text) { |
| 486 | if (updating) { |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | Ref<EditorExportPreset> current = get_current_preset(); |
| 491 | ERR_FAIL_COND(current.is_null()); |
| 492 | |
| 493 | current->set_custom_features(p_text); |
| 494 | _update_feature_list(); |
| 495 | } |
| 496 | |
| 497 | void ProjectExportDialog::_tab_changed(int) { |
| 498 | _update_feature_list(); |
| 499 | } |
| 500 | |
| 501 | void ProjectExportDialog::_update_parameters(const String &p_edited_property) { |
| 502 | _update_current_preset(); |
| 503 | } |
| 504 | |
| 505 | void ProjectExportDialog::_advanced_options_pressed() { |
| 506 | if (updating) { |
| 507 | return; |
| 508 | } |
| 509 | EditorSettings::get_singleton()->set_setting("_export_preset_advanced_mode", advanced_options->is_pressed()); |
| 510 | EditorSettings::get_singleton()->save(); |
| 511 | |
| 512 | Ref<EditorExportPreset> current = get_current_preset(); |
| 513 | if (current.is_valid()) { |
| 514 | current->notify_property_list_changed(); |
| 515 | } |
| 516 | _update_presets(); |
| 517 | } |
| 518 | |
| 519 | void ProjectExportDialog::_runnable_pressed() { |
| 520 | if (updating) { |
| 521 | return; |
| 522 | } |
| 523 | |
| 524 | Ref<EditorExportPreset> current = get_current_preset(); |
| 525 | ERR_FAIL_COND(current.is_null()); |
| 526 | |
| 527 | if (runnable->is_pressed()) { |
| 528 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 529 | Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i); |
| 530 | if (p->get_platform() == current->get_platform()) { |
| 531 | p->set_runnable(current == p); |
| 532 | } |
| 533 | } |
| 534 | } else { |
| 535 | current->set_runnable(false); |
| 536 | } |
| 537 | |
| 538 | _update_presets(); |
| 539 | } |
| 540 | |
| 541 | void ProjectExportDialog::_name_changed(const String &p_string) { |
| 542 | if (updating) { |
| 543 | return; |
| 544 | } |
| 545 | |
| 546 | Ref<EditorExportPreset> current = get_current_preset(); |
| 547 | ERR_FAIL_COND(current.is_null()); |
| 548 | |
| 549 | int current_index = presets->get_current(); |
| 550 | |
| 551 | String trimmed_name = p_string.strip_edges(); |
| 552 | if (trimmed_name.is_empty()) { |
| 553 | ERR_PRINT_ED("Invalid preset name: preset name cannot be empty!"); |
| 554 | name->set_text(current->get_name()); |
| 555 | return; |
| 556 | } |
| 557 | |
| 558 | if (EditorExport::get_singleton()->has_preset_with_name(trimmed_name, current_index)) { |
| 559 | ERR_PRINT_ED(vformat("Invalid preset name: a preset with the name '%s' already exists!", trimmed_name)); |
| 560 | name->set_text(current->get_name()); |
| 561 | return; |
| 562 | } |
| 563 | |
| 564 | current->set_name(trimmed_name); |
| 565 | _update_presets(); |
| 566 | } |
| 567 | |
| 568 | void ProjectExportDialog::_name_editing_finished() { |
| 569 | if (updating) { |
| 570 | return; |
| 571 | } |
| 572 | |
| 573 | _name_changed(name->get_text()); |
| 574 | } |
| 575 | |
| 576 | void ProjectExportDialog::set_export_path(const String &p_value) { |
| 577 | Ref<EditorExportPreset> current = get_current_preset(); |
| 578 | ERR_FAIL_COND(current.is_null()); |
| 579 | |
| 580 | current->set_export_path(p_value); |
| 581 | } |
| 582 | |
| 583 | String ProjectExportDialog::get_export_path() { |
| 584 | Ref<EditorExportPreset> current = get_current_preset(); |
| 585 | ERR_FAIL_COND_V(current.is_null(), String("")); |
| 586 | |
| 587 | return current->get_export_path(); |
| 588 | } |
| 589 | |
| 590 | Ref<EditorExportPreset> ProjectExportDialog::get_current_preset() const { |
| 591 | return EditorExport::get_singleton()->get_export_preset(presets->get_current()); |
| 592 | } |
| 593 | |
| 594 | void ProjectExportDialog::_export_path_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing) { |
| 595 | if (updating) { |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | Ref<EditorExportPreset> current = get_current_preset(); |
| 600 | ERR_FAIL_COND(current.is_null()); |
| 601 | |
| 602 | current->set_export_path(p_value); |
| 603 | _update_presets(); |
| 604 | _update_export_all(); |
| 605 | } |
| 606 | |
| 607 | void ProjectExportDialog::_enc_filters_changed(const String &p_filters) { |
| 608 | if (updating) { |
| 609 | return; |
| 610 | } |
| 611 | |
| 612 | Ref<EditorExportPreset> current = get_current_preset(); |
| 613 | ERR_FAIL_COND(current.is_null()); |
| 614 | |
| 615 | current->set_enc_in_filter(enc_in_filters->get_text()); |
| 616 | current->set_enc_ex_filter(enc_ex_filters->get_text()); |
| 617 | |
| 618 | updating_enc_filters = true; |
| 619 | _update_current_preset(); |
| 620 | updating_enc_filters = false; |
| 621 | } |
| 622 | |
| 623 | void ProjectExportDialog::_open_key_help_link() { |
| 624 | OS::get_singleton()->shell_open(vformat("%s/engine_details/development/compiling/compiling_with_script_encryption_key.html", GODOT_VERSION_DOCS_URL)); |
| 625 | } |
| 626 | |
| 627 | void ProjectExportDialog::_enc_pck_changed(bool p_pressed) { |
| 628 | if (updating) { |
| 629 | return; |
| 630 | } |
| 631 | |
| 632 | Ref<EditorExportPreset> current = get_current_preset(); |
| 633 | ERR_FAIL_COND(current.is_null()); |
| 634 | |
| 635 | current->set_enc_pck(p_pressed); |
| 636 | enc_directory->set_disabled(!p_pressed); |
| 637 | enc_in_filters->set_editable(p_pressed); |
| 638 | enc_ex_filters->set_editable(p_pressed); |
| 639 | script_key->set_editable(p_pressed); |
| 640 | show_script_key->set_disabled(!p_pressed); |
| 641 | if (!p_pressed) { |
| 642 | show_script_key->set_pressed(false); |
| 643 | } |
| 644 | |
| 645 | _update_current_preset(); |
| 646 | } |
| 647 | |
| 648 | void ProjectExportDialog::_seed_input_changed(const String &p_text) { |
| 649 | if (updating) { |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | Ref<EditorExportPreset> current = get_current_preset(); |
| 654 | ERR_FAIL_COND(current.is_null()); |
| 655 | |
| 656 | current->set_seed(seed_input->get_text().to_int()); |
| 657 | |
| 658 | updating_seed = true; |
| 659 | _update_current_preset(); |
| 660 | updating_seed = false; |
| 661 | } |
| 662 | |
| 663 | void ProjectExportDialog::_enc_directory_changed(bool p_pressed) { |
| 664 | if (updating) { |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | Ref<EditorExportPreset> current = get_current_preset(); |
| 669 | ERR_FAIL_COND(current.is_null()); |
| 670 | |
| 671 | current->set_enc_directory(p_pressed); |
| 672 | |
| 673 | _update_current_preset(); |
| 674 | } |
| 675 | |
| 676 | void ProjectExportDialog::_script_encryption_key_changed(const String &p_key) { |
| 677 | if (updating) { |
| 678 | return; |
| 679 | } |
| 680 | |
| 681 | Ref<EditorExportPreset> current = get_current_preset(); |
| 682 | ERR_FAIL_COND(current.is_null()); |
| 683 | |
| 684 | current->set_script_encryption_key(p_key); |
| 685 | |
| 686 | updating_script_key = true; |
| 687 | _update_current_preset(); |
| 688 | updating_script_key = false; |
| 689 | } |
| 690 | |
| 691 | void ProjectExportDialog::_script_encryption_key_visibility_changed(bool p_visible) { |
| 692 | show_script_key->set_button_icon(get_editor_theme_icon(p_visible ? SNAME("GuiVisibilityVisible") : SNAME("GuiVisibilityHidden"))); |
| 693 | show_script_key->set_tooltip_text(p_visible ? TTRC("Hide encryption key") : TTRC("Show encryption key")); |
| 694 | script_key->set_secret(!p_visible); |
| 695 | } |
| 696 | |
| 697 | bool ProjectExportDialog::_validate_script_encryption_key(const String &p_key) { |
| 698 | bool is_valid = false; |
| 699 | |
| 700 | if (!p_key.is_empty() && p_key.is_valid_hex_number(false) && p_key.length() == 64) { |
| 701 | is_valid = true; |
| 702 | } |
| 703 | return is_valid; |
| 704 | } |
| 705 | |
| 706 | void ProjectExportDialog::_script_export_mode_changed(EditorExportPreset::ScriptExportMode p_mode) { |
| 707 | if (updating) { |
| 708 | return; |
| 709 | } |
| 710 | |
| 711 | Ref<EditorExportPreset> current = get_current_preset(); |
| 712 | ERR_FAIL_COND(current.is_null()); |
| 713 | |
| 714 | current->set_script_export_mode(p_mode); |
| 715 | |
| 716 | _update_current_preset(); |
| 717 | } |
| 718 | |
| 719 | void ProjectExportDialog::_duplicate_preset() { |
| 720 | Ref<EditorExportPreset> current = get_current_preset(); |
| 721 | if (current.is_null()) { |
| 722 | return; |
| 723 | } |
| 724 | |
| 725 | Ref<EditorExportPreset> preset = current->get_platform()->create_preset(); |
| 726 | ERR_FAIL_COND(preset.is_null()); |
| 727 | |
| 728 | String preset_name = current->get_name() + " (copy)"; |
| 729 | bool make_runnable = true; |
| 730 | while (true) { |
| 731 | bool valid = true; |
| 732 | |
| 733 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 734 | Ref<EditorExportPreset> p = EditorExport::get_singleton()->get_export_preset(i); |
| 735 | if (p->get_platform() == preset->get_platform() && p->is_runnable()) { |
| 736 | make_runnable = false; |
| 737 | } |
| 738 | if (p->get_name() == preset_name) { |
| 739 | valid = false; |
| 740 | break; |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | if (valid) { |
| 745 | break; |
| 746 | } |
| 747 | |
| 748 | preset_name += " (copy)"; |
| 749 | } |
| 750 | |
| 751 | preset->set_name(preset_name); |
| 752 | if (make_runnable) { |
| 753 | preset->set_runnable(make_runnable); |
| 754 | } |
| 755 | preset->set_dedicated_server(current->is_dedicated_server()); |
| 756 | preset->set_export_filter(current->get_export_filter()); |
| 757 | preset->set_include_filter(current->get_include_filter()); |
| 758 | preset->set_exclude_filter(current->get_exclude_filter()); |
| 759 | preset->set_customized_files(current->get_customized_files()); |
| 760 | preset->set_selected_files(current->get_selected_files()); |
| 761 | preset->set_patches(current->get_patches()); |
| 762 | preset->set_patch_delta_encoding_enabled(current->is_patch_delta_encoding_enabled()); |
| 763 | preset->set_patch_delta_zstd_level(current->get_patch_delta_zstd_level()); |
| 764 | preset->set_patch_delta_min_reduction(current->get_patch_delta_min_reduction()); |
| 765 | preset->set_patch_delta_include_filter(current->get_patch_delta_include_filter()); |
| 766 | preset->set_patch_delta_exclude_filter(current->get_patch_delta_exclude_filter()); |
| 767 | preset->set_custom_features(current->get_custom_features()); |
| 768 | preset->set_enc_in_filter(current->get_enc_in_filter()); |
| 769 | preset->set_enc_ex_filter(current->get_enc_ex_filter()); |
| 770 | preset->set_enc_pck(current->get_enc_pck()); |
| 771 | preset->set_enc_directory(current->get_enc_directory()); |
| 772 | preset->set_script_encryption_key(current->get_script_encryption_key()); |
| 773 | preset->set_script_export_mode(current->get_script_export_mode()); |
| 774 | |
| 775 | for (const KeyValue<StringName, Variant> &E : current->get_values()) { |
| 776 | preset->set(E.key, E.value); |
| 777 | } |
| 778 | |
| 779 | EditorExport::get_singleton()->add_export_preset(preset); |
| 780 | _update_presets(); |
| 781 | _edit_preset(EditorExport::get_singleton()->get_export_preset_count() - 1); |
| 782 | } |
| 783 | |
| 784 | void ProjectExportDialog::_delete_preset() { |
| 785 | Ref<EditorExportPreset> current = get_current_preset(); |
| 786 | if (current.is_null()) { |
| 787 | return; |
| 788 | } |
| 789 | |
| 790 | delete_confirm->set_text(vformat(TTR("Delete preset '%s'?"), current->get_name())); |
| 791 | delete_confirm->popup_centered(); |
| 792 | } |
| 793 | |
| 794 | void ProjectExportDialog::_delete_preset_confirm() { |
| 795 | int idx = presets->get_current(); |
| 796 | _edit_preset(idx - 1); |
| 797 | export_button->set_disabled(true); |
| 798 | get_ok_button()->set_disabled(true); |
| 799 | EditorExport::get_singleton()->remove_export_preset(idx); |
| 800 | _update_presets(); |
| 801 | |
| 802 | // The Export All button might become enabled (if all other presets have an export path defined), |
| 803 | // or it could be disabled (if there are no presets anymore). |
| 804 | _update_export_all(); |
| 805 | } |
| 806 | |
| 807 | Variant ProjectExportDialog::get_drag_data_fw(const Point2 &p_point, Control *p_from) { |
| 808 | if (p_from == presets) { |
| 809 | int pos = -1; |
| 810 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 811 | if (presets->is_anything_selected()) { |
| 812 | pos = presets->get_selected_items()[0]; |
| 813 | } |
| 814 | } else { |
| 815 | pos = presets->get_item_at_position(p_point, true); |
| 816 | } |
| 817 | |
| 818 | if (pos >= 0) { |
| 819 | Dictionary d; |
| 820 | d["type"] = "export_preset"; |
| 821 | d["preset"] = pos; |
| 822 | |
| 823 | HBoxContainer *drag = memnew(HBoxContainer); |
| 824 | TextureRect *tr = memnew(TextureRect); |
| 825 | tr->set_texture(presets->get_item_icon(pos)); |
| 826 | drag->add_child(tr); |
| 827 | Label *label = memnew(Label); |
| 828 | label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 829 | label->set_text(presets->get_item_text(pos)); |
| 830 | label->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); // Don't translate user input. |
| 831 | drag->add_child(label); |
| 832 | |
| 833 | presets->set_drag_preview(drag); |
| 834 | |
| 835 | return d; |
| 836 | } |
| 837 | } else if (p_from == patches) { |
| 838 | TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? patches->get_selected() : patches->get_item_at_position(p_point); |
| 839 | |
| 840 | if (item) { |
| 841 | int item_metadata = item->get_metadata(0); |
| 842 | Dictionary d; |
| 843 | d["type"] = "export_patch"; |
| 844 | d["patch"] = item_metadata; |
| 845 | |
| 846 | Label *label = memnew(Label); |
| 847 | label->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 848 | label->set_text(item->get_text(0)); |
| 849 | patches->set_drag_preview(label); |
| 850 | |
| 851 | return d; |
| 852 | } |
| 853 | } |
| 854 | return Variant(); |
| 855 | } |
| 856 | |
| 857 | bool ProjectExportDialog::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { |
| 858 | if (p_from == presets) { |
| 859 | Dictionary d = p_data; |
| 860 | if (!d.has("type") || String(d["type"]) != "export_preset") { |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | int pos = -1; |
| 865 | bool end = true; |
| 866 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 867 | if (presets->is_anything_selected()) { |
| 868 | pos = presets->get_selected_items()[0]; |
| 869 | } |
| 870 | } else { |
| 871 | pos = presets->get_item_at_position(p_point, true); |
| 872 | end = presets->is_pos_at_end_of_items(p_point); |
| 873 | } |
| 874 | |
| 875 | if (pos < 0 && !end) { |
| 876 | return false; |
| 877 | } |
| 878 | } else if (p_from == patches) { |
| 879 | Dictionary d = p_data; |
| 880 | if (d.get("type", "") != "export_patch") { |
| 881 | return false; |
| 882 | } |
| 883 | |
| 884 | TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? patches->get_selected() : patches->get_item_at_position(p_point); |
| 885 | if (!item) { |
| 886 | return false; |
| 887 | } |
| 888 | |
| 889 | patches->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); |
| 890 | } |
| 891 | |
| 892 | return true; |
| 893 | } |
| 894 | |
| 895 | void ProjectExportDialog::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { |
| 896 | if (p_from == presets) { |
| 897 | Dictionary d = p_data; |
| 898 | int from_pos = d["preset"]; |
| 899 | |
| 900 | int to_pos = -1; |
| 901 | |
| 902 | int pos = -1; |
| 903 | bool end = true; |
| 904 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 905 | if (presets->is_anything_selected()) { |
| 906 | pos = presets->get_selected_items()[0]; |
| 907 | } |
| 908 | } else { |
| 909 | pos = presets->get_item_at_position(p_point, true); |
| 910 | end = presets->is_pos_at_end_of_items(p_point); |
| 911 | } |
| 912 | |
| 913 | if (pos >= 0) { |
| 914 | to_pos = pos; |
| 915 | } |
| 916 | |
| 917 | if (to_pos == -1 && !end) { |
| 918 | return; |
| 919 | } |
| 920 | |
| 921 | if (to_pos == from_pos) { |
| 922 | return; |
| 923 | } else if (to_pos > from_pos) { |
| 924 | to_pos--; |
| 925 | } |
| 926 | |
| 927 | Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(from_pos); |
| 928 | EditorExport::get_singleton()->remove_export_preset(from_pos); |
| 929 | EditorExport::get_singleton()->add_export_preset(preset, to_pos); |
| 930 | |
| 931 | _update_presets(); |
| 932 | if (to_pos >= 0) { |
| 933 | _edit_preset(to_pos); |
| 934 | } else { |
| 935 | _edit_preset(presets->get_item_count() - 1); |
| 936 | } |
| 937 | } else if (p_from == patches) { |
| 938 | Dictionary d = p_data; |
| 939 | int from_pos = d["patch"]; |
| 940 | |
| 941 | TreeItem *item = (p_point == Vector2(Math::INF, Math::INF)) ? patches->get_selected() : patches->get_item_at_position(p_point); |
| 942 | if (!item) { |
| 943 | return; |
| 944 | } |
| 945 | |
| 946 | int to_pos = item->get_metadata(0); |
| 947 | |
| 948 | int pos = -1; |
| 949 | if (p_point == Vector2(Math::INF, Math::INF)) { |
| 950 | pos = patches->get_drop_section_at_position(patches->get_item_rect(item).position); |
| 951 | } else { |
| 952 | pos = patches->get_drop_section_at_position(p_point); |
| 953 | } |
| 954 | if (pos > 0) { |
| 955 | to_pos++; |
| 956 | } |
| 957 | |
| 958 | if (to_pos > from_pos) { |
| 959 | to_pos--; |
| 960 | } |
| 961 | |
| 962 | Ref<EditorExportPreset> preset = get_current_preset(); |
| 963 | String patch = preset->get_patch(from_pos); |
| 964 | preset->remove_patch(from_pos); |
| 965 | preset->add_patch(patch, to_pos); |
| 966 | |
| 967 | _update_current_preset(); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | void ProjectExportDialog::_export_type_changed(int p_which) { |
| 972 | if (updating) { |
| 973 | return; |
| 974 | } |
| 975 | |
| 976 | Ref<EditorExportPreset> current = get_current_preset(); |
| 977 | if (current.is_null()) { |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | EditorExportPreset::ExportFilter filter_type = (EditorExportPreset::ExportFilter)p_which; |
| 982 | current->set_export_filter(filter_type); |
| 983 | current->set_dedicated_server(filter_type == EditorExportPreset::EXPORT_CUSTOMIZED); |
| 984 | server_strip_message->set_visible(filter_type == EditorExportPreset::EXPORT_CUSTOMIZED); |
| 985 | |
| 986 | // Default to stripping everything when first switching to server build. |
| 987 | if (filter_type == EditorExportPreset::EXPORT_CUSTOMIZED && current->get_customized_files_count() == 0) { |
| 988 | current->set_file_export_mode("res://", EditorExportPreset::MODE_FILE_STRIP); |
| 989 | } |
| 990 | include_label->set_text(_get_resource_export_header(current->get_export_filter())); |
| 991 | |
| 992 | updating = true; |
| 993 | _fill_resource_tree(); |
| 994 | updating = false; |
| 995 | } |
| 996 | |
| 997 | String ProjectExportDialog::_get_resource_export_header(EditorExportPreset::ExportFilter p_filter) const { |
| 998 | switch (p_filter) { |
| 999 | case EditorExportPreset::EXCLUDE_SELECTED_RESOURCES: |
| 1000 | return TTR("Resources to exclude:"); |
| 1001 | case EditorExportPreset::EXPORT_CUSTOMIZED: |
| 1002 | return TTR("Resources to override export behavior:"); |
| 1003 | default: |
| 1004 | return TTR("Resources to export:"); |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | void ProjectExportDialog::_filter_changed(const String &p_filter) { |
| 1009 | if (updating) { |
| 1010 | return; |
| 1011 | } |
| 1012 | |
| 1013 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1014 | if (current.is_null()) { |
| 1015 | return; |
| 1016 | } |
| 1017 | |
| 1018 | current->set_include_filter(include_filters->get_text()); |
| 1019 | current->set_exclude_filter(exclude_filters->get_text()); |
| 1020 | } |
| 1021 | |
| 1022 | void ProjectExportDialog::_fill_resource_tree() { |
| 1023 | include_files->clear(); |
| 1024 | include_label->hide(); |
| 1025 | include_margin->hide(); |
| 1026 | |
| 1027 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1028 | if (current.is_null()) { |
| 1029 | return; |
| 1030 | } |
| 1031 | |
| 1032 | EditorExportPreset::ExportFilter f = current->get_export_filter(); |
| 1033 | |
| 1034 | if (f == EditorExportPreset::EXPORT_ALL_RESOURCES) { |
| 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | TreeItem *root = include_files->create_item(); |
| 1039 | |
| 1040 | if (f == EditorExportPreset::EXPORT_CUSTOMIZED) { |
| 1041 | include_files->set_columns(2); |
| 1042 | include_files->set_column_expand(1, false); |
| 1043 | include_files->set_column_custom_minimum_width(1, 250 * EDSCALE); |
| 1044 | } else { |
| 1045 | include_files->set_columns(1); |
| 1046 | } |
| 1047 | |
| 1048 | include_label->show(); |
| 1049 | include_margin->show(); |
| 1050 | |
| 1051 | _fill_tree(EditorFileSystem::get_singleton()->get_filesystem(), root, current, f); |
| 1052 | |
| 1053 | if (f == EditorExportPreset::EXPORT_CUSTOMIZED) { |
| 1054 | _propagate_file_export_mode(include_files->get_root(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED); |
| 1055 | } |
| 1056 | } |
| 1057 | |
| 1058 | void ProjectExportDialog::_setup_item_for_file_mode(TreeItem *p_item, EditorExportPreset::FileExportMode p_mode) { |
| 1059 | if (p_mode == EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) { |
| 1060 | p_item->set_checked(0, false); |
| 1061 | p_item->set_cell_mode(1, TreeItem::CELL_MODE_STRING); |
| 1062 | p_item->set_editable(1, false); |
| 1063 | p_item->set_selectable(1, false); |
| 1064 | p_item->set_custom_color(1, get_theme_color(SNAME("font_disabled_color"), EditorStringName(Editor))); |
| 1065 | } else { |
| 1066 | p_item->set_checked(0, true); |
| 1067 | p_item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); |
| 1068 | p_item->set_editable(1, true); |
| 1069 | p_item->set_selectable(1, true); |
| 1070 | p_item->clear_custom_color(1); |
| 1071 | } |
| 1072 | p_item->set_metadata(1, p_mode); |
| 1073 | } |
| 1074 | |
| 1075 | bool ProjectExportDialog::_fill_tree(EditorFileSystemDirectory *p_dir, TreeItem *p_item, Ref<EditorExportPreset> ¤t, EditorExportPreset::ExportFilter p_export_filter) { |
| 1076 | p_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); |
| 1077 | p_item->set_icon(0, presets->get_theme_icon(SNAME("folder"), SNAME("FileDialog"))); |
| 1078 | p_item->set_text(0, p_dir->get_name() + "/"); |
| 1079 | p_item->set_editable(0, true); |
| 1080 | p_item->set_metadata(0, p_dir->get_path()); |
| 1081 | |
| 1082 | if (p_export_filter == EditorExportPreset::EXPORT_CUSTOMIZED) { |
| 1083 | _setup_item_for_file_mode(p_item, current->get_file_export_mode(p_dir->get_path())); |
| 1084 | } |
| 1085 | |
| 1086 | bool used = false; |
| 1087 | for (int i = 0; i < p_dir->get_subdir_count(); i++) { |
| 1088 | TreeItem *subdir = include_files->create_item(p_item); |
| 1089 | if (_fill_tree(p_dir->get_subdir(i), subdir, current, p_export_filter)) { |
| 1090 | used = true; |
| 1091 | } else { |
| 1092 | memdelete(subdir); |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | for (int i = 0; i < p_dir->get_file_count(); i++) { |
| 1097 | String type = p_dir->get_file_type(i); |
| 1098 | if (p_export_filter == EditorExportPreset::EXPORT_SELECTED_SCENES && type != "PackedScene") { |
| 1099 | continue; |
| 1100 | } |
| 1101 | if (type == "TextFile" || type == "OtherFile") { |
| 1102 | continue; |
| 1103 | } |
| 1104 | |
| 1105 | TreeItem *file = include_files->create_item(p_item); |
| 1106 | file->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); |
| 1107 | file->set_text(0, p_dir->get_file(i)); |
| 1108 | |
| 1109 | String path = p_dir->get_file_path(i); |
| 1110 | |
| 1111 | Ref<Texture2D> icon; |
| 1112 | if (!type.is_empty()) { |
| 1113 | icon = EditorNode::get_singleton()->get_class_icon(type); |
| 1114 | } |
| 1115 | if (icon.is_null()) { |
| 1116 | icon = get_editor_theme_icon(SNAME("File")); |
| 1117 | } |
| 1118 | file->set_icon(0, icon); |
| 1119 | file->set_editable(0, true); |
| 1120 | file->set_metadata(0, path); |
| 1121 | |
| 1122 | if (p_export_filter == EditorExportPreset::EXPORT_CUSTOMIZED) { |
| 1123 | _setup_item_for_file_mode(file, current->get_file_export_mode(path)); |
| 1124 | } else { |
| 1125 | file->set_checked(0, current->has_export_file(path)); |
| 1126 | file->propagate_check(0); |
| 1127 | } |
| 1128 | |
| 1129 | used = true; |
| 1130 | } |
| 1131 | return used; |
| 1132 | } |
| 1133 | |
| 1134 | void ProjectExportDialog::_propagate_file_export_mode(TreeItem *p_item, EditorExportPreset::FileExportMode p_inherited_export_mode) { |
| 1135 | EditorExportPreset::FileExportMode file_export_mode = (EditorExportPreset::FileExportMode)(int)p_item->get_metadata(1); |
| 1136 | bool is_inherited = false; |
| 1137 | if (file_export_mode == EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) { |
| 1138 | file_export_mode = p_inherited_export_mode; |
| 1139 | is_inherited = true; |
| 1140 | } |
| 1141 | |
| 1142 | if (file_export_mode == EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED) { |
| 1143 | p_item->set_text(1, ""); |
| 1144 | } else { |
| 1145 | String text = file_mode_popup->get_item_text(file_mode_popup->get_item_index(file_export_mode)); |
| 1146 | if (is_inherited) { |
| 1147 | text += " " + TTR("(Inherited)"); |
| 1148 | } |
| 1149 | p_item->set_text(1, text); |
| 1150 | } |
| 1151 | |
| 1152 | for (int i = 0; i < p_item->get_child_count(); i++) { |
| 1153 | _propagate_file_export_mode(p_item->get_child(i), file_export_mode); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | void ProjectExportDialog::_tree_changed() { |
| 1158 | if (updating) { |
| 1159 | return; |
| 1160 | } |
| 1161 | |
| 1162 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1163 | if (current.is_null()) { |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | TreeItem *item = include_files->get_edited(); |
| 1168 | if (!item) { |
| 1169 | return; |
| 1170 | } |
| 1171 | |
| 1172 | if (current->get_export_filter() == EditorExportPreset::EXPORT_CUSTOMIZED) { |
| 1173 | EditorExportPreset::FileExportMode file_mode = EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED; |
| 1174 | String path = item->get_metadata(0); |
| 1175 | |
| 1176 | if (item->is_checked(0)) { |
| 1177 | file_mode = current->get_file_export_mode(path, EditorExportPreset::MODE_FILE_STRIP); |
| 1178 | } |
| 1179 | |
| 1180 | current->set_file_export_mode(path, file_mode); |
| 1181 | _setup_item_for_file_mode(item, file_mode); |
| 1182 | _propagate_file_export_mode(include_files->get_root(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED); |
| 1183 | } else { |
| 1184 | item->propagate_check(0); |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | void ProjectExportDialog::_check_propagated_to_item(Object *p_obj, int column) { |
| 1189 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1190 | if (current.is_null()) { |
| 1191 | return; |
| 1192 | } |
| 1193 | TreeItem *item = Object::cast_to<TreeItem>(p_obj); |
| 1194 | String path = item->get_metadata(0); |
| 1195 | if (item && !path.ends_with("/")) { |
| 1196 | bool added = item->is_checked(0); |
| 1197 | if (added) { |
| 1198 | current->add_export_file(path); |
| 1199 | } else { |
| 1200 | current->remove_export_file(path); |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | void ProjectExportDialog::_tree_popup_edited(bool p_arrow_clicked) { |
| 1206 | Rect2 bounds = include_files->get_custom_popup_rect(); |
| 1207 | bounds.position += get_global_canvas_transform().get_origin(); |
| 1208 | bounds.size *= get_global_canvas_transform().get_scale(); |
| 1209 | if (!is_embedding_subwindows()) { |
| 1210 | bounds.position += get_position(); |
| 1211 | } |
| 1212 | file_mode_popup->popup(bounds); |
| 1213 | } |
| 1214 | |
| 1215 | void ProjectExportDialog::_set_file_export_mode(int p_id) { |
| 1216 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1217 | if (current.is_null()) { |
| 1218 | return; |
| 1219 | } |
| 1220 | |
| 1221 | TreeItem *item = include_files->get_edited(); |
| 1222 | String path = item->get_metadata(0); |
| 1223 | |
| 1224 | EditorExportPreset::FileExportMode file_export_mode = (EditorExportPreset::FileExportMode)p_id; |
| 1225 | current->set_file_export_mode(path, file_export_mode); |
| 1226 | item->set_metadata(1, file_export_mode); |
| 1227 | _propagate_file_export_mode(include_files->get_root(), EditorExportPreset::MODE_FILE_NOT_CUSTOMIZED); |
| 1228 | } |
| 1229 | |
| 1230 | void ProjectExportDialog::_patch_delta_encoding_changed(bool p_pressed) { |
| 1231 | if (updating) { |
| 1232 | return; |
| 1233 | } |
| 1234 | |
| 1235 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1236 | ERR_FAIL_COND(current.is_null()); |
| 1237 | |
| 1238 | current->set_patch_delta_encoding_enabled(p_pressed); |
| 1239 | |
| 1240 | _update_current_preset(); |
| 1241 | } |
| 1242 | |
| 1243 | void ProjectExportDialog::_patch_delta_include_filter_changed(const String &p_filter) { |
| 1244 | if (updating) { |
| 1245 | return; |
| 1246 | } |
| 1247 | |
| 1248 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1249 | ERR_FAIL_COND(current.is_null()); |
| 1250 | |
| 1251 | current->set_patch_delta_include_filter(patch_delta_include_filter->get_text()); |
| 1252 | |
| 1253 | updating_patch_delta_filters = true; |
| 1254 | _update_current_preset(); |
| 1255 | updating_patch_delta_filters = false; |
| 1256 | } |
| 1257 | |
| 1258 | void ProjectExportDialog::_patch_delta_exclude_filter_changed(const String &p_filter) { |
| 1259 | if (updating) { |
| 1260 | return; |
| 1261 | } |
| 1262 | |
| 1263 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1264 | ERR_FAIL_COND(current.is_null()); |
| 1265 | |
| 1266 | current->set_patch_delta_exclude_filter(patch_delta_exclude_filter->get_text()); |
| 1267 | |
| 1268 | updating_patch_delta_filters = true; |
| 1269 | _update_current_preset(); |
| 1270 | updating_patch_delta_filters = false; |
| 1271 | } |
| 1272 | |
| 1273 | void ProjectExportDialog::_patch_delta_zstd_level_changed(double p_value) { |
| 1274 | if (updating) { |
| 1275 | return; |
| 1276 | } |
| 1277 | |
| 1278 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1279 | ERR_FAIL_COND(current.is_null()); |
| 1280 | |
| 1281 | current->set_patch_delta_zstd_level((int)p_value); |
| 1282 | |
| 1283 | _update_current_preset(); |
| 1284 | } |
| 1285 | |
| 1286 | void ProjectExportDialog::_patch_delta_min_reduction_changed(double p_value) { |
| 1287 | if (updating) { |
| 1288 | return; |
| 1289 | } |
| 1290 | |
| 1291 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1292 | ERR_FAIL_COND(current.is_null()); |
| 1293 | |
| 1294 | current->set_patch_delta_min_reduction(p_value / 100.0); |
| 1295 | |
| 1296 | _update_current_preset(); |
| 1297 | } |
| 1298 | |
| 1299 | void ProjectExportDialog::_patch_tree_button_clicked(Object *p_item, int p_column, int p_id, int p_mouse_button_index) { |
| 1300 | TreeItem *ti = Object::cast_to<TreeItem>(p_item); |
| 1301 | |
| 1302 | patch_index = ti->get_metadata(0); |
| 1303 | |
| 1304 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1305 | ERR_FAIL_COND(current.is_null()); |
| 1306 | |
| 1307 | if (p_id == 0) { |
| 1308 | Vector<String> preset_patches = current->get_patches(); |
| 1309 | ERR_FAIL_INDEX(patch_index, preset_patches.size()); |
| 1310 | patch_erase->set_text(vformat(TTR("Delete patch '%s' from list?"), preset_patches[patch_index].get_file())); |
| 1311 | patch_erase->popup_centered(); |
| 1312 | } else { |
| 1313 | patch_dialog->popup_file_dialog(); |
| 1314 | } |
| 1315 | } |
| 1316 | |
| 1317 | void ProjectExportDialog::_patch_tree_item_edited() { |
| 1318 | TreeItem *item = patches->get_edited(); |
| 1319 | if (!item) { |
| 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1324 | ERR_FAIL_COND(current.is_null()); |
| 1325 | |
| 1326 | int index = item->get_metadata(0); |
| 1327 | String patch_path = item->get_text(0); |
| 1328 | |
| 1329 | current->set_patch(index, patch_path); |
| 1330 | item->set_tooltip_text(0, patch_path); |
| 1331 | } |
| 1332 | |
| 1333 | void ProjectExportDialog::_patch_file_selected(const String &p_path) { |
| 1334 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1335 | ERR_FAIL_COND(current.is_null()); |
| 1336 | |
| 1337 | String relative_path = ProjectSettings::get_singleton()->get_resource_path().path_to_file(p_path); |
| 1338 | |
| 1339 | Vector<String> preset_patches = current->get_patches(); |
| 1340 | if (patch_index >= preset_patches.size()) { |
| 1341 | current->add_patch(relative_path); |
| 1342 | } else { |
| 1343 | current->set_patch(patch_index, relative_path); |
| 1344 | } |
| 1345 | |
| 1346 | _update_current_preset(); |
| 1347 | } |
| 1348 | |
| 1349 | void ProjectExportDialog::_patch_delete_confirmed() { |
| 1350 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1351 | ERR_FAIL_COND(current.is_null()); |
| 1352 | |
| 1353 | Vector<String> preset_patches = current->get_patches(); |
| 1354 | if (patch_index < preset_patches.size()) { |
| 1355 | current->remove_patch(patch_index); |
| 1356 | _update_current_preset(); |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | void ProjectExportDialog::_patch_add_pack_pressed() { |
| 1361 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1362 | ERR_FAIL_COND(current.is_null()); |
| 1363 | |
| 1364 | patch_index = current->get_patches().size(); |
| 1365 | patch_dialog->popup_file_dialog(); |
| 1366 | } |
| 1367 | |
| 1368 | void ProjectExportDialog::_export_pck_zip() { |
| 1369 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1370 | ERR_FAIL_COND(current.is_null()); |
| 1371 | |
| 1372 | String dir = current->get_export_path().get_base_dir(); |
| 1373 | export_pck_zip->set_current_dir(dir); |
| 1374 | |
| 1375 | export_pck_zip->popup_file_dialog(); |
| 1376 | } |
| 1377 | |
| 1378 | void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) { |
| 1379 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1380 | ERR_FAIL_COND(current.is_null()); |
| 1381 | Ref<EditorExportPlatform> platform = current->get_platform(); |
| 1382 | ERR_FAIL_COND(platform.is_null()); |
| 1383 | |
| 1384 | const Dictionary &fd_option = export_pck_zip->get_selected_options(); |
| 1385 | bool export_debug = fd_option.get(TTR("Export With Debug"), true); |
| 1386 | bool export_as_patch = fd_option.get(TTR("Export As Patch"), true); |
| 1387 | |
| 1388 | EditorSettings::get_singleton()->set_project_metadata("export_options", "export_debug", export_debug); |
| 1389 | EditorSettings::get_singleton()->set_project_metadata("export_options", "export_as_patch", export_as_patch); |
| 1390 | |
| 1391 | if (p_path.ends_with(".zip")) { |
| 1392 | if (export_as_patch) { |
| 1393 | platform->export_zip_patch(current, export_debug, p_path); |
| 1394 | } else { |
| 1395 | platform->export_zip(current, export_debug, p_path); |
| 1396 | } |
| 1397 | } else if (p_path.ends_with(".pck")) { |
| 1398 | if (export_as_patch) { |
| 1399 | platform->export_pack_patch(current, export_debug, p_path); |
| 1400 | } else { |
| 1401 | platform->export_pack(current, export_debug, p_path); |
| 1402 | } |
| 1403 | } else { |
| 1404 | ERR_FAIL_MSG("Path must end with .pck or .zip"); |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | void ProjectExportDialog::_open_export_template_manager() { |
| 1409 | hide(); |
| 1410 | EditorNode::get_singleton()->open_export_template_manager(); |
| 1411 | } |
| 1412 | |
| 1413 | void ProjectExportDialog::_export_project() { |
| 1414 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1415 | ERR_FAIL_COND(current.is_null()); |
| 1416 | Ref<EditorExportPlatform> platform = current->get_platform(); |
| 1417 | ERR_FAIL_COND(platform.is_null()); |
| 1418 | |
| 1419 | export_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM); |
| 1420 | export_project->clear_filters(); |
| 1421 | |
| 1422 | List<String> extension_list = platform->get_binary_extensions(current); |
| 1423 | for (const String &extension : extension_list) { |
| 1424 | // TRANSLATORS: This is the name of a project export file format. %s will be replaced by the platform name. |
| 1425 | export_project->add_filter("*." + extension, vformat(TTR("%s Export"), platform->get_name())); |
| 1426 | } |
| 1427 | |
| 1428 | String path = current->get_export_path(); |
| 1429 | if (!path.is_empty()) { |
| 1430 | if (extension_list.find(path.get_extension()) == nullptr && extension_list.size() >= 1) { |
| 1431 | path = path.get_basename() + "." + extension_list.front()->get(); |
| 1432 | } |
| 1433 | export_project->set_current_path(path); |
| 1434 | } else { |
| 1435 | if (extension_list.size() >= 1) { |
| 1436 | export_project->set_current_file(default_filename + "." + extension_list.front()->get()); |
| 1437 | } else { |
| 1438 | export_project->set_current_file(default_filename); |
| 1439 | } |
| 1440 | } |
| 1441 | export_project->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); |
| 1442 | export_project->popup_file_dialog(); |
| 1443 | } |
| 1444 | |
| 1445 | void ProjectExportDialog::_export_project_to_path(const String &p_path) { |
| 1446 | // Save this name for use in future exports (but drop the file extension) |
| 1447 | default_filename = p_path.get_file().get_basename(); |
| 1448 | EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename); |
| 1449 | |
| 1450 | Ref<EditorExportPreset> current = get_current_preset(); |
| 1451 | ERR_FAIL_COND_MSG(current.is_null(), "Failed to start the export: current preset is invalid."); |
| 1452 | Ref<EditorExportPlatform> platform = current->get_platform(); |
| 1453 | ERR_FAIL_COND_MSG(platform.is_null(), "Failed to start the export: current preset has no valid platform."); |
| 1454 | current->set_export_path(p_path); |
| 1455 | |
| 1456 | exporting = true; |
| 1457 | |
| 1458 | platform->clear_messages(); |
| 1459 | current->update_value_overrides(); |
| 1460 | Dictionary fd_option = export_project->get_selected_options(); |
| 1461 | bool export_debug = fd_option.get(TTR("Export With Debug"), true); |
| 1462 | |
| 1463 | EditorSettings::get_singleton()->set_project_metadata("export_options", "export_debug", export_debug); |
| 1464 | |
| 1465 | Error err = platform->export_project(current, export_debug, current->get_export_path(), 0); |
| 1466 | result_dialog_log->clear(); |
| 1467 | if (err != ERR_SKIP) { |
| 1468 | if (platform->fill_log_messages(result_dialog_log, err)) { |
| 1469 | result_dialog->popup_centered_ratio(0.5); |
| 1470 | } |
| 1471 | } |
| 1472 | |
| 1473 | exporting = false; |
| 1474 | } |
| 1475 | |
| 1476 | void ProjectExportDialog::_export_all_dialog() { |
| 1477 | export_all_dialog->show(); |
| 1478 | export_all_dialog->popup_centered(Size2(300, 80)); |
| 1479 | } |
| 1480 | |
| 1481 | void ProjectExportDialog::_export_all_dialog_action(const String &p_str) { |
| 1482 | export_all_dialog->hide(); |
| 1483 | |
| 1484 | _export_all(p_str != "release"); |
| 1485 | } |
| 1486 | |
| 1487 | void ProjectExportDialog::_export_all(bool p_debug) { |
| 1488 | exporting = true; |
| 1489 | bool show_dialog = false; |
| 1490 | |
| 1491 | { // Scope for the editor progress, we must free it before showing the dialog at the end. |
| 1492 | String export_target = p_debug ? TTR("Debug") : TTR("Release"); |
| 1493 | EditorProgress ep("exportall", TTR("Exporting All") + " " + export_target, EditorExport::get_singleton()->get_export_preset_count(), true); |
| 1494 | |
| 1495 | result_dialog_log->clear(); |
| 1496 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 1497 | Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i); |
| 1498 | if (preset.is_null()) { |
| 1499 | exporting = false; |
| 1500 | ERR_FAIL_MSG("Failed to start the export: one of the presets is invalid."); |
| 1501 | } |
| 1502 | |
| 1503 | Ref<EditorExportPlatform> platform = preset->get_platform(); |
| 1504 | if (platform.is_null()) { |
| 1505 | exporting = false; |
| 1506 | ERR_FAIL_MSG("Failed to start the export: one of the presets has no valid platform."); |
| 1507 | } |
| 1508 | |
| 1509 | ep.step(preset->get_name(), i); |
| 1510 | |
| 1511 | platform->clear_messages(); |
| 1512 | preset->update_value_overrides(); |
| 1513 | Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0); |
| 1514 | if (err == ERR_SKIP) { |
| 1515 | exporting = false; |
| 1516 | return; |
| 1517 | } |
| 1518 | bool has_messages = platform->fill_log_messages(result_dialog_log, err); |
| 1519 | show_dialog = show_dialog || has_messages; |
| 1520 | } |
| 1521 | } |
| 1522 | |
| 1523 | if (show_dialog) { |
| 1524 | result_dialog->popup_centered_ratio(0.5); |
| 1525 | } |
| 1526 | |
| 1527 | exporting = false; |
| 1528 | } |
| 1529 | |
| 1530 | void ProjectExportDialog::_bind_methods() { |
| 1531 | ClassDB::bind_method("set_export_path", &ProjectExportDialog::set_export_path); |
| 1532 | ClassDB::bind_method("get_export_path", &ProjectExportDialog::get_export_path); |
| 1533 | ClassDB::bind_method("get_current_preset", &ProjectExportDialog::get_current_preset); |
| 1534 | |
| 1535 | ADD_PROPERTY(PropertyInfo(Variant::STRING, "export_path"), "set_export_path", "get_export_path"); |
| 1536 | } |
| 1537 | |
| 1538 | ProjectExportDialog::ProjectExportDialog() { |
| 1539 | set_title(TTR("Export")); |
| 1540 | set_flag(FLAG_MAXIMIZE_DISABLED, false); |
| 1541 | set_clamp_to_embedder(true); |
| 1542 | |
| 1543 | VBoxContainer *main_vb = memnew(VBoxContainer); |
| 1544 | add_child(main_vb); |
| 1545 | |
| 1546 | HSplitContainer *hbox = memnew(HSplitContainer); |
| 1547 | main_vb->add_child(hbox); |
| 1548 | hbox->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1549 | if (EDITOR_GET("interface/touchscreen/enable_touch_optimizations")) { |
| 1550 | hbox->set_touch_dragger_enabled(true); |
| 1551 | } |
| 1552 | |
| 1553 | // Presets list. |
| 1554 | |
| 1555 | VBoxContainer *preset_vb = memnew(VBoxContainer); |
| 1556 | preset_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1557 | preset_vb->set_stretch_ratio(0.35); |
| 1558 | hbox->add_child(preset_vb); |
| 1559 | |
| 1560 | Label *l = memnew(Label(TTR("Presets"))); |
| 1561 | l->set_theme_type_variation("HeaderSmall"); |
| 1562 | |
| 1563 | HBoxContainer *preset_hb = memnew(HBoxContainer); |
| 1564 | preset_hb->add_child(l); |
| 1565 | preset_hb->add_spacer(); |
| 1566 | preset_vb->add_child(preset_hb); |
| 1567 | |
| 1568 | add_preset = memnew(MenuButton); |
| 1569 | add_preset->set_text(TTR("Add...")); |
| 1570 | add_preset->get_popup()->connect("index_pressed", callable_mp(this, &ProjectExportDialog::_add_preset)); |
| 1571 | preset_hb->add_child(add_preset); |
| 1572 | MarginContainer *mc = memnew(MarginContainer); |
| 1573 | preset_vb->add_child(mc); |
| 1574 | mc->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1575 | presets = memnew(ItemList); |
| 1576 | presets->set_theme_type_variation("ItemListSecondary"); |
| 1577 | presets->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1578 | presets->set_custom_minimum_size(Size2(0, 200 * EDSCALE)); |
| 1579 | SET_DRAG_FORWARDING_GCD(presets, ProjectExportDialog); |
| 1580 | mc->add_child(presets); |
| 1581 | presets->connect(SceneStringName(item_selected), callable_mp(this, &ProjectExportDialog::_edit_preset)); |
| 1582 | duplicate_preset = memnew(Button); |
| 1583 | duplicate_preset->set_tooltip_text(TTR("Duplicate")); |
| 1584 | duplicate_preset->set_flat(true); |
| 1585 | preset_hb->add_child(duplicate_preset); |
| 1586 | duplicate_preset->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_duplicate_preset)); |
| 1587 | delete_preset = memnew(Button); |
| 1588 | delete_preset->set_tooltip_text(TTR("Delete")); |
| 1589 | delete_preset->set_flat(true); |
| 1590 | preset_hb->add_child(delete_preset); |
| 1591 | delete_preset->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_delete_preset)); |
| 1592 | |
| 1593 | // Preset settings. |
| 1594 | |
| 1595 | settings_vb = memnew(VBoxContainer); |
| 1596 | settings_vb->hide(); |
| 1597 | settings_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1598 | hbox->add_child(settings_vb); |
| 1599 | |
| 1600 | PanelContainer *panel = memnew(PanelContainer); |
| 1601 | panel->set_theme_type_variation(SNAME("PanelForeground")); |
| 1602 | settings_vb->add_child(panel); |
| 1603 | |
| 1604 | VBoxContainer *top_settings = memnew(VBoxContainer); |
| 1605 | top_settings->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1606 | panel->add_child(top_settings); |
| 1607 | |
| 1608 | HBoxContainer *name_hbox = memnew(HBoxContainer); |
| 1609 | Label *name_label = memnew(Label); |
| 1610 | name_label->set_theme_type_variation("HeaderSmall"); |
| 1611 | name_label->set_text(TTR("Name:")); |
| 1612 | name_hbox->add_child(name_label); |
| 1613 | name = memnew(LineEdit); |
| 1614 | name->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1615 | name->connect(SceneStringName(text_submitted), callable_mp(this, &ProjectExportDialog::_name_changed)); |
| 1616 | name->connect(SceneStringName(focus_exited), callable_mp(this, &ProjectExportDialog::_name_editing_finished)); |
| 1617 | name_hbox->add_child(name); |
| 1618 | |
| 1619 | top_settings->add_child(name_hbox); |
| 1620 | |
| 1621 | runnable = memnew(CheckButton); |
| 1622 | runnable->set_text(TTR("Runnable")); |
| 1623 | 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.")); |
| 1624 | runnable->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_runnable_pressed)); |
| 1625 | |
| 1626 | advanced_options = memnew(CheckButton); |
| 1627 | advanced_options->set_text(TTR("Advanced Options")); |
| 1628 | advanced_options->set_tooltip_text(TTR("If checked, the advanced options will be shown.")); |
| 1629 | advanced_options->set_pressed(EDITOR_GET("_export_preset_advanced_mode")); |
| 1630 | advanced_options->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_advanced_options_pressed)); |
| 1631 | |
| 1632 | HBoxContainer *preset_configs_container = memnew(HBoxContainer); |
| 1633 | preset_configs_container->add_spacer(true); |
| 1634 | preset_configs_container->add_child(advanced_options); |
| 1635 | preset_configs_container->add_child(runnable); |
| 1636 | top_settings->add_child(preset_configs_container); |
| 1637 | |
| 1638 | export_path = memnew(EditorPropertyPath); |
| 1639 | top_settings->add_child(export_path); |
| 1640 | export_path->set_label(TTR("Export Path")); |
| 1641 | export_path->set_object_and_property(this, "export_path"); |
| 1642 | export_path->set_save_mode(); |
| 1643 | export_path->connect("property_changed", callable_mp(this, &ProjectExportDialog::_export_path_changed)); |
| 1644 | |
| 1645 | // Subsections. |
| 1646 | |
| 1647 | sections = memnew(TabContainer); |
| 1648 | sections->set_use_hidden_tabs_for_min_size(true); |
| 1649 | sections->set_theme_type_variation("TabContainerOdd"); |
| 1650 | settings_vb->add_child(sections); |
| 1651 | sections->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1652 | |
| 1653 | // Main preset parameters. |
| 1654 | |
| 1655 | parameters = memnew(EditorInspector); |
| 1656 | parameters->set_name(TTRC("Options")); |
| 1657 | parameters->set_mark_unsaved(false); |
| 1658 | parameters->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1659 | parameters->set_use_doc_hints(true); |
| 1660 | sections->add_child(parameters); |
| 1661 | parameters->connect("property_edited", callable_mp(this, &ProjectExportDialog::_update_parameters)); |
| 1662 | EditorExport::get_singleton()->connect("export_presets_updated", callable_mp(this, &ProjectExportDialog::_force_update_current_preset_parameters)); |
| 1663 | |
| 1664 | // Resources export parameters. |
| 1665 | |
| 1666 | ScrollContainer *resources_scroll_container = memnew(ScrollContainer); |
| 1667 | resources_scroll_container->set_name(TTR("Resources")); |
| 1668 | resources_scroll_container->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); |
| 1669 | sections->add_child(resources_scroll_container); |
| 1670 | |
| 1671 | VBoxContainer *resources_vb = memnew(VBoxContainer); |
| 1672 | resources_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1673 | resources_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1674 | resources_scroll_container->add_child(resources_vb); |
| 1675 | |
| 1676 | export_filter = memnew(OptionButton); |
| 1677 | export_filter->set_accessibility_name(TTRC("Export Mode")); |
| 1678 | export_filter->add_item(TTR("Export all resources in the project")); |
| 1679 | export_filter->add_item(TTR("Export selected scenes (and dependencies)")); |
| 1680 | export_filter->add_item(TTR("Export selected resources (and dependencies)")); |
| 1681 | export_filter->add_item(TTR("Export all resources in the project except resources checked below")); |
| 1682 | export_filter->add_item(TTR("Export as dedicated server")); |
| 1683 | resources_vb->add_margin_child(TTR("Export Mode:"), export_filter); |
| 1684 | export_filter->connect(SceneStringName(item_selected), callable_mp(this, &ProjectExportDialog::_export_type_changed)); |
| 1685 | |
| 1686 | include_label = memnew(Label); |
| 1687 | include_label->set_text(TTR("Resources to export:")); |
| 1688 | resources_vb->add_child(include_label); |
| 1689 | include_margin = memnew(MarginContainer); |
| 1690 | include_margin->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1691 | resources_vb->add_child(include_margin); |
| 1692 | |
| 1693 | include_files = memnew(Tree); |
| 1694 | include_files->set_custom_minimum_size(Size2(1, 75 * EDSCALE)); |
| 1695 | include_margin->add_child(include_files); |
| 1696 | include_files->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1697 | include_files->connect("item_edited", callable_mp(this, &ProjectExportDialog::_tree_changed)); |
| 1698 | include_files->connect("check_propagated_to_item", callable_mp(this, &ProjectExportDialog::_check_propagated_to_item)); |
| 1699 | include_files->connect("custom_popup_edited", callable_mp(this, &ProjectExportDialog::_tree_popup_edited)); |
| 1700 | |
| 1701 | server_strip_message = memnew(Label); |
| 1702 | server_strip_message->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1703 | server_strip_message->set_visible(false); |
| 1704 | server_strip_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 1705 | server_strip_message->set_custom_minimum_size(Size2(300 * EDSCALE, 1)); |
| 1706 | resources_vb->add_child(server_strip_message); |
| 1707 | |
| 1708 | { |
| 1709 | LocalVector<StringName> resource_names; |
| 1710 | ClassDB::get_inheriters_from_class("Resource", resource_names); |
| 1711 | |
| 1712 | PackedStringArray strippable; |
| 1713 | for (const StringName &resource_name : resource_names) { |
| 1714 | if (ClassDB::has_method(resource_name, "create_placeholder", true)) { |
| 1715 | strippable.push_back(resource_name); |
| 1716 | } |
| 1717 | } |
| 1718 | strippable.sort(); |
| 1719 | |
| 1720 | String message = TTR("\"Strip Visuals\" will replace the following resources with placeholders:") + " "; |
| 1721 | message += String(", ").join(strippable); |
| 1722 | server_strip_message->set_text(message); |
| 1723 | } |
| 1724 | |
| 1725 | file_mode_popup = memnew(PopupMenu); |
| 1726 | add_child(file_mode_popup); |
| 1727 | file_mode_popup->add_item(TTR("Strip Visuals"), EditorExportPreset::MODE_FILE_STRIP); |
| 1728 | file_mode_popup->add_item(TTR("Keep"), EditorExportPreset::MODE_FILE_KEEP); |
| 1729 | file_mode_popup->add_item(TTR("Remove"), EditorExportPreset::MODE_FILE_REMOVE); |
| 1730 | file_mode_popup->connect(SceneStringName(id_pressed), callable_mp(this, &ProjectExportDialog::_set_file_export_mode)); |
| 1731 | |
| 1732 | include_filters = memnew(LineEdit); |
| 1733 | include_filters->set_accessibility_name(TTRC("Include Filters")); |
| 1734 | resources_vb->add_margin_child( |
| 1735 | TTR("Filters to export non-resource files/folders\n(comma-separated, e.g: *.json, *.txt, docs/*)"), |
| 1736 | include_filters); |
| 1737 | include_filters->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_filter_changed)); |
| 1738 | |
| 1739 | exclude_filters = memnew(LineEdit); |
| 1740 | exclude_filters->set_accessibility_name(TTRC("Exclude Filters")); |
| 1741 | resources_vb->add_margin_child( |
| 1742 | TTR("Filters to exclude files/folders from project\n(comma-separated, e.g: *.json, *.txt, docs/*)"), |
| 1743 | exclude_filters); |
| 1744 | exclude_filters->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_filter_changed)); |
| 1745 | |
| 1746 | // Patching. |
| 1747 | |
| 1748 | ScrollContainer *patch_scroll_container = memnew(ScrollContainer); |
| 1749 | patch_scroll_container->set_name(TTRC("Patching")); |
| 1750 | patch_scroll_container->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); |
| 1751 | sections->add_child(patch_scroll_container); |
| 1752 | |
| 1753 | VBoxContainer *patch_vb = memnew(VBoxContainer); |
| 1754 | patch_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1755 | patch_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1756 | patch_scroll_container->add_child(patch_vb); |
| 1757 | |
| 1758 | patch_delta_encoding = memnew(CheckButton); |
| 1759 | patch_delta_encoding->connect(SceneStringName(toggled), callable_mp(this, &ProjectExportDialog::_patch_delta_encoding_changed)); |
| 1760 | patch_delta_encoding->set_text(TTRC("Enable Delta Encoding")); |
| 1761 | patch_delta_encoding->set_tooltip_text(TTRC("If checked, any change to a file already present in the base packs will be exported as the difference between the old file and the new file.\n" |
| 1762 | "Enabling this comes at the cost of longer export times as well as longer load times for patched resources.")); |
| 1763 | patch_vb->add_child(patch_delta_encoding); |
| 1764 | |
| 1765 | patch_delta_zstd_level = memnew(SpinBox); |
| 1766 | patch_delta_zstd_level->set_min(ZSTD_minCLevel()); |
| 1767 | patch_delta_zstd_level->set_max(ZSTD_maxCLevel()); |
| 1768 | patch_delta_zstd_level->set_step(1); |
| 1769 | patch_delta_zstd_level->set_tooltip_text( |
| 1770 | vformat(TTR("The Zstandard compression level to use when generating delta-encoded patches.\n" |
| 1771 | "Higher positive levels will reduce patch sizes, at the cost of longer export time, but do not affect the time it takes to apply patches.\n" |
| 1772 | "Negative levels will reduce the time it takes to apply patches, at the cost of worse compression.\n" |
| 1773 | "Levels above 19 require more memory both during export and when applying patches, usually for very little benefit.\n" |
| 1774 | "Level 0 will cause Zstandard to use its default compression level, which is currently level %d."), |
| 1775 | ZSTD_CLEVEL_DEFAULT)); |
| 1776 | patch_delta_zstd_level->connect(SceneStringName(value_changed), callable_mp(this, &ProjectExportDialog::_patch_delta_zstd_level_changed)); |
| 1777 | patch_vb->add_margin_child(TTRC("Delta Encoding Compression Level"), patch_delta_zstd_level); |
| 1778 | |
| 1779 | patch_delta_min_reduction = memnew(SpinBox); |
| 1780 | patch_delta_min_reduction->set_min(0.0); |
| 1781 | patch_delta_min_reduction->set_max(100.0); |
| 1782 | patch_delta_min_reduction->set_step(1.0); |
| 1783 | patch_delta_min_reduction->set_suffix("%"); |
| 1784 | patch_delta_min_reduction->set_tooltip_text(TTRC("How much smaller, when compared to the new file, a delta-encoded patch needs to be for it to be exported.\n" |
| 1785 | "If the patch is not at least this much smaller, the new file will be exported as-is.")); |
| 1786 | patch_delta_min_reduction->connect(SceneStringName(value_changed), callable_mp(this, &ProjectExportDialog::_patch_delta_min_reduction_changed)); |
| 1787 | patch_vb->add_margin_child(TTRC("Delta Encoding Minimum Size Reduction"), patch_delta_min_reduction); |
| 1788 | |
| 1789 | patch_delta_include_filter = memnew(LineEdit); |
| 1790 | patch_delta_include_filter->set_accessibility_name(TTRC("Delta Encoding Include Filters")); |
| 1791 | patch_delta_include_filter->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_patch_delta_include_filter_changed)); |
| 1792 | patch_vb->add_margin_child(TTRC("Filters to include files/folders from being delta-encoded\n(comma-separated, e.g: *.gdc, scripts/*)"), patch_delta_include_filter); |
| 1793 | |
| 1794 | patch_delta_exclude_filter = memnew(LineEdit); |
| 1795 | patch_delta_exclude_filter->set_accessibility_name(TTRC("Delta Encoding Exclude Filters")); |
| 1796 | patch_delta_exclude_filter->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_patch_delta_exclude_filter_changed)); |
| 1797 | patch_vb->add_margin_child(TTRC("Filters to exclude files/folders from being delta-encoded\n(comma-separated, e.g: *.ctex, textures/*)"), patch_delta_exclude_filter); |
| 1798 | |
| 1799 | patches = memnew(Tree); |
| 1800 | patches->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1801 | patches->set_hide_root(true); |
| 1802 | patches->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED); |
| 1803 | patches->connect("button_clicked", callable_mp(this, &ProjectExportDialog::_patch_tree_button_clicked)); |
| 1804 | patches->connect("item_edited", callable_mp(this, &ProjectExportDialog::_patch_tree_item_edited)); |
| 1805 | SET_DRAG_FORWARDING_GCD(patches, ProjectExportDialog); |
| 1806 | patches->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); |
| 1807 | patch_vb->add_margin_child(TTR("Base Packs:"), patches, true); |
| 1808 | |
| 1809 | patch_dialog = memnew(EditorFileDialog); |
| 1810 | patch_dialog->add_filter("*.pck", TTR("Godot Project Pack")); |
| 1811 | patch_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM); |
| 1812 | patch_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); |
| 1813 | patch_dialog->connect("file_selected", callable_mp(this, &ProjectExportDialog::_patch_file_selected)); |
| 1814 | add_child(patch_dialog); |
| 1815 | |
| 1816 | patch_erase = memnew(ConfirmationDialog); |
| 1817 | patch_erase->set_ok_button_text(TTR("Delete")); |
| 1818 | patch_erase->connect(SceneStringName(confirmed), callable_mp(this, &ProjectExportDialog::_patch_delete_confirmed)); |
| 1819 | add_child(patch_erase); |
| 1820 | |
| 1821 | patch_add_btn = memnew(Button); |
| 1822 | patch_add_btn->set_text(TTR("Add Pack")); |
| 1823 | patch_add_btn->set_h_size_flags(Control::SIZE_SHRINK_CENTER); |
| 1824 | patch_add_btn->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_patch_add_pack_pressed)); |
| 1825 | patch_vb->add_child(patch_add_btn); |
| 1826 | |
| 1827 | // Feature tags. |
| 1828 | |
| 1829 | VBoxContainer *feature_vb = memnew(VBoxContainer); |
| 1830 | feature_vb->set_name(TTR("Features")); |
| 1831 | feature_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1832 | custom_features = memnew(LineEdit); |
| 1833 | custom_features->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_custom_features_changed)); |
| 1834 | feature_vb->add_margin_child(TTR("Custom (comma-separated):"), custom_features); |
| 1835 | custom_feature_display = memnew(RichTextLabel); |
| 1836 | custom_feature_display->set_custom_minimum_size(Size2(1, 75 * EDSCALE)); |
| 1837 | custom_feature_display->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1838 | feature_vb->add_margin_child(TTR("Feature List:"), custom_feature_display, true); |
| 1839 | sections->add_child(feature_vb); |
| 1840 | |
| 1841 | // Encryption export parameters. |
| 1842 | |
| 1843 | ScrollContainer *sec_scroll_container = memnew(ScrollContainer); |
| 1844 | sec_scroll_container->set_name(TTR("Encryption")); |
| 1845 | sec_scroll_container->set_horizontal_scroll_mode(ScrollContainer::SCROLL_MODE_DISABLED); |
| 1846 | |
| 1847 | VBoxContainer *sec_vb = memnew(VBoxContainer); |
| 1848 | sec_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1849 | sec_scroll_container->add_child(sec_vb); |
| 1850 | |
| 1851 | enc_pck = memnew(CheckButton); |
| 1852 | enc_pck->connect(SceneStringName(toggled), callable_mp(this, &ProjectExportDialog::_enc_pck_changed)); |
| 1853 | enc_pck->set_text(TTR("Encrypt Exported PCK")); |
| 1854 | sec_vb->add_child(enc_pck); |
| 1855 | |
| 1856 | enc_directory = memnew(CheckButton); |
| 1857 | enc_directory->connect(SceneStringName(toggled), callable_mp(this, &ProjectExportDialog::_enc_directory_changed)); |
| 1858 | enc_directory->set_text(TTR("Encrypt Index (File Names and Info)")); |
| 1859 | sec_vb->add_child(enc_directory); |
| 1860 | |
| 1861 | enc_in_filters = memnew(LineEdit); |
| 1862 | enc_in_filters->set_accessibility_name(TTRC("Include Filters")); |
| 1863 | enc_in_filters->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_enc_filters_changed)); |
| 1864 | sec_vb->add_margin_child( |
| 1865 | TTR("Filters to include files/folders\n(comma-separated, e.g: *.tscn, *.tres, scenes/*)"), |
| 1866 | enc_in_filters); |
| 1867 | |
| 1868 | enc_ex_filters = memnew(LineEdit); |
| 1869 | enc_ex_filters->set_accessibility_name(TTRC("Exclude Filters")); |
| 1870 | enc_ex_filters->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_enc_filters_changed)); |
| 1871 | sec_vb->add_margin_child( |
| 1872 | TTR("Filters to exclude files/folders\n(comma-separated, e.g: *.ctex, *.import, music/*)"), |
| 1873 | enc_ex_filters); |
| 1874 | |
| 1875 | script_key = memnew(LineEdit); |
| 1876 | script_key->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1877 | script_key->set_accessibility_name(TTRC("Encryption Key (256-bits as hexadecimal):")); |
| 1878 | script_key->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_script_encryption_key_changed)); |
| 1879 | script_key->set_secret(true); |
| 1880 | |
| 1881 | show_script_key = memnew(Button); |
| 1882 | show_script_key->set_toggle_mode(true); |
| 1883 | show_script_key->connect(SceneStringName(toggled), callable_mp(this, &ProjectExportDialog::_script_encryption_key_visibility_changed)); |
| 1884 | |
| 1885 | HBoxContainer *encryption_hb = memnew(HBoxContainer); |
| 1886 | encryption_hb->add_child(script_key); |
| 1887 | encryption_hb->add_child(show_script_key); |
| 1888 | |
| 1889 | script_key_error = memnew(Label); |
| 1890 | script_key_error->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1891 | script_key_error->set_text(String::utf8("• ") + TTR("Invalid Encryption Key (must be 64 hexadecimal characters long)")); |
| 1892 | script_key_error->add_theme_color_override(SceneStringName(font_color), EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor))); |
| 1893 | sec_vb->add_margin_child(TTRC("Encryption Key (256-bits as hexadecimal):"), encryption_hb); |
| 1894 | sec_vb->add_child(script_key_error); |
| 1895 | sections->add_child(sec_scroll_container); |
| 1896 | |
| 1897 | seed_input = memnew(LineEdit); |
| 1898 | seed_input->set_accessibility_name(TTRC("Initialization vector seed")); |
| 1899 | seed_input->connect(SceneStringName(text_changed), callable_mp(this, &ProjectExportDialog::_seed_input_changed)); |
| 1900 | sec_vb->add_margin_child(TTR("Initialization vector seed"), seed_input); |
| 1901 | |
| 1902 | Label *sec_info = memnew(Label); |
| 1903 | sec_info->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1904 | sec_info->set_text(TTR("Note: Encryption key needs to be stored in the binary,\nyou need to build the export templates from source.")); |
| 1905 | sec_vb->add_child(sec_info); |
| 1906 | |
| 1907 | LinkButton *sec_more_info = memnew(LinkButton); |
| 1908 | sec_more_info->set_text(TTR("More Info...")); |
| 1909 | sec_more_info->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_open_key_help_link)); |
| 1910 | sec_vb->add_child(sec_more_info); |
| 1911 | |
| 1912 | // Script export parameters. |
| 1913 | |
| 1914 | VBoxContainer *script_vb = memnew(VBoxContainer); |
| 1915 | script_vb->set_name(TTR("Scripts")); |
| 1916 | |
| 1917 | script_mode = memnew(OptionButton); |
| 1918 | script_mode->set_accessibility_name(TTRC("GDScript Export Mode:")); |
| 1919 | script_vb->add_margin_child(TTR("GDScript Export Mode:"), script_mode); |
| 1920 | script_mode->add_item(TTR("Text (easier debugging)"), (int)EditorExportPreset::MODE_SCRIPT_TEXT); |
| 1921 | script_mode->add_item(TTR("Binary tokens (faster loading)"), (int)EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS); |
| 1922 | script_mode->add_item(TTR("Compressed binary tokens (smaller files)"), (int)EditorExportPreset::MODE_SCRIPT_BINARY_TOKENS_COMPRESSED); |
| 1923 | script_mode->connect(SceneStringName(item_selected), callable_mp(this, &ProjectExportDialog::_script_export_mode_changed)); |
| 1924 | |
| 1925 | sections->add_child(script_vb); |
| 1926 | |
| 1927 | sections->connect("tab_changed", callable_mp(this, &ProjectExportDialog::_tab_changed)); |
| 1928 | |
| 1929 | // Disable by default. |
| 1930 | duplicate_preset->set_disabled(true); |
| 1931 | delete_preset->set_disabled(true); |
| 1932 | script_key_error->hide(); |
| 1933 | parameters->edit(nullptr); |
| 1934 | |
| 1935 | // Label shown when no presets are present. |
| 1936 | |
| 1937 | empty_label = memnew(Label(TTRC("No presets found.\nCreate one so that its parameters can be edited here."))); |
| 1938 | empty_label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_CENTER); |
| 1939 | empty_label->set_vertical_alignment(VERTICAL_ALIGNMENT_CENTER); |
| 1940 | empty_label->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); |
| 1941 | empty_label->set_clip_text(true); // Necessary to avoid overexpanding the dialog vertically. |
| 1942 | empty_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); |
| 1943 | empty_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); |
| 1944 | empty_label->hide(); |
| 1945 | hbox->add_child(empty_label); |
| 1946 | |
| 1947 | // Deletion dialog. |
| 1948 | |
| 1949 | delete_confirm = memnew(ConfirmationDialog); |
| 1950 | add_child(delete_confirm); |
| 1951 | delete_confirm->set_ok_button_text(TTR("Delete")); |
| 1952 | delete_confirm->connect(SceneStringName(confirmed), callable_mp(this, &ProjectExportDialog::_delete_preset_confirm)); |
| 1953 | |
| 1954 | // Export buttons, dialogs and errors. |
| 1955 | |
| 1956 | set_cancel_button_text(TTR("Close")); |
| 1957 | set_ok_button_text(TTR("Export PCK/ZIP...")); |
| 1958 | 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.")); |
| 1959 | get_ok_button()->set_disabled(true); |
| 1960 | |
| 1961 | export_button = add_button(TTR("Export Project..."), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export"); |
| 1962 | export_button->set_tooltip_text(TTR("Export the project as a playable build (Godot executable and project data) for the selected preset.")); |
| 1963 | export_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_export_project)); |
| 1964 | // Disable initially before we select a valid preset. |
| 1965 | export_button->set_disabled(true); |
| 1966 | |
| 1967 | export_all_dialog = memnew(ConfirmationDialog); |
| 1968 | add_child(export_all_dialog); |
| 1969 | export_all_dialog->set_title(TTR("Export All")); |
| 1970 | export_all_dialog->set_text(TTR("Choose an export mode:")); |
| 1971 | export_all_dialog->get_ok_button()->hide(); |
| 1972 | export_all_dialog->add_button(TTR("Debug"), true, "debug"); |
| 1973 | export_all_dialog->add_button(TTR("Release"), true, "release"); |
| 1974 | export_all_dialog->connect("custom_action", callable_mp(this, &ProjectExportDialog::_export_all_dialog_action)); |
| 1975 | |
| 1976 | export_all_button = add_button(TTR("Export All..."), !DisplayServer::get_singleton()->get_swap_cancel_ok(), "export"); |
| 1977 | export_all_button->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_export_all_dialog)); |
| 1978 | export_all_button->set_disabled(true); |
| 1979 | |
| 1980 | export_pck_zip = memnew(EditorFileDialog); |
| 1981 | export_pck_zip->add_filter("*.zip", TTR("ZIP File")); |
| 1982 | export_pck_zip->add_filter("*.pck", TTR("Godot Project Pack")); |
| 1983 | export_pck_zip->set_access(EditorFileDialog::ACCESS_FILESYSTEM); |
| 1984 | export_pck_zip->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE); |
| 1985 | add_child(export_pck_zip); |
| 1986 | export_pck_zip->connect("file_selected", callable_mp(this, &ProjectExportDialog::_export_pck_zip_selected)); |
| 1987 | |
| 1988 | // Export warnings and errors bottom section. |
| 1989 | |
| 1990 | export_texture_format_error = memnew(ProjectExportTextureFormatError(this)); |
| 1991 | main_vb->add_child(export_texture_format_error); |
| 1992 | export_texture_format_error->hide(); |
| 1993 | |
| 1994 | export_error = memnew(Label); |
| 1995 | export_error->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 1996 | main_vb->add_child(export_error); |
| 1997 | export_error->hide(); |
| 1998 | export_error->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_WORD_ELLIPSIS); |
| 1999 | export_error->add_theme_color_override(SceneStringName(font_color), EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor))); |
| 2000 | |
| 2001 | export_warning = memnew(Label); |
| 2002 | export_warning->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 2003 | main_vb->add_child(export_warning); |
| 2004 | export_warning->hide(); |
| 2005 | export_warning->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_WORD_ELLIPSIS); |
| 2006 | export_warning->add_theme_color_override(SceneStringName(font_color), EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("warning_color"), EditorStringName(Editor))); |
| 2007 | |
| 2008 | export_templates_error = memnew(HBoxContainer); |
| 2009 | main_vb->add_child(export_templates_error); |
| 2010 | export_templates_error->hide(); |
| 2011 | |
| 2012 | Label *export_error2 = memnew(Label); |
| 2013 | export_error2->set_focus_mode(Control::FOCUS_ACCESSIBILITY); |
| 2014 | export_templates_error->add_child(export_error2); |
| 2015 | export_error2->set_text_overrun_behavior(TextServer::OVERRUN_TRIM_WORD_ELLIPSIS); |
| 2016 | export_error2->add_theme_color_override(SceneStringName(font_color), EditorNode::get_singleton()->get_editor_theme()->get_color(SNAME("error_color"), EditorStringName(Editor))); |
| 2017 | export_error2->set_text(String::utf8("• ") + TTR("Export templates for this platform are missing:") + " "); |
| 2018 | |
| 2019 | result_dialog = memnew(AcceptDialog); |
| 2020 | result_dialog->set_title(TTR("Project Export")); |
| 2021 | result_dialog_log = memnew(RichTextLabel); |
| 2022 | result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE); |
| 2023 | result_dialog->add_child(result_dialog_log); |
| 2024 | |
| 2025 | main_vb->add_child(result_dialog); |
| 2026 | result_dialog->hide(); |
| 2027 | |
| 2028 | LinkButton *download_templates = memnew(LinkButton); |
| 2029 | download_templates->set_text(TTR("Manage Export Templates")); |
| 2030 | download_templates->set_v_size_flags(Control::SIZE_SHRINK_CENTER); |
| 2031 | export_templates_error->add_child(download_templates); |
| 2032 | download_templates->connect(SceneStringName(pressed), callable_mp(this, &ProjectExportDialog::_open_export_template_manager)); |
| 2033 | |
| 2034 | // Export project file dialog. |
| 2035 | |
| 2036 | export_project = memnew(EditorFileDialog); |
| 2037 | export_project->set_access(EditorFileDialog::ACCESS_FILESYSTEM); |
| 2038 | add_child(export_project); |
| 2039 | export_project->connect("file_selected", callable_mp(this, &ProjectExportDialog::_export_project_to_path)); |
| 2040 | |
| 2041 | export_project->add_option(TTR("Export With Debug"), Vector<String>(), EditorSettings::get_singleton()->get_project_metadata("export_options", "export_debug", true)); |
| 2042 | export_pck_zip->add_option(TTR("Export With Debug"), Vector<String>(), EditorSettings::get_singleton()->get_project_metadata("export_options", "export_debug", true)); |
| 2043 | export_pck_zip->add_option(TTR("Export As Patch"), Vector<String>(), EditorSettings::get_singleton()->get_project_metadata("export_options", "export_as_patch", true)); |
| 2044 | |
| 2045 | set_hide_on_ok(false); |
| 2046 | |
| 2047 | default_filename = EditorSettings::get_singleton()->get_project_metadata("export_options", "default_filename", ""); |
| 2048 | // If no default set, use project name |
| 2049 | if (default_filename.is_empty()) { |
| 2050 | // If no project name defined, use a sane default |
| 2051 | default_filename = GLOBAL_GET("application/config/name"); |
| 2052 | if (default_filename.is_empty()) { |
| 2053 | default_filename = "UnnamedProject"; |
| 2054 | } |
| 2055 | } |
| 2056 | } |