Rework export template dialog to allow individual templates

This commit is contained in:
kobewi
2026-03-03 22:35:49 +01:00
parent 3f63a400fa
commit 64c8952975
3 changed files with 1308 additions and 932 deletions
File diff suppressed because it is too large Load Diff
+165 -66
View File
@@ -32,90 +32,190 @@
#include "scene/gui/dialogs.h"
class Button;
class EditorExportPreset;
class ExportTemplateVersion;
class FileDialog;
class HTTPRequest;
class MenuButton;
class ItemList;
class HBoxContainer;
class OptionButton;
class ProgressBar;
class Texture2D;
class Tree;
class TreeItem;
class ExportTemplateManager : public AcceptDialog {
GDCLASS(ExportTemplateManager, AcceptDialog);
bool current_version_exists = false;
bool mirrors_available = false;
bool is_refreshing_mirrors = false;
bool is_downloading_templates = false;
float update_countdown = 0;
const StringName PATH_META = "path";
const StringName FILE_META = "file";
Label *current_value = nullptr;
Label *current_missing_label = nullptr;
Label *current_installed_label = nullptr;
enum class TemplateID {
WINDOWS_X86_32,
WINDOWS_X86_64,
WINDOWS_ARM64,
HBoxContainer *current_installed_hb = nullptr;
LineEdit *current_installed_path = nullptr;
Button *current_uninstall_button = nullptr;
LINUX_X86_32,
LINUX_X86_64,
LINUX_ARM32,
LINUX_ARM64,
MACOS,
WEB,
WEB_EXTENSIONS,
WEB_NOTHREADS,
WEB_EXTENSIONS_NOTHREADS,
ANDROID,
ANDROID_SOURCE,
IOS,
ICU_DATA,
};
enum class PlatformID {
WINDOWS,
LINUX,
MACOS,
WEB,
ANDROID,
IOS,
COMMON,
};
enum class DownloadStatus {
NONE,
PENDING,
IN_PROGRESS,
COMPLETED,
FAILED,
};
enum class ButtonID {
DOWNLOAD,
REPAIR,
REMOVE,
CANCEL,
FAIL,
NONE,
};
struct PlatformInfo {
String name;
Ref<Texture2D> icon;
HashSet<TemplateID> templates;
String group;
};
struct TemplateInfo {
String name;
String description;
PackedStringArray file_list;
};
struct FileMetadata {
DownloadStatus download_status = DownloadStatus::NONE;
HTTPRequest *downloader = nullptr;
String fail_reason;
float progress_cache = 0.0;
bool is_missing = false;
};
bool mirrors_empty = true;
HashMap<PlatformID, PlatformInfo> platform_map;
HashMap<TemplateID, TemplateInfo> template_data;
HTTPRequest *mirrors_requester = nullptr;
LocalVector<HTTPRequest *> downloaders;
bool download_all_enabled = true;
HashSet<String> queued_templates;
HashSet<String> queued_files;
int download_count = 0;
mutable HashMap<String, FileMetadata> file_metadata;
LocalVector<TreeItem *> downloading_items;
bool queue_update_pending = false;
HashMap<String, int> checked_cache;
HashMap<String, bool> folding_cache;
VBoxContainer *install_options_vb = nullptr;
OptionButton *mirrors_list = nullptr;
Button *open_mirror = nullptr;
ItemList *version_list = nullptr;
Tree *installed_templates_tree = nullptr;
Tree *available_templates_tree = nullptr;
Button *open_folder_button = nullptr;
Button *install_button = nullptr;
HBoxContainer *offline_container = nullptr;
enum MirrorAction {
VISIT_WEB_MIRROR,
COPY_MIRROR_URL,
};
MenuButton *mirror_options_button = nullptr;
HBoxContainer *enable_online_hb = nullptr;
HBoxContainer *download_progress_hb = nullptr;
ProgressBar *download_progress_bar = nullptr;
Label *download_progress_label = nullptr;
HTTPRequest *download_templates = nullptr;
Button *install_file_button = nullptr;
Button *download_current_button = nullptr;
HTTPRequest *request_mirrors = nullptr;
enum TemplatesAction {
OPEN_TEMPLATE_FOLDER,
UNINSTALL_TEMPLATE,
};
Tree *installed_table = nullptr;
ConfirmationDialog *uninstall_confirm = nullptr;
String uninstall_version;
FileDialog *install_file_dialog = nullptr;
AcceptDialog *hide_dialog_accept = nullptr;
void _update_template_status();
void _download_current();
void _download_template(const String &p_url, bool p_skip_check = false);
void _download_template_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);
void _cancel_template_download();
void _refresh_mirrors();
void _refresh_mirrors_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);
void _request_mirrors();
void _mirrors_request_completed(int p_result, int p_response_code, const PackedStringArray &p_headers, const PackedByteArray &p_body);
void _set_empty_mirror_list();
String _get_current_mirror_url() const;
void _update_online_mode();
bool _is_online() const;
void _force_online_mode();
void _open_mirror();
bool _humanize_http_status(HTTPRequest *p_request, String *r_status, int *r_downloaded_bytes, int *r_total_bytes);
void _set_current_progress_status(const String &p_status, bool p_error = false);
void _set_current_progress_value(float p_value, const String &p_status);
void _initialize_template_data();
void _update_template_tree();
void _update_template_tree_theme(Tree *p_tree);
void _fill_template_tree(Tree *p_tree, const HashMap<TemplateID, LocalVector<String>> &p_installed_template_files, bool p_is_current_version);
void _update_template_tree_with_folding();
void _update_install_button();
bool _can_download_templates();
void _install_file();
bool _install_file_selected(const String &p_file, bool p_skip_progress = false);
void _update_folding_cache(TreeItem *p_item);
void _uninstall_template(const String &p_version);
void _uninstall_template_confirmed();
String _get_template_folder_path(const String &p_version) const;
Ref<Texture2D> _get_platform_icon(const String &p_platform_name);
String _get_selected_mirror() const;
void _mirror_options_button_cbk(int p_id);
void _installed_table_button_cbk(Object *p_item, int p_column, int p_id, MouseButton p_button);
void _version_selected();
void _tree_button_clicked(TreeItem *p_item, int p_column, int p_id, MouseButton p_button);
void _tree_item_edited();
void _install_templates(TreeItem *p_files = nullptr);
void _open_template_directory();
void _open_template_folder(const String &p_version);
void _queue_download_tree_item(TreeItem *p_item);
void _process_download_queue();
void _queue_process_download_queue();
HTTPRequest *_get_available_downloader(int *r_from_index);
void _download_request_completed(int p_result, int p_response_code, const PackedStringArray &p_headers, const PackedByteArray &p_body, HTTPRequest *p_downloader);
bool _is_template_download_finished(TreeItem *p_template);
String _get_download_error(int p_result, int p_response_code) const;
virtual void ok_pressed() override;
void _hide_dialog();
void _set_item_type(TreeItem *p_item, int p_type);
void _setup_item_text(TreeItem *p_item, const String &p_text);
FileMetadata *_get_file_metadata(const String &p_text) const;
FileMetadata *_get_file_metadata(const TreeItem *p_item) const;
void _apply_item_folding(TreeItem *p_item, bool p_default = false);
void _cancel_item_download(TreeItem *p_item);
void _item_download_failed(TreeItem *p_item, const String &p_reason);
void _add_fail_reason_button(TreeItem *p_item, const String &p_filename = String());
String _get_item_path(TreeItem *p_item) const;
bool _item_is_file(TreeItem *p_item) const;
bool _status_is_finished(DownloadStatus p_status) { return p_status == DownloadStatus::COMPLETED || p_status == DownloadStatus::FAILED; }
float _get_download_progress(const TreeItem *p_item) const;
void _draw_item_progress(TreeItem *p_item, const Rect2 &p_rect);
struct ThemeCache {
Ref<Texture2D> install_icon;
Ref<Texture2D> remove_icon;
Ref<Texture2D> repair_icon;
Ref<Texture2D> failure_icon;
Ref<Texture2D> cancel_icon;
Ref<Texture2D> progress_icons[8];
Color current_version_color;
Color incomplete_template_color;
Color missing_file_color;
Color download_progress_color;
Color download_failed_color;
int icon_width = 0;
} theme_cache;
protected:
void _notification(int p_what);
@@ -128,11 +228,10 @@ public:
bool is_android_template_installed(const Ref<EditorExportPreset> &p_preset);
bool can_install_android_template(const Ref<EditorExportPreset> &p_preset);
Error install_android_template(const Ref<EditorExportPreset> &p_preset);
Error install_android_template_from_file(const String &p_file, const Ref<EditorExportPreset> &p_preset);
void popup_manager();
bool is_downloading() const { return is_downloading_templates; }
bool is_downloading() const;
void stop_download();
ExportTemplateManager();
+4
View File
@@ -1461,6 +1461,10 @@ Color TreeItem::get_button_color(int p_column, int p_index) const {
void TreeItem::set_button_tooltip_text(int p_column, int p_index, const String &p_tooltip) {
ERR_FAIL_INDEX(p_column, cells.size());
if (p_index < 0) {
p_index += cells[p_column].buttons.size();
}
ERR_FAIL_INDEX(p_index, cells[p_column].buttons.size());
cells.write[p_column].buttons.write[p_index].tooltip = p_tooltip;