diff options
Diffstat (limited to 'editor/editor_node.cpp')
-rw-r--r-- | editor/editor_node.cpp | 83 |
1 files changed, 69 insertions, 14 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6ec656d588..3162095e1f 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -170,6 +170,9 @@ static const String META_TEXT_TO_COPY = "text_to_copy"; static const String EDITOR_NODE_CONFIG_SECTION = "EditorNode"; +static const String REMOVE_ANDROID_BUILD_TEMPLATE_MESSAGE = "The Android build template is already installed in this project and it won't be overwritten.\nRemove the \"%s\" directory manually before attempting this operation again."; +static const String INSTALL_ANDROID_BUILD_TEMPLATE_MESSAGE = "This will set up your project for gradle Android builds by installing the source template to \"%s\".\nNote that in order to make gradle builds instead of using pre-built APKs, the \"Use Gradle Build\" option should be enabled in the Android export preset."; + void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames) { ERR_FAIL_COND_MSG(p_full_paths.size() != r_filenames.size(), vformat("disambiguate_filenames requires two string vectors of same length (%d != %d).", p_full_paths.size(), r_filenames.size())); @@ -965,7 +968,7 @@ void EditorNode::_fs_changed() { String config_error; bool missing_templates; if (export_defer.android_build_template) { - export_template_manager->install_android_template(); + export_template_manager->install_android_template(export_preset); } if (!platform->can_export(export_preset, config_error, missing_templates, export_defer.debug)) { ERR_PRINT(vformat("Cannot export project with preset \"%s\" due to configuration errors:\n%s", preset_name, config_error)); @@ -2515,7 +2518,16 @@ void EditorNode::_edit_current(bool p_skip_foreign) { } void EditorNode::_android_build_source_selected(const String &p_file) { - export_template_manager->install_android_template_from_file(p_file); + export_template_manager->install_android_template_from_file(p_file, android_export_preset); +} + +void EditorNode::_android_export_preset_selected(int p_index) { + if (p_index >= 0) { + android_export_preset = EditorExport::get_singleton()->get_export_preset(choose_android_export_profile->get_item_id(p_index)); + } else { + android_export_preset.unref(); + } + install_android_build_template_message->set_text(vformat(TTR(INSTALL_ANDROID_BUILD_TEMPLATE_MESSAGE), export_template_manager->get_android_build_directory(android_export_preset))); } void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { @@ -2801,14 +2813,45 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_INSTALL_ANDROID_SOURCE: { if (p_confirmed) { - export_template_manager->install_android_template(); - } else { - if (DirAccess::exists("res://android/build")) { + if (export_template_manager->is_android_template_installed(android_export_preset)) { + remove_android_build_template->set_text(vformat(TTR(REMOVE_ANDROID_BUILD_TEMPLATE_MESSAGE), export_template_manager->get_android_build_directory(android_export_preset))); remove_android_build_template->popup_centered(); - } else if (export_template_manager->can_install_android_template()) { + } else if (!export_template_manager->can_install_android_template(android_export_preset)) { + gradle_build_manage_templates->popup_centered(); + } else { + export_template_manager->install_android_template(android_export_preset); + } + } else { + bool has_custom_gradle_build = false; + choose_android_export_profile->clear(); + for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { + Ref<EditorExportPreset> export_preset = EditorExport::get_singleton()->get_export_preset(i); + if (export_preset->get_platform()->get_class_name() == "EditorExportPlatformAndroid" && (bool)export_preset->get("gradle_build/use_gradle_build")) { + choose_android_export_profile->add_item(export_preset->get_name(), i); + String gradle_build_directory = export_preset->get("gradle_build/gradle_build_directory"); + String android_source_template = export_preset->get("gradle_build/android_source_template"); + if (!android_source_template.is_empty() || (gradle_build_directory != "" && gradle_build_directory != "res://android")) { + has_custom_gradle_build = true; + } + } + } + _android_export_preset_selected(choose_android_export_profile->get_item_count() >= 1 ? 0 : -1); + + if (choose_android_export_profile->get_item_count() > 1 && has_custom_gradle_build) { + // If there's multiple options and at least one of them uses a custom gradle build then prompt the user to choose. + choose_android_export_profile->show(); install_android_build_template->popup_centered(); } else { - gradle_build_manage_templates->popup_centered(); + choose_android_export_profile->hide(); + + if (export_template_manager->is_android_template_installed(android_export_preset)) { + remove_android_build_template->set_text(vformat(TTR(REMOVE_ANDROID_BUILD_TEMPLATE_MESSAGE), export_template_manager->get_android_build_directory(android_export_preset))); + remove_android_build_template->popup_centered(); + } else if (export_template_manager->can_install_android_template(android_export_preset)) { + install_android_build_template->popup_centered(); + } else { + gradle_build_manage_templates->popup_centered(); + } } } } break; @@ -2821,7 +2864,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { OS::get_singleton()->shell_show_in_file_manager(OS::get_singleton()->get_user_data_dir(), true); } break; case FILE_EXPLORE_ANDROID_BUILD_TEMPLATES: { - OS::get_singleton()->shell_show_in_file_manager(ProjectSettings::get_singleton()->get_resource_path().path_join("android"), true); + OS::get_singleton()->shell_show_in_file_manager(ProjectSettings::get_singleton()->globalize_path(export_template_manager->get_android_build_directory(android_export_preset).get_base_dir()), true); } break; case FILE_QUIT: case RUN_PROJECT_MANAGER: @@ -7208,14 +7251,26 @@ EditorNode::EditorNode() { file_android_build_source->connect("file_selected", callable_mp(this, &EditorNode::_android_build_source_selected)); gui_base->add_child(file_android_build_source); - install_android_build_template = memnew(ConfirmationDialog); - install_android_build_template->set_text(TTR("This will set up your project for gradle Android builds by installing the source template to \"res://android/build\".\nYou can then apply modifications and build your own custom APK on export (adding modules, changing the AndroidManifest.xml, etc.).\nNote that in order to make gradle builds instead of using pre-built APKs, the \"Use Gradle Build\" option should be enabled in the Android export preset.")); - install_android_build_template->set_ok_button_text(TTR("Install")); - install_android_build_template->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current)); - gui_base->add_child(install_android_build_template); + { + VBoxContainer *vbox = memnew(VBoxContainer); + install_android_build_template_message = memnew(Label); + install_android_build_template_message->set_autowrap_mode(TextServer::AUTOWRAP_WORD_SMART); + install_android_build_template_message->set_custom_minimum_size(Size2(300 * EDSCALE, 1)); + vbox->add_child(install_android_build_template_message); + + choose_android_export_profile = memnew(OptionButton); + choose_android_export_profile->connect("item_selected", callable_mp(this, &EditorNode::_android_export_preset_selected)); + vbox->add_child(choose_android_export_profile); + + install_android_build_template = memnew(ConfirmationDialog); + install_android_build_template->set_ok_button_text(TTR("Install")); + install_android_build_template->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current)); + install_android_build_template->add_child(vbox); + install_android_build_template->set_min_size(Vector2(500.0 * EDSCALE, 0)); + gui_base->add_child(install_android_build_template); + } remove_android_build_template = memnew(ConfirmationDialog); - remove_android_build_template->set_text(TTR("The Android build template is already installed in this project and it won't be overwritten.\nRemove the \"res://android/build\" directory manually before attempting this operation again.")); remove_android_build_template->set_ok_button_text(TTR("Show in File Manager")); remove_android_build_template->connect("confirmed", callable_mp(this, &EditorNode::_menu_option).bind(FILE_EXPLORE_ANDROID_BUILD_TEMPLATES)); gui_base->add_child(remove_android_build_template); |