diff --git a/File_Format_Library/FileFormats/BMD/BMD.cs b/File_Format_Library/FileFormats/BMD/BMD.cs index fe304c6d..c7ad22b6 100644 --- a/File_Format_Library/FileFormats/BMD/BMD.cs +++ b/File_Format_Library/FileFormats/BMD/BMD.cs @@ -116,9 +116,11 @@ namespace FirstPlugin LoadBMD(BMDFile); } - private class BMDTextureFolder : STTextureFolder, ITextureIconLoader + private class BMDTextureFolder : STTextureFolder, ITextureContainer { - public List IconTextureList + public bool DisplayIcons => true; + + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/Effects/PCTL.cs b/File_Format_Library/FileFormats/Effects/PCTL.cs index 2015e4f3..35eb272a 100644 --- a/File_Format_Library/FileFormats/Effects/PCTL.cs +++ b/File_Format_Library/FileFormats/Effects/PCTL.cs @@ -272,13 +272,15 @@ namespace FirstPlugin } } - public class TextureFolder : TreeNodeCustom, IContextMenuNode, ITextureIconLoader + public class TextureFolder : TreeNodeCustom, IContextMenuNode, ITextureContainer { public TextureFolder(string text) { Text = text; } + public bool DisplayIcons => true; + public ToolStripItem[] GetContextMenuItems() { return new ToolStripItem[] @@ -287,7 +289,7 @@ namespace FirstPlugin }; } - public List IconTextureList + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/Grezzo/CMB.cs b/File_Format_Library/FileFormats/Grezzo/CMB.cs index 49f3119f..73f9180d 100644 --- a/File_Format_Library/FileFormats/Grezzo/CMB.cs +++ b/File_Format_Library/FileFormats/Grezzo/CMB.cs @@ -496,9 +496,11 @@ namespace FirstPlugin } } - private class TextureFolder : STTextureFolder, ITextureIconLoader + private class TextureFolder : STTextureFolder, ITextureContainer { - public List IconTextureList + public bool DisplayIcons => true; + + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/Grezzo/CTXB.cs b/File_Format_Library/FileFormats/Grezzo/CTXB.cs index 3d2abab2..e291d670 100644 --- a/File_Format_Library/FileFormats/Grezzo/CTXB.cs +++ b/File_Format_Library/FileFormats/Grezzo/CTXB.cs @@ -11,7 +11,7 @@ using Toolbox.Library.Forms; namespace FirstPlugin { - public class CTXB : TreeNodeFile, IFileFormat, ITextureIconLoader + public class CTXB : TreeNodeFile, IFileFormat, ITextureContainer { public FileType FileType { get; set; } = FileType.Archive; @@ -39,7 +39,9 @@ namespace FirstPlugin } } - public List IconTextureList + public bool DisplayIcons => true; + + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/HyruleWarriors/G1T/G1T.cs b/File_Format_Library/FileFormats/HyruleWarriors/G1T/G1T.cs index 0511bfef..5bb70991 100644 --- a/File_Format_Library/FileFormats/HyruleWarriors/G1T/G1T.cs +++ b/File_Format_Library/FileFormats/HyruleWarriors/G1T/G1T.cs @@ -10,7 +10,7 @@ using System.Drawing; namespace FirstPlugin { - public class G1T : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureIconLoader + public class G1T : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer { public FileType FileType { get; set; } = FileType.Image; @@ -38,8 +38,9 @@ namespace FirstPlugin } } + public bool DisplayIcons => true; - public List IconTextureList + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs b/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs index e68b8f5f..165aab80 100644 --- a/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs +++ b/File_Format_Library/FileFormats/Layout/Rev/BRLYT.cs @@ -121,7 +121,7 @@ namespace LayoutBXLYT { TPL tpl = (TPL)file.OpenFile(); file.FileFormat = tpl; - foreach (var tex in tpl.IconTextureList) + foreach (var tex in tpl.TextureList) { //Only need the first texture if (!textures.ContainsKey(tex.Text)) diff --git a/File_Format_Library/FileFormats/NLG/MarioStrikers/StrikersRLT.cs b/File_Format_Library/FileFormats/NLG/MarioStrikers/StrikersRLT.cs index eb267c2a..b6f9e3ff 100644 --- a/File_Format_Library/FileFormats/NLG/MarioStrikers/StrikersRLT.cs +++ b/File_Format_Library/FileFormats/NLG/MarioStrikers/StrikersRLT.cs @@ -8,7 +8,7 @@ using System.Runtime.InteropServices; namespace FirstPlugin.NLG { - public class StrikersRLT : TreeNodeFile, IFileFormat, ITextureIconLoader + public class StrikersRLT : TreeNodeFile, IFileFormat, ITextureContainer { public FileType FileType { get; set; } = FileType.Image; @@ -37,7 +37,9 @@ namespace FirstPlugin.NLG } } - public List IconTextureList + public bool DisplayIcons => true; + + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/Texture/BNTX.cs b/File_Format_Library/FileFormats/Texture/BNTX.cs index 2935456a..08dc6cd4 100644 --- a/File_Format_Library/FileFormats/Texture/BNTX.cs +++ b/File_Format_Library/FileFormats/Texture/BNTX.cs @@ -21,7 +21,7 @@ using FirstPlugin.Forms; namespace FirstPlugin { - public class BNTX : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureIconLoader + public class BNTX : TreeNodeFile, IFileFormat, IContextMenuNode, ITextureContainer { public bool LoadIcons = false; @@ -58,7 +58,9 @@ namespace FirstPlugin } } - public List IconTextureList + public bool DisplayIcons => LoadIcons; + + public List TextureList { get { @@ -563,7 +565,7 @@ namespace FirstPlugin public void LoadFile(Stream stream, string Name = "") { Textures = new Dictionary(StringComparer.InvariantCultureIgnoreCase); - IconTextureList = new List(); + TextureList = new List(); BinaryTexFile = new BntxFile(stream); Text = BinaryTexFile.Name; diff --git a/File_Format_Library/FileFormats/Texture/CTPK.cs b/File_Format_Library/FileFormats/Texture/CTPK.cs index caaa703b..7db1c045 100644 --- a/File_Format_Library/FileFormats/Texture/CTPK.cs +++ b/File_Format_Library/FileFormats/Texture/CTPK.cs @@ -12,7 +12,7 @@ using System.Runtime.InteropServices; namespace FirstPlugin { - public class CTPK : TreeNodeFile, IFileFormat, ITextureIconLoader + public class CTPK : TreeNodeFile, IFileFormat, ITextureContainer { public FileType FileType { get; set; } = FileType.Layout; @@ -31,7 +31,9 @@ namespace FirstPlugin } } - public List IconTextureList + public bool DisplayIcons => true; + + public List TextureList { get { diff --git a/File_Format_Library/FileFormats/Texture/TPL.cs b/File_Format_Library/FileFormats/Texture/TPL.cs index 54dcf745..e0ceb8ef 100644 --- a/File_Format_Library/FileFormats/Texture/TPL.cs +++ b/File_Format_Library/FileFormats/Texture/TPL.cs @@ -11,7 +11,7 @@ using Toolbox.Library.IO; namespace FirstPlugin { - public class TPL : TreeNodeFile, IFileFormat, ITextureIconLoader + public class TPL : TreeNodeFile, IFileFormat, ITextureContainer { public FileType FileType { get; set; } = FileType.Image; @@ -40,7 +40,9 @@ namespace FirstPlugin } } - public List IconTextureList + public bool DisplayIcons => true; + + public List TextureList { get { diff --git a/Switch_Toolbox_Library/Compression/Formats/Zlib.cs b/Switch_Toolbox_Library/Compression/Formats/Zlib.cs index a5e60246..d7ded8e9 100644 --- a/Switch_Toolbox_Library/Compression/Formats/Zlib.cs +++ b/Switch_Toolbox_Library/Compression/Formats/Zlib.cs @@ -34,8 +34,7 @@ namespace Toolbox.Library reader.ReadUInt16(); IsValid = magicNumber == 0x789C || magicNumber == 0x78DA; - if (IsValid) - { + if (IsValid) { startPosition = reader.Position - 4; break; } diff --git a/Switch_Toolbox_Library/Forms/Custom/Treeview/TreeViewCustom.cs b/Switch_Toolbox_Library/Forms/Custom/Treeview/TreeViewCustom.cs index df7e511f..8c03cfb6 100644 --- a/Switch_Toolbox_Library/Forms/Custom/Treeview/TreeViewCustom.cs +++ b/Switch_Toolbox_Library/Forms/Custom/Treeview/TreeViewCustom.cs @@ -85,7 +85,7 @@ namespace Toolbox.Library { private readonly Dictionary _treeNodes = new Dictionary(); - public List TextureIcons = new List(); + public List TextureIcons = new List(); public List SingleTextureIcons = new List(); public TreeViewCustom() @@ -113,7 +113,10 @@ namespace Toolbox.Library { for (int i = 0; i < TextureIcons.Count; i++) { - foreach (TreeNode node in TextureIcons[i].IconTextureList) + if (!TextureIcons[i].DisplayIcons) + continue; + + foreach (TreeNode node in TextureIcons[i].TextureList) { if (node is STGenericTexture) { @@ -268,8 +271,11 @@ namespace Toolbox.Library Thread.Start(); } - public void ReloadTextureIcons(ITextureIconLoader textureIconList) + public void ReloadTextureIcons(ITextureContainer textureIconList) { + if (!textureIconList.DisplayIcons) + return; + if (Thread != null && Thread.IsAlive) Thread.Abort(); @@ -280,7 +286,7 @@ namespace Toolbox.Library List treeNodes = new List(); List imageIcons = new List(); - foreach (TreeNode node in textureIconList.IconTextureList) + foreach (TreeNode node in textureIconList.TextureList) { if (node is STGenericTexture) { diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs index a958e380..bd083ccd 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs @@ -100,8 +100,8 @@ namespace Toolbox.Library.Forms AddNode((TreeNode)FileFormat); } - if (FileFormat is ITextureIconLoader) { - ObjectTree.LoadGenericTextureIcons((ITextureIconLoader)FileFormat); + if (FileFormat is ITextureContainer) { + ObjectTree.LoadGenericTextureIcons((ITextureContainer)FileFormat); } } diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs index 37a0f9ea..20af8470 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs @@ -829,7 +829,7 @@ namespace Toolbox.Library.Forms treeViewCustom1.ReloadTextureIcons(texIcons, false); } - public void LoadGenericTextureIcons(ITextureIconLoader iconList) { + public void LoadGenericTextureIcons(ITextureContainer iconList) { treeViewCustom1.TextureIcons.Add(iconList); treeViewCustom1.ReloadTextureIcons(iconList); } @@ -870,9 +870,9 @@ namespace Toolbox.Library.Forms { if (e.Node == null) return; - else if (e.Node is ITextureIconLoader) { + else if (e.Node is ITextureContainer) { treeViewCustom1.BeginUpdate(); - LoadGenericTextureIcons((ITextureIconLoader)e.Node); + LoadGenericTextureIcons((ITextureContainer)e.Node); treeViewCustom1.EndUpdate(); } else if (e.Node is ISingleTextureIconLoader) { diff --git a/Switch_Toolbox_Library/Interfaces/Textures/ITextureContainer.cs b/Switch_Toolbox_Library/Interfaces/Textures/ITextureContainer.cs index 7e1c9393..bc65eddd 100644 --- a/Switch_Toolbox_Library/Interfaces/Textures/ITextureContainer.cs +++ b/Switch_Toolbox_Library/Interfaces/Textures/ITextureContainer.cs @@ -8,6 +8,8 @@ namespace Toolbox.Library { public interface ITextureContainer { - Dictionary Textures { get; set; } + List TextureList { get; set; } + + bool DisplayIcons { get; } } } diff --git a/Switch_Toolbox_Library/Interfaces/Textures/ITextureIconLoader.cs b/Switch_Toolbox_Library/Interfaces/Textures/ITextureIconLoader.cs index b39eaa50..3667cbc5 100644 --- a/Switch_Toolbox_Library/Interfaces/Textures/ITextureIconLoader.cs +++ b/Switch_Toolbox_Library/Interfaces/Textures/ITextureIconLoader.cs @@ -6,15 +6,6 @@ using System.Threading.Tasks; namespace Toolbox.Library { - /// - /// A texture list to display icons on a treeview - /// Note these will load and attach an icon when the parent treenode is expanded! - /// - public interface ITextureIconLoader - { - List IconTextureList { get; set; } - } - /// /// Reprenets a single texture that loads an icon. /// These will check both on expand, and on root diff --git a/Switch_Toolbox_Library/Rendering/GenericModelRenderer/GenericModelRenderer.cs b/Switch_Toolbox_Library/Rendering/GenericModelRenderer/GenericModelRenderer.cs index 2b7b07fa..64d94243 100644 --- a/Switch_Toolbox_Library/Rendering/GenericModelRenderer/GenericModelRenderer.cs +++ b/Switch_Toolbox_Library/Rendering/GenericModelRenderer/GenericModelRenderer.cs @@ -337,10 +337,13 @@ namespace Toolbox.Library.Rendering foreach (var container in TextureContainers) { - if (container.Textures.ContainsKey(activeTex)) + for (int i = 0; i < container.TextureList?.Count; i++) { - BindGLTexture(tex, shader, container.Textures[activeTex]); - return tex.textureUnit + 1; + if (activeTex == container.TextureList[i].Text) + { + BindGLTexture(tex, shader, container.TextureList[i]); + return tex.textureUnit + 1; + } } } diff --git a/Toolbox/MainForm.Designer.cs b/Toolbox/MainForm.Designer.cs index 93dae9fb..c2542df7 100644 --- a/Toolbox/MainForm.Designer.cs +++ b/Toolbox/MainForm.Designer.cs @@ -44,6 +44,7 @@ this.toolsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.compressionToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.batchToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.hashCalculatorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.experimentalToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.windowsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.cascadeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -72,7 +73,7 @@ this.stToolStrip1 = new Toolbox.Library.Forms.STToolStrip(); this.saveToolStripButton = new System.Windows.Forms.ToolStripButton(); this.updateToolstrip = new System.Windows.Forms.ToolStripButton(); - this.hashCalculatorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.batchExportTexturesAllSupportedFormatsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.stPanel1.SuspendLayout(); this.tabControlContextMenuStrip.SuspendLayout(); @@ -185,7 +186,8 @@ this.toolsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.compressionToolStripMenuItem, this.batchToolStripMenuItem, - this.hashCalculatorToolStripMenuItem}); + this.hashCalculatorToolStripMenuItem, + this.batchExportTexturesAllSupportedFormatsToolStripMenuItem}); this.toolsToolStripMenuItem.Name = "toolsToolStripMenuItem"; this.toolsToolStripMenuItem.Size = new System.Drawing.Size(47, 21); this.toolsToolStripMenuItem.Text = "Tools"; @@ -193,16 +195,23 @@ // compressionToolStripMenuItem // this.compressionToolStripMenuItem.Name = "compressionToolStripMenuItem"; - this.compressionToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.compressionToolStripMenuItem.Size = new System.Drawing.Size(315, 22); this.compressionToolStripMenuItem.Text = "Compression"; // // batchToolStripMenuItem // this.batchToolStripMenuItem.Name = "batchToolStripMenuItem"; - this.batchToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.batchToolStripMenuItem.Size = new System.Drawing.Size(315, 22); this.batchToolStripMenuItem.Text = "Batch Set File Table"; this.batchToolStripMenuItem.Click += new System.EventHandler(this.batchToolStripMenuItem_Click); // + // hashCalculatorToolStripMenuItem + // + this.hashCalculatorToolStripMenuItem.Name = "hashCalculatorToolStripMenuItem"; + this.hashCalculatorToolStripMenuItem.Size = new System.Drawing.Size(315, 22); + this.hashCalculatorToolStripMenuItem.Text = "Hash Calculator"; + this.hashCalculatorToolStripMenuItem.Click += new System.EventHandler(this.hashCalculatorToolStripMenuItem_Click); + // // experimentalToolStripMenuItem // this.experimentalToolStripMenuItem.Name = "experimentalToolStripMenuItem"; @@ -465,12 +474,12 @@ this.updateToolstrip.ToolTipText = "Update Tool"; this.updateToolstrip.Click += new System.EventHandler(this.updateToolstrip_Click); // - // hashCalculatorToolStripMenuItem + // batchExportTexturesAllSupportedFormatsToolStripMenuItem // - this.hashCalculatorToolStripMenuItem.Name = "hashCalculatorToolStripMenuItem"; - this.hashCalculatorToolStripMenuItem.Size = new System.Drawing.Size(180, 22); - this.hashCalculatorToolStripMenuItem.Text = "Hash Calculator"; - this.hashCalculatorToolStripMenuItem.Click += new System.EventHandler(this.hashCalculatorToolStripMenuItem_Click); + this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Name = "batchExportTexturesAllSupportedFormatsToolStripMenuItem"; + this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Size = new System.Drawing.Size(315, 22); + this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Text = "Batch Export Textures (All Supported Formats)"; + this.batchExportTexturesAllSupportedFormatsToolStripMenuItem.Click += new System.EventHandler(this.batchExportTexturesAllSupportedFormatsToolStripMenuItem_Click); // // MainForm // @@ -552,5 +561,6 @@ private System.Windows.Forms.ToolStripMenuItem openFolderToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem batchToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem hashCalculatorToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem batchExportTexturesAllSupportedFormatsToolStripMenuItem; } } diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index d6dec672..bd9caed8 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -1343,5 +1343,89 @@ namespace Toolbox HashCalculatorForm form = new HashCalculatorForm(); form.Show(this); } + + private void batchExportTexturesAllSupportedFormatsToolStripMenuItem_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Multiselect = true; + + if (ofd.ShowDialog() == DialogResult.OK) + { + FolderSelectDialog folderDlg = new FolderSelectDialog(); + if (folderDlg.ShowDialog() == DialogResult.OK) { + BatchExportTextures(ofd.FileNames, folderDlg.SelectedPath); + } + } + } + + private void BatchExportTextures(string[] files, string outputFolder) + { + List Formats = new List(); + Formats.Add("Portable Graphics Network (.png)"); + Formats.Add("Microsoft DDS (.dds)"); + Formats.Add("Joint Photographic Experts Group (.jpg)"); + Formats.Add("Bitmap Image (.bmp)"); + Formats.Add("Tagged Image File Format (.tiff)"); + Formats.Add("ASTC (.astc)"); + + List failedFiles = new List(); + + BatchFormatExport form = new BatchFormatExport(Formats); + if (form.ShowDialog() == DialogResult.OK) + { + string extension = form.GetSelectedExtension(); + foreach (var file in files) + { + try + { + var fileFormat = STFileLoader.OpenFileFormat(file); + SearchFileFormat(fileFormat, extension, outputFolder); + } + catch + { + failedFiles.Add(file); + } + } + } + + if (failedFiles.Count > 0) + { + string detailList = ""; + foreach (var file in failedFiles) + detailList += $"{file}\n"; + + STErrorDialog.Show("Some files failed to export! See detail list of failed files.", "Switch Toolbox", detailList); + } + else + MessageBox.Show("Files batched successfully!"); + } + + private void SearchFileFormat(IFileFormat fileFormat, string extension, string outputFolder) + { + if (fileFormat == null) return; + + if (fileFormat is STGenericTexture) + ExportTexture(((STGenericTexture)fileFormat), $"{outputFolder}/{fileFormat.FileName}.{extension}"); + else if (fileFormat is IArchiveFile) + SearchArchive((IArchiveFile)fileFormat, extension, outputFolder); + else if (fileFormat is ITextureContainer) + { + foreach (STGenericTexture tex in ((ITextureContainer)fileFormat).TextureList) { + ExportTexture(tex, $"{outputFolder}/{tex.Text}.{extension}"); + } + } + + fileFormat.Unload(); + } + + private void ExportTexture(STGenericTexture tex, string filePath) { + tex.Export(filePath); + } + + private void SearchArchive(IArchiveFile archiveFile, string extension, string outputFolder) + { + foreach (var file in archiveFile.Files) + SearchFileFormat(file.OpenFile(), extension, outputFolder); + } } }