From 181420f3b229f8e40a1bfe7bfafd3f3a19af0d32 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 29 Aug 2017 20:17:34 -0300 Subject: [PATCH] Added nice icon to show when a file is broken on import. --- editor/editor_file_system.cpp | 7 +++++++ editor/editor_file_system.h | 1 + editor/filesystem_dock.cpp | 32 ++++++++++++++++++++++---------- editor/filesystem_dock.h | 1 + 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 48825d52188..c175886d14e 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -118,6 +118,12 @@ Vector EditorFileSystemDirectory::get_file_deps(int p_idx) const { return files[p_idx]->deps; } +bool EditorFileSystemDirectory::get_file_import_is_valid(int p_idx) const { + + ERR_FAIL_INDEX_V(p_idx, files.size(), false); + return files[p_idx]->import_valid; +} + StringName EditorFileSystemDirectory::get_file_type(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, files.size(), ""); @@ -142,6 +148,7 @@ void EditorFileSystemDirectory::_bind_methods() { ClassDB::bind_method(D_METHOD("get_file", "idx"), &EditorFileSystemDirectory::get_file); ClassDB::bind_method(D_METHOD("get_file_path", "idx"), &EditorFileSystemDirectory::get_file_path); ClassDB::bind_method(D_METHOD("get_file_type", "idx"), &EditorFileSystemDirectory::get_file_type); + ClassDB::bind_method(D_METHOD("get_file_import_is_valid", "idx"), &EditorFileSystemDirectory::get_file_import_is_valid); ClassDB::bind_method(D_METHOD("get_name"), &EditorFileSystemDirectory::get_name); ClassDB::bind_method(D_METHOD("get_path"), &EditorFileSystemDirectory::get_path); ClassDB::bind_method(D_METHOD("get_parent"), &EditorFileSystemDirectory::get_parent); diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index efbbec0e081..cee3219b43f 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -84,6 +84,7 @@ public: String get_file_path(int p_idx) const; StringName get_file_type(int p_idx) const; Vector get_file_deps(int p_idx) const; + bool get_file_import_is_valid(int p_idx) const; EditorFileSystemDirectory *get_parent(); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index d0d8b0f0cd6..9aa856119df 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -367,6 +367,7 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List * fi.name = file; fi.type = p_path->get_file_type(i); fi.path = p_path->get_file_path(i); + fi.import_broken = !p_path->get_file_import_is_valid(i); fi.import_status = 0; matches->push_back(fi); @@ -401,6 +402,7 @@ void FileSystemDock::_update_files(bool p_keep_selection) { thumbnail_size *= EDSCALE; Ref folder_thumbnail; Ref file_thumbnail; + Ref file_thumbnail_broken; bool use_thumbnails = (display_mode == DISPLAY_THUMBNAILS); bool use_folders = search_box->get_text().length() == 0 && split_mode; @@ -434,8 +436,18 @@ void FileSystemDock::_update_files(bool p_keep_selection) { Theme::get_default()->set_icon("ResizedFile", "EditorIcons", resized_file); } + if (!has_icon("ResizedFileBroken", "EditorIcons")) { + Ref file = get_icon("FileBigBroken", "EditorIcons"); + Ref img = file->get_data(); + img->resize(thumbnail_size, thumbnail_size); + Ref resized_file = Ref(memnew(ImageTexture)); + resized_file->create_from_image(img, 0); + Theme::get_default()->set_icon("ResizedFileBroken", "EditorIcons", resized_file); + } + file_thumbnail = get_icon("ResizedFile", "EditorIcons"); + file_thumbnail_broken = get_icon("ResizedFileBroken", "EditorIcons"); } else { files->set_icon_mode(ItemList::ICON_MODE_LEFT); @@ -496,6 +508,7 @@ void FileSystemDock::_update_files(bool p_keep_selection) { fi.name = efd->get_file(i); fi.path = path.plus_file(fi.name); fi.type = efd->get_file_type(i); + fi.import_broken = !efd->get_file_import_is_valid(i); fi.import_status = 0; filelist.push_back(fi); @@ -511,24 +524,21 @@ void FileSystemDock::_update_files(bool p_keep_selection) { StringName type = E->get().type; Ref type_icon; + Ref big_icon = file_thumbnail; String tooltip = fname; - if (E->get().import_status == 0) { + if (!E->get().import_broken) { if (has_icon(type, ei)) { type_icon = get_icon(type, ei); } else { type_icon = get_icon(oi, ei); } - } else if (E->get().import_status == 1) { - type_icon = get_icon("DependencyOk", "EditorIcons"); - } else if (E->get().import_status == 2) { - type_icon = get_icon("DependencyChanged", "EditorIcons"); - tooltip += TTR("\nStatus: Needs Re-Import"); - } else if (E->get().import_status == 3) { + } else { type_icon = get_icon("ImportFail", "EditorIcons"); - tooltip += ("\nStatus: Missing Dependencies"); + big_icon = file_thumbnail_broken; + tooltip += TTR("\nStatus: Import of file failed. Please fix file and reimport manually."); } if (E->get().sources.size()) { @@ -538,14 +548,16 @@ void FileSystemDock::_update_files(bool p_keep_selection) { } if (use_thumbnails) { - files->add_item(fname, file_thumbnail, true); + files->add_item(fname, big_icon, true); files->set_item_metadata(files->get_item_count() - 1, fp); files->set_item_tag_icon(files->get_item_count() - 1, type_icon); Array udata; udata.resize(2); udata[0] = files->get_item_count() - 1; udata[1] = fname; - EditorResourcePreview::get_singleton()->queue_resource_preview(fp, this, "_thumbnail_done", udata); + if (!E->get().import_broken) { + EditorResourcePreview::get_singleton()->queue_resource_preview(fp, this, "_thumbnail_done", udata); + } } else { files->add_item(fname, type_icon, true); files->set_item_metadata(files->get_item_count() - 1, fp); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index c33a745ce48..a35b1450859 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -169,6 +169,7 @@ private: StringName type; int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken Vector sources; + bool import_broken; bool operator<(const FileInfo &fi) const { return name < fi.name;