public void InitializeSpeciesImages(List <Species> species) { var creatureColors = new byte[] { 44, 42, 57, 10, 26, 78 }; // uniform color pattern that is used for all species in the selector var creatureColorsPolar = new byte[] { 18, 18, 18, 18, 18, 18 }; // uniform color pattern that is used for all polar species in the selector var lImgList = new ImageList(); _iconIndices = new List <string>(); bool imageFolderExist = !string.IsNullOrEmpty(CreatureColored.ImageFolder) && Directory.Exists(CreatureColored.ImageFolder); //var speciesWOImage = new List<string>();// to determine which species have no image yet foreach (Species s in species) { if (!imageFolderExist) { continue; } var(imgExists, imagePath, speciesListName) = CreatureColored.SpeciesImageExists(s, s.name.Contains("Polar") ? creatureColorsPolar : creatureColors); //if (!imgExists && !speciesWOImage.Contains(s.name)) speciesWOImage.Add(s.name); if (!imgExists || _iconIndices.Contains(speciesListName)) { continue; } try { lImgList.Images.Add(Image.FromFile(imagePath)); _iconIndices.Add(speciesListName); } catch (OutOfMemoryException) { // usually this exception occurs if the image file is corrupted if (FileService.TryDeleteFile(imagePath)) { (imgExists, imagePath, speciesListName) = CreatureColored.SpeciesImageExists(s, s.name.Contains("Polar") ? creatureColorsPolar : creatureColors); if (imgExists) { try { lImgList.Images.Add(Image.FromFile(imagePath)); _iconIndices.Add(speciesListName); } catch { // ignore image if it failed a second time } } } } } //Clipboard.SetText(speciesWOImage.Any() ? string.Join("\n", speciesWOImage) : string.Empty); lImgList.ImageSize = new Size(64, 64); lvLastSpecies.LargeImageList = lImgList; lvSpeciesInLibrary.LargeImageList = lImgList; UpdateLastSpecies(); UpdateLibraryList(); }
private static (List <SpeciesListEntry>, ImageList, List <string>) LoadSpeciesImagesAndCreateSpeciesList(List <Species> species, Dictionary <string, string> aliases) { Dictionary <string, Species> speciesNameToSpecies = new Dictionary <string, Species>(); var creatureColors = new int[] { 44, 42, 57, 10, 26, 78 }; // uniform color pattern that is used for all species in the selector var creatureColorsPolar = new int[] { 18, 18, 18, 18, 18, 18 }; // uniform color pattern that is used for all polar species in the selector ImageList lImgList = new ImageList(); var iconIndices = new List <string>(); bool imageFolderExist = Directory.Exists(FileService.GetPath(FileService.ImageFolderName)); //var speciesWOImage = new List<string>();// to determine which species have no image yet foreach (Species ss in species) { if (!speciesNameToSpecies.ContainsKey(ss.DescriptiveNameAndMod)) { speciesNameToSpecies.Add(ss.DescriptiveNameAndMod, ss); } if (!imageFolderExist) { continue; } var(imgExists, imagePath, speciesListName) = CreatureColored.SpeciesImageExists(ss, ss.name.Contains("Polar") ? creatureColorsPolar : creatureColors); if (!imgExists || iconIndices.Contains(speciesListName)) { continue; } try { lImgList.Images.Add(Image.FromFile(imagePath)); iconIndices.Add(speciesListName); } catch (OutOfMemoryException) { // usually this exception occurs if the image file is corrupted if (FileService.TryDeleteFile(imagePath)) { (imgExists, imagePath, speciesListName) = CreatureColored.SpeciesImageExists(ss, ss.name.Contains("Polar") ? creatureColorsPolar : creatureColors); if (imgExists) { try { lImgList.Images.Add(Image.FromFile(imagePath)); } catch { // ignore image if it failed a second time } iconIndices.Add(speciesListName); } } } //if (!imgExists && !speciesWOImage.Contains(ss.name)) speciesWOImage.Add(ss.name); } //Clipboard.SetText(string.Join("\n", speciesWOImage)); var entryList = new List <SpeciesListEntry>(); foreach (var s in species) { entryList.Add(new SpeciesListEntry { DisplayName = s.name, SearchName = s.name, ModName = s.Mod?.title ?? string.Empty, Species = s }); } foreach (var a in aliases) { if (speciesNameToSpecies.ContainsKey(a.Value)) { entryList.Add(new SpeciesListEntry { DisplayName = a.Key + " (→" + speciesNameToSpecies[a.Value].name + ")", SearchName = a.Key, Species = speciesNameToSpecies[a.Value], ModName = speciesNameToSpecies[a.Value].Mod?.title ?? string.Empty, }); } } entryList = entryList.OrderBy(s => s.DisplayName).ToList(); return(entryList, lImgList, iconIndices); }