From dc523e3bd2016ca358027193cbe799c66fc0ef28 Mon Sep 17 00:00:00 2001 From: Pavle Date: Sat, 4 Jul 2020 11:47:23 +0200 Subject: [PATCH] Fixed texture preview and option for exporting all files --- GlacierTEXEditor/ExportAllTextures.cs | 32 +++++-- GlacierTEXEditor/Form1.cs | 124 ++++++++++++++------------ 2 files changed, 92 insertions(+), 64 deletions(-) diff --git a/GlacierTEXEditor/ExportAllTextures.cs b/GlacierTEXEditor/ExportAllTextures.cs index 73245c0..22d049b 100644 --- a/GlacierTEXEditor/ExportAllTextures.cs +++ b/GlacierTEXEditor/ExportAllTextures.cs @@ -153,12 +153,19 @@ private void BtnExportAllTextures_Click(object sender, EventArgs e) var dictionary = options1.ElementAt(i).Value.Extensions; dictionary.Add(extension, new Dictionary()); - List dimensions = GetDimensions(i); + if (Textures[i].NumOfMipMips > 1) + { + List dimensions = GetDimensions(i); - for (int j = 0; j < dimensions.Count; j++) + for (int j = 0; j < dimensions.Count; j++) + { + dictionary.ElementAt(dictionary.Count - 1).Value.Add(j, dimensions[j]); + } + } + else { - int width = Convert.ToInt32(dimensions[j].Substring(0, dimensions[j].IndexOf('x'))); - dictionary.ElementAt(dictionary.Count - 1).Value.Add(Textures[i].Width / width, dimensions[j]); + string dimensions = Textures[i].Width + "x" + Textures[i].Height; + dictionary.ElementAt(dictionary.Count - 1).Value.Add(0, dimensions); } } } @@ -177,14 +184,21 @@ private void BtnExportAllTextures_Click(object sender, EventArgs e) ExportOptions.Add(i, new Option()); ExportOptions.ElementAt(i).Value.ExportAsSingleFile = true; - ExportOptions.ElementAt(i).Value.Extensions.Add("DDS", new Dictionary()); + ExportOptions.ElementAt(i).Value.Extensions.Add(".dds", new Dictionary()); - List dimensions = GetDimensions(i); + if (Textures[i].NumOfMipMips > 1) + { + List dimensions = GetDimensions(i); - for (int j = 0; j < dimensions.Count; j++) + for (int j = 0; j < dimensions.Count; j++) + { + ExportOptions.ElementAt(i).Value.Extensions.ElementAt(0).Value.Add(j, dimensions[j]); + } + } + else { - int width = Convert.ToInt32(dimensions[j].Substring(0, dimensions[j].IndexOf('x'))); - ExportOptions.ElementAt(i).Value.Extensions.ElementAt(0).Value.Add(Textures[i].Width / width, dimensions[j]); + string dimensions = Textures[i].Width + "x" + Textures[i].Height; + ExportOptions.ElementAt(i).Value.Extensions.ElementAt(0).Value.Add(0, dimensions); } } } diff --git a/GlacierTEXEditor/Form1.cs b/GlacierTEXEditor/Form1.cs index e7faf67..37e543f 100644 --- a/GlacierTEXEditor/Form1.cs +++ b/GlacierTEXEditor/Form1.cs @@ -138,6 +138,9 @@ private void CbZipFiles_SelectedIndexChanged(object sender, EventArgs e) tsmiSaveTEX.Enabled = true; cmsSaveTEX.Enabled = true; + tsmiExtractAllFiles.Enabled = true; + cmsExtractAllFiles.Enabled = true; + selectedZipPath = cbZipFiles.SelectedItem.ToString(); filePath = Path.Combine(GetOutputPath(), Path.GetFileNameWithoutExtension(selectedZipPath) + ".TEX"); @@ -1393,7 +1396,7 @@ private bool ExportRGBAFile(Texture texture, string exportPath, int index = 0) } else { - SaveToImage(data, texture.Width, texture.Height, exportPath, extension); + SaveToImage(data, width, height, exportPath, extension); } } @@ -1683,7 +1686,7 @@ private bool ExportPALNFile(Texture texture, string exportPath, int index = 0) } else { - SaveToImage(data, texture.Width, texture.Height, exportPath, extension); + SaveToImage(data, width, height, exportPath, extension); } return true; @@ -1802,7 +1805,7 @@ private bool ExportI8File(Texture texture, string exportPath, int index = 0) } else { - SaveToImage(texture.Data[0], texture.Width, texture.Height, exportPath, extension, StbImageWriteSharp.ColorComponents.Grey); + SaveToImage(texture.Data[0], width, height, exportPath, extension, StbImageWriteSharp.ColorComponents.Grey); } return true; @@ -1922,7 +1925,7 @@ private bool ExportU8V8File(Texture texture, string exportPath, int index = 0) } else { - SaveToImage(colors, texture.Width, texture.Height, exportPath, extension); + SaveToImage(colors, width, height, exportPath, extension); } return true; @@ -2545,6 +2548,8 @@ private void ExportFile() private void ExportAllFiles() { + toolStripStatusLabel1.Text = "Exporting all textures..."; + using (ExportAllTextures exportAllTextures = new ExportAllTextures()) { exportAllTextures.Textures = textures; @@ -2552,86 +2557,88 @@ private void ExportAllFiles() if (dialogResult == DialogResult.OK) { - for (int i = 0; i < exportAllTextures.ExportOptions.Count; i++) + Dictionary options = exportAllTextures.ExportOptions; + + foreach (KeyValuePair option in options) { - Texture texture = textures[i]; - Dictionary options = exportAllTextures.ExportOptions; + Texture texture = textures[option.Key]; - foreach (KeyValuePair option in options) + foreach (var entry in option.Value.Extensions) { - foreach (var entry in option.Value.Extensions) - { - string extension = entry.Key; - string exportPath = Path.Combine(exportAllTextures.ExportPath, texture.GetFileName(extension)); + string extension = entry.Key; + string exportPath = Path.Combine(exportAllTextures.ExportPath, texture.GetFileName(extension)); - if (extension.Equals(".dds")) + if (extension.Equals(".dds")) + { + if (option.Value.ExportAsSingleFile) { - if (option.Value.ExportAsSingleFile) - { - ExportSelectedOptionsToDDS(texture, entry.Value, texture.Type1, exportPath); - } - else - { - Dictionary paths = GetExportPaths(entry.Value, texture.Width, texture.Height, extension, exportPath); - - foreach (KeyValuePair entry2 in paths) - { - switch (texture.Type1) - { - case "DXT1": - ExportDXTFile(texture, entry2.Value, entry2.Key); - break; - case "DXT3": - ExportDXTFile(texture, entry2.Value, entry2.Key); - break; - case "RGBA": - ExportRGBAFile(texture, entry2.Value, entry2.Key); - break; - case "PALN": - ExportPALNFile(texture, entry2.Value, entry2.Key); - break; - case "I8 ": - ExportI8File(texture, entry2.Value, entry2.Key); - break; - case "U8V8": - ExportU8V8File(texture, entry2.Value, entry2.Key); - break; - } - } - } + ExportSelectedOptionsToDDS(texture, entry.Value, texture.Type1, exportPath); } else { - foreach (var entry2 in entry.Value) + Dictionary paths = GetExportPaths(entry.Value, texture.Width, texture.Height, extension, exportPath); + + foreach (KeyValuePair entry2 in paths) { switch (texture.Type1) { case "DXT1": - ExportDXTFile(texture, exportPath, entry2.Key); + ExportDXTFile(texture, entry2.Value, entry2.Key); break; case "DXT3": - ExportDXTFile(texture, exportPath, entry2.Key); + ExportDXTFile(texture, entry2.Value, entry2.Key); break; case "RGBA": - ExportRGBAFile(texture, exportPath, entry2.Key); + ExportRGBAFile(texture, entry2.Value, entry2.Key); break; case "PALN": - ExportPALNFile(texture, exportPath, entry2.Key); + ExportPALNFile(texture, entry2.Value, entry2.Key); break; case "I8 ": - ExportI8File(texture, exportPath, entry2.Key); + ExportI8File(texture, entry2.Value, entry2.Key); break; case "U8V8": - ExportU8V8File(texture, exportPath, entry2.Key); + ExportU8V8File(texture, entry2.Value, entry2.Key); break; } } } } + else + { + Dictionary paths = GetExportPaths(entry.Value, texture.Width, texture.Height, extension, exportPath); + + foreach (KeyValuePair entry2 in paths) + { + switch (texture.Type1) + { + case "DXT1": + ExportDXTFile(texture, entry2.Value, entry2.Key); + break; + case "DXT3": + ExportDXTFile(texture, entry2.Value, entry2.Key); + break; + case "RGBA": + ExportRGBAFile(texture, entry2.Value, entry2.Key); + break; + case "PALN": + ExportPALNFile(texture, entry2.Value, entry2.Key); + break; + case "I8 ": + ExportI8File(texture, entry2.Value, entry2.Key); + break; + case "U8V8": + ExportU8V8File(texture, entry2.Value, entry2.Key); + break; + } + } + } } } } } + + toolStripStatusLabel1.Text = "All textures exported successfully."; } private string ReverseTypeText(string type) @@ -2949,11 +2956,9 @@ private void LvTexDetails_SelectedIndexChanged(object sender, EventArgs e) { tsmiImportFile.Enabled = true; tsmiExportFile.Enabled = true; - tsmiExtractAllFiles.Enabled = true; cmsImportFile.Enabled = true; cmsExportFile.Enabled = true; - cmsExtractAllFiles.Enabled = true; } } @@ -3019,6 +3024,11 @@ private void DisplayTexture(Texture texture) private void DisplayDXTTexture(Texture texture, int index, int width, int height) { byte[] data = ConvertDXTToRGBA(texture.Data[index], width, height, texture.Type1); + + byte[] data2 = new byte[data.Length]; + Array.Copy(data, 0, data2, 0, data.Length); + + ConvertRGBAToBGRA(data, width, height); Bitmap bmp = BMPImage.DataToBitmap(data, width, height); pbTexture.Image = bmp; @@ -3097,6 +3107,8 @@ private void DisplayU8V8Texture(Texture texture, int index, int width, int heigh private void AddZipFiles(string path) { + toolStripStatusLabel1.Text = "Adding ZIP files."; + List files = Directory.GetFiles(path, "*.zip*", SearchOption.AllDirectories).ToList(); cbZipFiles.Items.Clear(); @@ -3105,6 +3117,8 @@ private void AddZipFiles(string path) { cbZipFiles.Items.Add(file); } + + toolStripStatusLabel1.Text = "ZIP files added successfully."; } private void BtnCreateTEXFile_Click(object sender, EventArgs e)