Path: blob/master/editor/asset_library/editor_asset_installer.cpp
9902 views
/**************************************************************************/1/* editor_asset_installer.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "editor_asset_installer.h"3132#include "core/io/dir_access.h"33#include "core/io/file_access.h"34#include "core/io/zip_io.h"35#include "editor/editor_node.h"36#include "editor/editor_string_names.h"37#include "editor/file_system/editor_file_system.h"38#include "editor/gui/editor_file_dialog.h"39#include "editor/gui/editor_toaster.h"40#include "editor/gui/progress_dialog.h"41#include "editor/themes/editor_scale.h"42#include "scene/gui/check_box.h"43#include "scene/gui/label.h"44#include "scene/gui/link_button.h"45#include "scene/gui/separator.h"46#include "scene/gui/split_container.h"4748void EditorAssetInstaller::_item_checked_cbk() {49if (updating_source || !source_tree->get_edited()) {50return;51}5253updating_source = true;54TreeItem *item = source_tree->get_edited();55item->propagate_check(0);56_fix_conflicted_indeterminate_state(source_tree->get_root(), 0);57_update_confirm_button();58_rebuild_destination_tree();59updating_source = false;60}6162// Determine parent state based on non-conflict children, to avoid indeterminate state, and allow toggle dir with conflicts.63bool EditorAssetInstaller::_fix_conflicted_indeterminate_state(TreeItem *p_item, int p_column) {64if (p_item->get_child_count() == 0) {65return false;66}67bool all_non_conflict_checked = true;68bool all_non_conflict_unchecked = true;69bool has_conflict_child = false;70bool has_indeterminate_child = false;71TreeItem *child_item = p_item->get_first_child();72while (child_item) {73has_conflict_child |= _fix_conflicted_indeterminate_state(child_item, p_column);74Dictionary child_meta = child_item->get_metadata(p_column);75bool child_conflict = child_meta.get("is_conflict", false);76if (child_conflict) {77child_item->set_checked(p_column, false);78has_conflict_child = true;79} else {80bool child_checked = child_item->is_checked(p_column);81bool child_indeterminate = child_item->is_indeterminate(p_column);82all_non_conflict_checked &= (child_checked || child_indeterminate);83all_non_conflict_unchecked &= !child_checked;84has_indeterminate_child |= child_indeterminate;85}86child_item = child_item->get_next();87}88if (has_indeterminate_child) {89p_item->set_indeterminate(p_column, true);90} else if (all_non_conflict_checked) {91p_item->set_checked(p_column, true);92} else if (all_non_conflict_unchecked) {93p_item->set_checked(p_column, false);94}95if (has_conflict_child) {96p_item->set_custom_color(p_column, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));97} else {98p_item->clear_custom_color(p_column);99}100return has_conflict_child;101}102103bool EditorAssetInstaller::_is_item_checked(const String &p_source_path) const {104return file_item_map.has(p_source_path) && (file_item_map[p_source_path]->is_checked(0) || file_item_map[p_source_path]->is_indeterminate(0));105}106107void EditorAssetInstaller::open_asset(const String &p_path, bool p_autoskip_toplevel) {108package_path = p_path;109asset_files.clear();110111Ref<FileAccess> io_fa;112zlib_filefunc_def io = zipio_create_io(&io_fa);113114unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io);115if (!pkg) {116EditorToaster::get_singleton()->popup_str(vformat(TTR("Error opening asset file for \"%s\" (not in ZIP format)."), asset_name), EditorToaster::SEVERITY_ERROR);117return;118}119120int ret = unzGoToFirstFile(pkg);121122while (ret == UNZ_OK) {123//get filename124unz_file_info info;125char fname[16384];126unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);127128String source_name = String::utf8(fname);129130// Create intermediate directories if they aren't reported by unzip.131// We are only interested in subfolders, so skip the root slash.132int separator = source_name.find_char('/', 1);133while (separator != -1) {134String dir_name = source_name.substr(0, separator + 1);135if (!dir_name.is_empty() && !asset_files.has(dir_name)) {136asset_files.insert(dir_name);137}138139separator = source_name.find_char('/', separator + 1);140}141142if (!source_name.is_empty() && !asset_files.has(source_name)) {143asset_files.insert(source_name);144}145146ret = unzGoToNextFile(pkg);147}148149unzClose(pkg);150151asset_title_label->set_text(asset_name);152153_check_has_toplevel();154// Default to false, unless forced.155skip_toplevel = p_autoskip_toplevel;156skip_toplevel_check->set_block_signals(true);157skip_toplevel_check->set_pressed(!skip_toplevel_check->is_disabled() && skip_toplevel);158skip_toplevel_check->set_block_signals(false);159160_update_file_mappings();161_rebuild_source_tree();162_rebuild_destination_tree();163164popup_centered_clamped(Size2(620, 640) * EDSCALE);165}166167void EditorAssetInstaller::_update_file_mappings() {168mapped_files.clear();169170bool first = true;171for (const String &E : asset_files) {172if (first) {173first = false;174175if (!toplevel_prefix.is_empty() && skip_toplevel) {176continue;177}178}179180String path = E; // We're going to mutate it.181if (!toplevel_prefix.is_empty() && skip_toplevel) {182path = path.trim_prefix(toplevel_prefix);183}184185mapped_files[E] = path;186}187}188189void EditorAssetInstaller::_rebuild_source_tree() {190updating_source = true;191source_tree->clear();192193TreeItem *root = source_tree->create_item();194root->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);195root->set_checked(0, true);196root->set_icon(0, get_theme_icon(SNAME("folder"), SNAME("FileDialog")));197root->set_text(0, "/");198root->set_editable(0, true);199200file_item_map.clear();201HashMap<String, TreeItem *> directory_item_map;202int num_file_conflicts = 0;203first_file_conflict = nullptr;204205for (const String &E : asset_files) {206String path = E; // We're going to mutate it.207208bool is_directory = false;209if (path.ends_with("/")) {210path = path.trim_suffix("/");211is_directory = true;212}213214TreeItem *parent_item;215216int separator = path.rfind_char('/');217if (separator == -1) {218parent_item = root;219} else {220String parent_path = path.substr(0, separator);221HashMap<String, TreeItem *>::Iterator I = directory_item_map.find(parent_path);222ERR_CONTINUE(!I);223parent_item = I->value;224}225226TreeItem *ti;227if (is_directory) {228ti = _create_dir_item(source_tree, parent_item, path, directory_item_map);229} else {230ti = _create_file_item(source_tree, parent_item, path, &num_file_conflicts);231}232file_item_map[E] = ti;233}234235_update_conflict_status(num_file_conflicts);236_update_confirm_button();237238updating_source = false;239}240241void EditorAssetInstaller::_update_source_tree() {242int num_file_conflicts = 0;243first_file_conflict = nullptr;244245for (const KeyValue<String, TreeItem *> &E : file_item_map) {246TreeItem *ti = E.value;247Dictionary item_meta = ti->get_metadata(0);248if ((bool)item_meta.get("is_dir", false)) {249continue;250}251252String asset_path = item_meta.get("asset_path", "");253ERR_CONTINUE(asset_path.is_empty());254255bool target_exists = _update_source_item_status(ti, asset_path);256if (target_exists) {257if (first_file_conflict == nullptr) {258first_file_conflict = ti;259}260num_file_conflicts += 1;261}262263item_meta["is_conflict"] = target_exists;264ti->set_metadata(0, item_meta);265}266267_update_conflict_status(num_file_conflicts);268_update_confirm_button();269}270271bool EditorAssetInstaller::_update_source_item_status(TreeItem *p_item, const String &p_path) {272ERR_FAIL_COND_V(!mapped_files.has(p_path), false);273String target_path = target_dir_path.path_join(mapped_files[p_path]);274275bool target_exists = FileAccess::exists(target_path);276if (target_exists) {277p_item->set_custom_color(0, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));278p_item->set_tooltip_text(0, vformat(TTR("%s (already exists)"), target_path));279p_item->set_checked(0, false);280} else {281p_item->clear_custom_color(0);282p_item->set_tooltip_text(0, target_path);283p_item->set_checked(0, true);284}285286p_item->propagate_check(0);287_fix_conflicted_indeterminate_state(p_item->get_tree()->get_root(), 0);288return target_exists;289}290291void EditorAssetInstaller::_rebuild_destination_tree() {292destination_tree->clear();293294TreeItem *root = destination_tree->create_item();295root->set_icon(0, get_theme_icon(SNAME("folder"), SNAME("FileDialog")));296root->set_text(0, target_dir_path + (target_dir_path == "res://" ? "" : "/"));297298HashMap<String, TreeItem *> directory_item_map;299300for (const KeyValue<String, String> &E : mapped_files) {301if (!_is_item_checked(E.key)) {302continue;303}304305String path = E.value; // We're going to mutate it.306307bool is_directory = false;308if (path.ends_with("/")) {309path = path.trim_suffix("/");310is_directory = true;311}312313TreeItem *parent_item;314315int separator = path.rfind_char('/');316if (separator == -1) {317parent_item = root;318} else {319String parent_path = path.substr(0, separator);320HashMap<String, TreeItem *>::Iterator I = directory_item_map.find(parent_path);321ERR_CONTINUE(!I);322parent_item = I->value;323}324325if (is_directory) {326_create_dir_item(destination_tree, parent_item, path, directory_item_map);327} else {328int num_file_conflicts = 0; // Don't need it, but need to pass something.329_create_file_item(destination_tree, parent_item, path, &num_file_conflicts);330}331}332}333334TreeItem *EditorAssetInstaller::_create_dir_item(Tree *p_tree, TreeItem *p_parent, const String &p_path, HashMap<String, TreeItem *> &p_item_map) {335TreeItem *ti = p_tree->create_item(p_parent);336337if (p_tree == source_tree) {338ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);339ti->set_editable(0, true);340ti->set_checked(0, true);341ti->propagate_check(0);342_fix_conflicted_indeterminate_state(ti->get_tree()->get_root(), 0);343344Dictionary meta;345meta["asset_path"] = p_path + "/";346meta["is_dir"] = true;347meta["is_conflict"] = false;348ti->set_metadata(0, meta);349}350351ti->set_text(0, p_path.get_file() + "/");352ti->set_icon(0, get_theme_icon(SNAME("folder"), SNAME("FileDialog")));353354p_item_map[p_path] = ti;355return ti;356}357358TreeItem *EditorAssetInstaller::_create_file_item(Tree *p_tree, TreeItem *p_parent, const String &p_path, int *r_conflicts) {359TreeItem *ti = p_tree->create_item(p_parent);360361if (p_tree == source_tree) {362ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);363ti->set_editable(0, true);364365bool target_exists = _update_source_item_status(ti, p_path);366if (target_exists) {367if (first_file_conflict == nullptr) {368first_file_conflict = ti;369}370*r_conflicts += 1;371}372373Dictionary meta;374meta["asset_path"] = p_path;375meta["is_dir"] = false;376meta["is_conflict"] = target_exists;377ti->set_metadata(0, meta);378}379380String file = p_path.get_file();381String extension = file.get_extension().to_lower();382if (extension_icon_map.has(extension)) {383ti->set_icon(0, extension_icon_map[extension]);384} else {385ti->set_icon(0, generic_extension_icon);386}387ti->set_text(0, file);388389return ti;390}391392void EditorAssetInstaller::_update_conflict_status(int p_conflicts) {393if (p_conflicts >= 1) {394asset_conflicts_link->set_text(vformat(TTRN("%d file conflicts with your project and won't be installed", "%d files conflict with your project and won't be installed", p_conflicts), p_conflicts));395asset_conflicts_link->show();396asset_conflicts_label->hide();397} else {398asset_conflicts_link->hide();399asset_conflicts_label->show();400}401}402403void EditorAssetInstaller::_update_confirm_button() {404TreeItem *root = source_tree->get_root();405get_ok_button()->set_disabled(!root || (!root->is_checked(0) && !root->is_indeterminate(0)));406}407408void EditorAssetInstaller::_toggle_source_tree(bool p_visible, bool p_scroll_to_error) {409source_tree_vb->set_visible(p_visible);410show_source_files_button->set_pressed_no_signal(p_visible); // To keep in sync if triggered by something else.411412if (p_visible) {413show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Back")));414} else {415show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Forward")));416}417418if (p_visible && p_scroll_to_error && first_file_conflict) {419source_tree->scroll_to_item(first_file_conflict, true);420}421}422423void EditorAssetInstaller::_check_has_toplevel() {424// Check if the file structure has a distinct top-level directory. This is typical425// for archives generated by GitHub, etc, but not for manually created ZIPs.426427toplevel_prefix = "";428skip_toplevel_check->set_pressed(false);429skip_toplevel_check->set_disabled(true);430skip_toplevel_check->set_tooltip_text(TTRC("This asset doesn't have a root directory, so it can't be ignored."));431432if (asset_files.is_empty()) {433return;434}435436String first_asset;437for (const String &E : asset_files) {438if (first_asset.is_empty()) { // Checking the first file/directory.439if (!E.ends_with("/")) {440return; // No directories in this asset.441}442443// We will match everything else against this directory.444first_asset = E;445continue;446}447448if (!E.begins_with(first_asset)) {449return; // Found a file or a directory that doesn't share the same base path.450}451}452453toplevel_prefix = first_asset;454skip_toplevel_check->set_disabled(false);455skip_toplevel_check->set_tooltip_text(TTRC("Ignore the root directory when extracting files."));456}457458void EditorAssetInstaller::_set_skip_toplevel(bool p_checked) {459if (skip_toplevel == p_checked) {460return;461}462463skip_toplevel = p_checked;464_update_file_mappings();465_update_source_tree();466_rebuild_destination_tree();467}468469void EditorAssetInstaller::_open_target_dir_dialog() {470if (!target_dir_dialog) {471target_dir_dialog = memnew(EditorFileDialog);472target_dir_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);473target_dir_dialog->set_title(TTRC("Select Install Folder"));474target_dir_dialog->set_current_dir(target_dir_path);475target_dir_dialog->connect("dir_selected", callable_mp(this, &EditorAssetInstaller::_target_dir_selected));476add_child(target_dir_dialog);477}478479target_dir_dialog->popup_file_dialog();480}481482void EditorAssetInstaller::_target_dir_selected(const String &p_target_path) {483if (target_dir_path == p_target_path) {484return;485}486487target_dir_path = p_target_path;488_update_file_mappings();489_update_source_tree();490_rebuild_destination_tree();491}492493void EditorAssetInstaller::ok_pressed() {494_install_asset();495}496497void EditorAssetInstaller::_install_asset() {498Ref<FileAccess> io_fa;499zlib_filefunc_def io = zipio_create_io(&io_fa);500501unzFile pkg = unzOpen2(package_path.utf8().get_data(), &io);502if (!pkg) {503EditorToaster::get_singleton()->popup_str(vformat(TTR("Error opening asset file for \"%s\" (not in ZIP format)."), asset_name), EditorToaster::SEVERITY_ERROR);504return;505}506507Vector<String> failed_files;508int ret = unzGoToFirstFile(pkg);509510ProgressDialog::get_singleton()->add_task("uncompress", TTR("Uncompressing Assets"), file_item_map.size());511512Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);513for (int idx = 0; ret == UNZ_OK; ret = unzGoToNextFile(pkg), idx++) {514unz_file_info info;515char fname[16384];516ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);517if (ret != UNZ_OK) {518break;519}520521String source_name = String::utf8(fname);522if (!_is_item_checked(source_name)) {523continue;524}525526HashMap<String, String>::Iterator E = mapped_files.find(source_name);527if (!E) {528continue; // No remapped path means we don't want it; most likely the root.529}530531String target_path = target_dir_path.path_join(E->value);532533Dictionary asset_meta = file_item_map[source_name]->get_metadata(0);534bool is_dir = asset_meta.get("is_dir", false);535if (is_dir) {536if (target_path.ends_with("/")) {537target_path = target_path.substr(0, target_path.length() - 1);538}539540da->make_dir_recursive(target_path);541} else {542Vector<uint8_t> uncomp_data;543uncomp_data.resize(info.uncompressed_size);544545unzOpenCurrentFile(pkg);546unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());547unzCloseCurrentFile(pkg);548549// Ensure that the target folder exists.550da->make_dir_recursive(target_path.get_base_dir());551552Ref<FileAccess> f = FileAccess::open(target_path, FileAccess::WRITE);553if (f.is_valid()) {554f->store_buffer(uncomp_data.ptr(), uncomp_data.size());555} else {556failed_files.push_back(target_path);557}558559ProgressDialog::get_singleton()->task_step("uncompress", target_path, idx);560}561}562563ProgressDialog::get_singleton()->end_task("uncompress");564unzClose(pkg);565566if (failed_files.size()) {567String msg = vformat(TTR("The following files failed extraction from asset \"%s\":"), asset_name) + "\n\n";568for (int i = 0; i < failed_files.size(); i++) {569if (i > 10) {570msg += "\n" + vformat(TTR("(and %s more files)"), itos(failed_files.size() - i));571break;572}573msg += "\n" + failed_files[i];574}575if (EditorNode::get_singleton() != nullptr) {576EditorNode::get_singleton()->show_warning(msg);577}578} else {579if (EditorNode::get_singleton() != nullptr) {580EditorNode::get_singleton()->show_warning(vformat(TTR("Asset \"%s\" installed successfully!"), asset_name), TTRC("Success!"));581}582}583584EditorFileSystem::get_singleton()->scan_changes();585}586587void EditorAssetInstaller::set_asset_name(const String &p_asset_name) {588asset_name = p_asset_name;589}590591String EditorAssetInstaller::get_asset_name() const {592return asset_name;593}594595void EditorAssetInstaller::_notification(int p_what) {596switch (p_what) {597case NOTIFICATION_THEME_CHANGED: {598if (show_source_files_button->is_pressed()) {599show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Back")));600} else {601show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Forward")));602}603asset_conflicts_link->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));604605generic_extension_icon = get_editor_theme_icon(SNAME("Object"));606607extension_icon_map.clear();608{609extension_icon_map["bmp"] = get_editor_theme_icon(SNAME("ImageTexture"));610extension_icon_map["dds"] = get_editor_theme_icon(SNAME("ImageTexture"));611extension_icon_map["exr"] = get_editor_theme_icon(SNAME("ImageTexture"));612extension_icon_map["hdr"] = get_editor_theme_icon(SNAME("ImageTexture"));613extension_icon_map["jpg"] = get_editor_theme_icon(SNAME("ImageTexture"));614extension_icon_map["jpeg"] = get_editor_theme_icon(SNAME("ImageTexture"));615extension_icon_map["png"] = get_editor_theme_icon(SNAME("ImageTexture"));616extension_icon_map["svg"] = get_editor_theme_icon(SNAME("ImageTexture"));617extension_icon_map["tga"] = get_editor_theme_icon(SNAME("ImageTexture"));618extension_icon_map["webp"] = get_editor_theme_icon(SNAME("ImageTexture"));619620extension_icon_map["wav"] = get_editor_theme_icon(SNAME("AudioStreamWAV"));621extension_icon_map["ogg"] = get_editor_theme_icon(SNAME("AudioStreamOggVorbis"));622extension_icon_map["mp3"] = get_editor_theme_icon(SNAME("AudioStreamMP3"));623624extension_icon_map["scn"] = get_editor_theme_icon(SNAME("PackedScene"));625extension_icon_map["tscn"] = get_editor_theme_icon(SNAME("PackedScene"));626extension_icon_map["escn"] = get_editor_theme_icon(SNAME("PackedScene"));627extension_icon_map["dae"] = get_editor_theme_icon(SNAME("PackedScene"));628extension_icon_map["gltf"] = get_editor_theme_icon(SNAME("PackedScene"));629extension_icon_map["glb"] = get_editor_theme_icon(SNAME("PackedScene"));630631extension_icon_map["gdshader"] = get_editor_theme_icon(SNAME("Shader"));632extension_icon_map["gdshaderinc"] = get_editor_theme_icon(SNAME("TextFile"));633extension_icon_map["gd"] = get_editor_theme_icon(SNAME("GDScript"));634if (ClassDB::class_exists("CSharpScript")) {635extension_icon_map["cs"] = get_editor_theme_icon(SNAME("CSharpScript"));636} else {637// Mark C# support as unavailable.638extension_icon_map["cs"] = get_editor_theme_icon(SNAME("ImportFail"));639}640641extension_icon_map["res"] = get_editor_theme_icon(SNAME("Resource"));642extension_icon_map["tres"] = get_editor_theme_icon(SNAME("Resource"));643extension_icon_map["atlastex"] = get_editor_theme_icon(SNAME("AtlasTexture"));644// By default, OBJ files are imported as Mesh resources rather than PackedScenes.645extension_icon_map["obj"] = get_editor_theme_icon(SNAME("MeshItem"));646647extension_icon_map["txt"] = get_editor_theme_icon(SNAME("TextFile"));648extension_icon_map["md"] = get_editor_theme_icon(SNAME("TextFile"));649extension_icon_map["rst"] = get_editor_theme_icon(SNAME("TextFile"));650extension_icon_map["json"] = get_editor_theme_icon(SNAME("TextFile"));651extension_icon_map["yml"] = get_editor_theme_icon(SNAME("TextFile"));652extension_icon_map["yaml"] = get_editor_theme_icon(SNAME("TextFile"));653extension_icon_map["toml"] = get_editor_theme_icon(SNAME("TextFile"));654extension_icon_map["cfg"] = get_editor_theme_icon(SNAME("TextFile"));655extension_icon_map["ini"] = get_editor_theme_icon(SNAME("TextFile"));656}657} break;658}659}660661EditorAssetInstaller::EditorAssetInstaller() {662VBoxContainer *vb = memnew(VBoxContainer);663add_child(vb);664665// Status bar.666667HBoxContainer *asset_status = memnew(HBoxContainer);668vb->add_child(asset_status);669670Label *asset_label = memnew(Label);671asset_label->set_text(TTRC("Asset:"));672asset_label->set_theme_type_variation("HeaderSmall");673asset_status->add_child(asset_label);674675asset_title_label = memnew(Label);676asset_title_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);677asset_status->add_child(asset_title_label);678679// File remapping controls.680681HBoxContainer *remapping_tools = memnew(HBoxContainer);682vb->add_child(remapping_tools);683684show_source_files_button = memnew(Button);685show_source_files_button->set_toggle_mode(true);686show_source_files_button->set_tooltip_text(TTRC("Open the list of the asset contents and select which files to install."));687remapping_tools->add_child(show_source_files_button);688show_source_files_button->connect(SceneStringName(toggled), callable_mp(this, &EditorAssetInstaller::_toggle_source_tree).bind(false));689690Button *target_dir_button = memnew(Button);691target_dir_button->set_text(TTRC("Change Install Folder"));692target_dir_button->set_tooltip_text(TTRC("Change the folder where the contents of the asset are going to be installed."));693remapping_tools->add_child(target_dir_button);694target_dir_button->connect(SceneStringName(pressed), callable_mp(this, &EditorAssetInstaller::_open_target_dir_dialog));695696remapping_tools->add_child(memnew(VSeparator));697698skip_toplevel_check = memnew(CheckBox);699skip_toplevel_check->set_text(TTRC("Ignore asset root"));700skip_toplevel_check->set_tooltip_text(TTRC("Ignore the root directory when extracting files."));701skip_toplevel_check->connect(SceneStringName(toggled), callable_mp(this, &EditorAssetInstaller::_set_skip_toplevel));702remapping_tools->add_child(skip_toplevel_check);703704remapping_tools->add_spacer();705706asset_conflicts_label = memnew(Label);707asset_conflicts_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);708asset_conflicts_label->set_theme_type_variation("HeaderSmall");709asset_conflicts_label->set_text(TTRC("No files conflict with your project"));710remapping_tools->add_child(asset_conflicts_label);711asset_conflicts_link = memnew(LinkButton);712asset_conflicts_link->set_theme_type_variation("HeaderSmallLink");713asset_conflicts_link->set_v_size_flags(Control::SIZE_SHRINK_CENTER);714asset_conflicts_link->set_tooltip_text(TTRC("Show contents of the asset and conflicting files."));715asset_conflicts_link->set_visible(false);716remapping_tools->add_child(asset_conflicts_link);717asset_conflicts_link->connect(SceneStringName(pressed), callable_mp(this, &EditorAssetInstaller::_toggle_source_tree).bind(true, true));718719// File hierarchy trees.720721HSplitContainer *tree_split = memnew(HSplitContainer);722tree_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);723vb->add_child(tree_split);724725source_tree_vb = memnew(VBoxContainer);726source_tree_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);727source_tree_vb->set_visible(show_source_files_button->is_pressed());728tree_split->add_child(source_tree_vb);729730Label *source_tree_label = memnew(Label);731source_tree_label->set_text(TTRC("Contents of the asset:"));732source_tree_label->set_theme_type_variation("HeaderSmall");733source_tree_vb->add_child(source_tree_label);734735source_tree = memnew(Tree);736source_tree->set_accessibility_name(TTRC("Source Files"));737source_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);738source_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);739source_tree->connect("item_edited", callable_mp(this, &EditorAssetInstaller::_item_checked_cbk));740source_tree->set_theme_type_variation("TreeSecondary");741source_tree_vb->add_child(source_tree);742743VBoxContainer *destination_tree_vb = memnew(VBoxContainer);744destination_tree_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);745tree_split->add_child(destination_tree_vb);746747Label *destination_tree_label = memnew(Label);748destination_tree_label->set_text(TTRC("Installation preview:"));749destination_tree_label->set_theme_type_variation("HeaderSmall");750destination_tree_vb->add_child(destination_tree_label);751752destination_tree = memnew(Tree);753destination_tree->set_accessibility_name(TTRC("Destination Files"));754destination_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);755destination_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);756destination_tree->connect("item_edited", callable_mp(this, &EditorAssetInstaller::_item_checked_cbk));757destination_tree_vb->add_child(destination_tree);758759// Dialog configuration.760761set_title(TTRC("Configure Asset Before Installing"));762set_ok_button_text(TTRC("Install"));763set_hide_on_ok(true);764}765766767