Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 48 additions & 28 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@

#ifdef ANDROID_ENABLED
#include "editor/gui/touch_actions_panel.h"
#else
#include "editor/export/android_sdk_manager.h"
#endif // ANDROID_ENABLED

#include "modules/modules_enabled.gen.h" // For gdscript, mono.
Expand Down Expand Up @@ -3397,6 +3399,37 @@ void EditorNode::_android_remove_build_templates(bool p_prompt_for_removal) {
remove_android_build_template->popup_centered_clamped(Size2(600, 200) * EDSCALE, 0.7);
}

void EditorNode::_setup_android_build(bool p_confirmed) {
if (p_confirmed) {
setup_android_build_template(android_export_preset, p_confirmed);
} 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 {
choose_android_export_profile->hide();

setup_android_build_template(android_export_preset, p_confirmed);
}
}
}

Error EditorNode::setup_android_build_template(const Ref<EditorExportPreset> &p_preset, bool p_confirmed) {
android_export_preset = p_preset;
if (export_template_manager->is_android_template_installed(p_preset)) {
Expand Down Expand Up @@ -3775,35 +3808,17 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) {
FindInFiles::get_singleton()->open_dock("", PROJECT_REPLACE_IN_FILES == p_option);
} break;

case PROJECT_INSTALL_ANDROID_SOURCE: {
if (p_confirmed) {
setup_android_build_template(android_export_preset, p_confirmed);
case PROJECT_SETUP_ANDROID_BUILD: {
#ifndef ANDROID_ENABLED
if (!(AndroidSDKManager::is_android_sdk_setup() && AndroidSDKManager::is_java_sdk_setup())) {
Callable setup_android_build_callable = callable_mp(this, &EditorNode::_setup_android_build).bind(p_confirmed);
android_sdk_manager->run_setup(setup_android_build_callable, setup_android_build_callable);
} 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 {
choose_android_export_profile->hide();

setup_android_build_template(android_export_preset, p_confirmed);
}
#endif
_setup_android_build(p_confirmed);
#ifndef ANDROID_ENABLED
}
#endif
} break;
case PROJECT_OPEN_USER_DATA_FOLDER: {
// Ensure_user_data_dir() to prevent the edge case: "Open User Data Folder" won't work after the project was renamed in ProjectSettingsEditor unless the project is saved.
Expand Down Expand Up @@ -8189,7 +8204,7 @@ void EditorNode::_build_project_menu(bool p_dark_mode) {
project_menu->add_separator();
project_menu->add_icon_shortcut(get_editor_theme_native_menu_icon(SNAME("ResourcePreloader"), menu_type == MENU_TYPE_GLOBAL, p_dark_mode), ED_GET_SHORTCUT("editor/export"), PROJECT_EXPORT);
project_menu->add_item(TTRC("Pack Project as ZIP..."), PROJECT_PACK_AS_ZIP);
project_menu->add_item(TTRC("Install Android Build Template..."), PROJECT_INSTALL_ANDROID_SOURCE);
project_menu->add_item(TTRC("Setup Android Build..."), PROJECT_SETUP_ANDROID_BUILD);
#ifndef ANDROID_ENABLED
project_menu->add_item(TTRC("Open User Data Folder"), PROJECT_OPEN_USER_DATA_FOLDER);
#endif
Expand Down Expand Up @@ -9069,6 +9084,11 @@ EditorNode::EditorNode() {
gui_base->add_child(fbx_importer_manager);
#endif

#ifndef ANDROID_ENABLED
android_sdk_manager = memnew(AndroidSDKManager);
gui_base->add_child(android_sdk_manager);
#endif

warning = memnew(AcceptDialog);
warning->set_unparent_when_invisible(true);
warning->add_button(TTRC("Copy Text"), true, "copy");
Expand Down
10 changes: 9 additions & 1 deletion editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ typedef void (*EditorNodeInitCallback)();
typedef void (*EditorPluginInitializeCallback)();
typedef bool (*EditorBuildCallback)();

#ifndef ANDROID_ENABLED
class AndroidSDKManager;
#endif
class AcceptDialog;
class BoxContainer;
class ColorPicker;
Expand Down Expand Up @@ -173,7 +176,7 @@ class EditorNode : public Node {
PROJECT_VERSION_CONTROL,
PROJECT_EXPORT,
PROJECT_PACK_AS_ZIP,
PROJECT_INSTALL_ANDROID_SOURCE,
PROJECT_SETUP_ANDROID_BUILD,
PROJECT_OPEN_USER_DATA_FOLDER,
PROJECT_RELOAD_CURRENT_PROJECT,
PROJECT_QUIT_TO_PROJECT_MANAGER,
Expand Down Expand Up @@ -500,6 +503,10 @@ class EditorNode : public Node {

bool unfocused_low_processor_usage_mode_enabled = true;

#ifndef ANDROID_ENABLED
AndroidSDKManager *android_sdk_manager = nullptr;
#endif

static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
static EditorPluginInitializeCallback plugin_init_callbacks[MAX_INIT_CALLBACKS];
static int build_callback_count;
Expand Down Expand Up @@ -553,6 +560,7 @@ class EditorNode : public Node {
void _android_install_build_template();
void _android_explore_build_templates();
void _android_remove_build_templates(bool p_prompt_for_removal);
void _setup_android_build(bool p_confirmed);

void _request_screenshot();
void _screenshot(bool p_use_utc = false);
Expand Down
Loading