diff --git a/File_Format_Library/FileFormats/BMD/BMD.cs b/File_Format_Library/FileFormats/BMD/BMD.cs index fe65f6db..594aa3f2 100644 --- a/File_Format_Library/FileFormats/BMD/BMD.cs +++ b/File_Format_Library/FileFormats/BMD/BMD.cs @@ -18,8 +18,10 @@ using OpenTK; namespace FirstPlugin { - public class BMD : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer + public class BMD : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer, ITextureIconLoader { + public List IconTextureList { get; set; } + public FileType FileType { get; set; } = FileType.Layout; public bool CanSave { get; set; } @@ -115,6 +117,7 @@ namespace FirstPlugin DrawableContainer.Drawables.Add(Skeleton); Textures = new Dictionary(); + IconTextureList = new List(); BMD_Renderer.TextureContainers.Add(this); @@ -254,6 +257,7 @@ namespace FirstPlugin var texWrapper = new BMDTextureWrapper(BMDFile.Textures.Textures[i]); TextureFolder.Nodes.Add(texWrapper); Renderer.TextureList.Add(texWrapper); + IconTextureList.Add(texWrapper); } } diff --git a/File_Format_Library/FileFormats/Texture/BNTX.cs b/File_Format_Library/FileFormats/Texture/BNTX.cs index 25eb1278..6a1a8c23 100644 --- a/File_Format_Library/FileFormats/Texture/BNTX.cs +++ b/File_Format_Library/FileFormats/Texture/BNTX.cs @@ -23,6 +23,8 @@ namespace FirstPlugin { public class BNTX : TreeNodeFile, IFileFormat, IContextMenuNode { + public List IconTextureList { get; set; } + public FileType FileType { get; set; } = FileType.Image; public bool CanSave { get; set; } @@ -482,6 +484,7 @@ namespace FirstPlugin public void LoadFile(Stream stream, string Name = "") { Textures = new Dictionary(StringComparer.InvariantCultureIgnoreCase); + IconTextureList = new List(); BinaryTexFile = new BntxFile(stream); Text = BinaryTexFile.Name; diff --git a/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs b/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs index f0fb8917..964c5747 100644 --- a/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs +++ b/Switch_Toolbox_Library/Forms/Custom/TreeViewCustom.cs @@ -102,9 +102,13 @@ namespace Toolbox.Library imgList.Images.Add(image); } + private Thread Thread; public void ReloadTextureIcons() { - Thread Thread = new Thread((ThreadStart)(() => + if (Thread != null && Thread.IsAlive) + Thread.Abort(); + + Thread = new Thread((ThreadStart)(() => { foreach (var textureIconList in TextureIcons) { @@ -123,18 +127,54 @@ namespace Toolbox.Library public void ReloadTextureIcons(ITextureIconLoader textureIconList) { - Thread Thread = new Thread((ThreadStart)(() => + if (Thread != null && Thread.IsAlive) + Thread.Abort(); + + this.BeginUpdate(); + + Thread = new Thread((ThreadStart)(() => { + foreach (TreeNode node in textureIconList.IconTextureList) + node.ImageKey = "Texture"; + + this.Invoke((MethodInvoker)delegate + { + { + this.Refresh(); + } + }); + foreach (TreeNode node in textureIconList.IconTextureList) { if (node is STGenericTexture) { - var image = ((STGenericTexture)node).GetBitmap(); - AddImageOnThread(image, node); + try + { + var image = ((STGenericTexture)node).GetBitmap(); + AddImageOnThread(image, node); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } } } + + if (this.InvokeRequired) + { + this.Invoke((MethodInvoker)delegate + { + { + this.EndUpdate(); + this.Refresh(); + } + }); + } + else + this.EndUpdate(); })); Thread.Start(); + } public void AddImageOnThread(Image image, TreeNode node) @@ -149,7 +189,6 @@ namespace Toolbox.Library this.ImageList.Images.Add(image); var dummy = this.ImageList.Handle; - this.Refresh(); image.Dispose(); }); diff --git a/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs b/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs index 733cb31f..9bb23056 100644 --- a/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs +++ b/Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs @@ -520,25 +520,27 @@ namespace Toolbox.Library imageData = CTR_3DS.DecodeBlock(data, (int)Width, (int)Height, Format); DontSwapRG = true; } - if (PlatformSwizzle == PlatformSwizzle.Platform_Gamecube) + else if (PlatformSwizzle == PlatformSwizzle.Platform_Gamecube) imageData = Decode_Gamecube.DecodeData(data, paletteData, Width, Height, Format, PaletteFormat); - - if (Format == TEX_FORMAT.R32G8X24_FLOAT) - imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, DDS.DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS); - - if (Format == TEX_FORMAT.BC5_SNORM) - imageData = DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true, true); - - if (IsCompressed(Format)) - imageData = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format); else { - if (IsAtscFormat(Format)) - imageData = ASTCDecoder.DecodeToRGBA8888(data, (int)GetBlockWidth(Format), (int)GetBlockHeight(Format), 1, (int)Width, (int)Height, 1); - else - imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format); + if (Format == TEX_FORMAT.R32G8X24_FLOAT) + imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, DDS.DXGI_FORMAT.DXGI_FORMAT_R32G8X24_TYPELESS); - // imageData = RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format); + if (Format == TEX_FORMAT.BC5_SNORM) + imageData = DDSCompressor.DecompressBC5(data, (int)Width, (int)Height, true, true); + + if (IsCompressed(Format)) + imageData = DDSCompressor.DecompressBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format); + else + { + if (IsAtscFormat(Format)) + imageData = ASTCDecoder.DecodeToRGBA8888(data, (int)GetBlockWidth(Format), (int)GetBlockHeight(Format), 1, (int)Width, (int)Height, 1); + else + imageData = DDSCompressor.DecodePixelBlock(data, (int)Width, (int)Height, (DDS.DXGI_FORMAT)Format); + + // imageData = RGBAPixelDecoder.Decode(data, (int)Width, (int)Height, Format); + } } if (parameters.DontSwapRG || DontSwapRG) diff --git a/Switch_Toolbox_Library/Toolbox.Library.dll b/Switch_Toolbox_Library/Toolbox.Library.dll index cae8e055..7c710f05 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.dll and b/Switch_Toolbox_Library/Toolbox.Library.dll differ diff --git a/Switch_Toolbox_Library/Toolbox.Library.pdb b/Switch_Toolbox_Library/Toolbox.Library.pdb index 4a344d1d..f938effa 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.pdb and b/Switch_Toolbox_Library/Toolbox.Library.pdb differ