Skip to content

Commit

Permalink
Fixed texture preview and option for exporting all files
Browse files Browse the repository at this point in the history
  • Loading branch information
pavledev committed Jul 4, 2020
1 parent f0587e1 commit dc523e3
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 64 deletions.
32 changes: 23 additions & 9 deletions GlacierTEXEditor/ExportAllTextures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,19 @@ private void BtnExportAllTextures_Click(object sender, EventArgs e)
var dictionary = options1.ElementAt(i).Value.Extensions;
dictionary.Add(extension, new Dictionary<int, string>());

List<string> dimensions = GetDimensions(i);
if (Textures[i].NumOfMipMips > 1)
{
List<string> 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);
}
}
}
Expand All @@ -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<int, string>());
ExportOptions.ElementAt(i).Value.Extensions.Add(".dds", new Dictionary<int, string>());

List<string> dimensions = GetDimensions(i);
if (Textures[i].NumOfMipMips > 1)
{
List<string> 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);
}
}
}
Expand Down
124 changes: 69 additions & 55 deletions GlacierTEXEditor/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2545,93 +2548,97 @@ private void ExportFile()

private void ExportAllFiles()
{
toolStripStatusLabel1.Text = "Exporting all textures...";

using (ExportAllTextures exportAllTextures = new ExportAllTextures())
{
exportAllTextures.Textures = textures;
DialogResult dialogResult = exportAllTextures.ShowDialog();

if (dialogResult == DialogResult.OK)
{
for (int i = 0; i < exportAllTextures.ExportOptions.Count; i++)
Dictionary<int, Option> options = exportAllTextures.ExportOptions;

foreach (KeyValuePair<int, Option> option in options)
{
Texture texture = textures[i];
Dictionary<int, Option> options = exportAllTextures.ExportOptions;
Texture texture = textures[option.Key];

foreach (KeyValuePair<int, Option> 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<int, string> paths = GetExportPaths(entry.Value, texture.Width, texture.Height, extension, exportPath);

foreach (KeyValuePair<int, string> 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<int, string> paths = GetExportPaths(entry.Value, texture.Width, texture.Height, extension, exportPath);

foreach (KeyValuePair<int, string> 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<int, string> paths = GetExportPaths(entry.Value, texture.Width, texture.Height, extension, exportPath);

foreach (KeyValuePair<int, string> 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)
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<string> files = Directory.GetFiles(path, "*.zip*", SearchOption.AllDirectories).ToList();

cbZipFiles.Items.Clear();
Expand All @@ -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)
Expand Down

0 comments on commit dc523e3

Please sign in to comment.