Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
New Tools and Save All options (#664)
Browse files Browse the repository at this point in the history
* Fix extra frame added to smd animation export

* New batch tools and save all option

* Update MainForm.cs

* Batch Rename BNTX from Filename

* Update MainForm.Designer.cs
  • Loading branch information
MediaMoots authored Oct 17, 2023
1 parent 360bb64 commit 9842158
Show file tree
Hide file tree
Showing 9 changed files with 532 additions and 227 deletions.
8 changes: 4 additions & 4 deletions File_Format_Library/FileFormats/BFRES/BFRESGroupNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,17 @@ private void BatchEditBaseAnimData()
}
}

public override void ReplaceAll()
public override void ReplaceAll(string ReplacePath = "")
{
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
if (ReplacePath != "" || sfd.ShowDialog() == DialogResult.OK)
{
if (Type == BRESGroupType.Textures)
{
GTXTextureImporter importer = new GTXTextureImporter();
List<GTXImporterSettings> settings = new List<GTXImporterSettings>();

foreach (string file in System.IO.Directory.GetFiles(sfd.SelectedPath))
foreach (string file in System.IO.Directory.GetFiles(ReplacePath != "" ? ReplacePath : sfd.SelectedPath))
{
string FileName = System.IO.Path.GetFileNameWithoutExtension(file);

Expand Down Expand Up @@ -260,7 +260,7 @@ public override void ReplaceAll()
}
else
{
foreach (string file in System.IO.Directory.GetFiles(sfd.SelectedPath))
foreach (string file in System.IO.Directory.GetFiles(ReplacePath != "" ? ReplacePath : sfd.SelectedPath))
{
string FileName = System.IO.Path.GetFileNameWithoutExtension(file);

Expand Down
2 changes: 1 addition & 1 deletion Switch_Toolbox_Library/Generics/STGenericWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void ReplaceAllAction(object sender, EventArgs e) {
ReplaceAll();
}

public virtual void ReplaceAll()
public virtual void ReplaceAll(string ReplacePath = "")
{
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
Expand Down
2 changes: 1 addition & 1 deletion Switch_Toolbox_Library/Generics/Texture/GenericTexture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ public override string ExportFilter
{
if (IsAtscFormat(Format))
{
return "Supported Formats|*.astc; *.png;*.tga;*.jpg;*.tiff|" +
return "Supported Formats|*.dds; *.astc; *.png;*.tga;*.jpg;*.tiff|" +
"ASTC |*.astc|" +
"Portable Network Graphics |*.png|" +
"Joint Photographic Experts Group |*.jpg|" +
Expand Down
1 change: 1 addition & 0 deletions Switch_Toolbox_Library/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Runtime
public static bool UseDirectXTexDecoder = true;
public static bool DEVELOPER_DEBUG_MODE = false;
public static bool AlwaysCompressOnSave = false;
public static bool AlwaysSaveAll = true;

public static class ResourceTables
{
Expand Down
547 changes: 330 additions & 217 deletions Toolbox/GUI/Settings.Designer.cs

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Toolbox/GUI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public Settings()
chkBotwFileTable.Checked = Runtime.ResourceTables.BotwTable;
chkTpFileTable.Checked = Runtime.ResourceTables.TpTable;
chkFrameCamera.Checked = Runtime.FrameCamera;
chkAlwaysSaveAll.Checked = Runtime.AlwaysSaveAll;
chkAlwaysCompressOnSave.Checked = Runtime.AlwaysCompressOnSave;
chkViewportGrid.Checked = Runtime.displayGrid;
chkViewportAxisLines.Checked = Runtime.displayAxisLines;
Expand Down Expand Up @@ -664,6 +665,11 @@ private void chkFrameCamera_CheckedChanged(object sender, EventArgs e) {
Runtime.FrameCamera = chkFrameCamera.Checked;
}

private void chkAlwaysSaveAll_CheckedChanged(object sender, EventArgs e)
{
Runtime.AlwaysSaveAll = chkAlwaysSaveAll.Checked;
}

private void chkAlwaysCompressOnSave_CheckedChanged(object sender, EventArgs e) {
Runtime.AlwaysCompressOnSave = chkAlwaysCompressOnSave.Checked;
}
Expand Down
32 changes: 31 additions & 1 deletion Toolbox/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

160 changes: 157 additions & 3 deletions Toolbox/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
using OpenTK.Graphics.OpenGL;
using Toolbox.Library.NodeWrappers;
using Toolbox.Library.Rendering;
using Bfres.Structs;
using Syroot.NintenTools.NSW.Bntx;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
using FirstPlugin;

namespace Toolbox
{
Expand Down Expand Up @@ -475,7 +479,16 @@ private void SaveNodeFormats(ObjectEditor editor, bool UseSaveDialog, bool UseCo
if (format != null)
{
if (!format.CanSave)
return;
{
if (Runtime.AlwaysSaveAll)
{
continue;
}
else
{
return;
}
}

string FileName = format.FilePath;
if (!File.Exists(FileName))
Expand All @@ -488,7 +501,16 @@ private void SaveNodeFormats(ObjectEditor editor, bool UseSaveDialog, bool UseCo
sfd.FileName = format.FileName;

if (sfd.ShowDialog() != DialogResult.OK)
return;
{
if (Runtime.AlwaysSaveAll)
{
continue;
}
else
{
return;
}
}

FileName = sfd.FileName;
}
Expand All @@ -498,7 +520,14 @@ private void SaveNodeFormats(ObjectEditor editor, bool UseSaveDialog, bool UseCo
if (format is STGenericWrapper && !(format is STGenericTexture))
{
((STGenericWrapper)format).Export(FileName);
return;
if (Runtime.AlwaysSaveAll)
{
continue;
}
else
{
return;
}
}

if (node is ArchiveBase)
Expand Down Expand Up @@ -1396,6 +1425,131 @@ private void batchExportModelsToolStripMenuItem_Click(object sender, EventArgs e
}
}

private void batchReplaceTXTGToolStripMenuItem_Click(object sender, EventArgs e)
{
BatchReplaceTXTG();
}

private void BatchReplaceTXTG()
{
ObjectEditor ObjectEditor = (ObjectEditor)ActiveMdiChild;
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
foreach (TreeNode node in ObjectEditor.GetNodes())
{
STGenericWrapper foundNode = (STGenericWrapper)node;
if (foundNode == null)
{
continue;
}

foreach (string file in System.IO.Directory.GetFiles(sfd.SelectedPath))
{
if (!file.Contains(foundNode.Text + "."))
{
continue;
}
foundNode.Replace(file);
}
}
}
}
private void batchReplaceFTPToolStripMenuItem_Click(object sender, EventArgs e)
{
BatchReplaceFTP();
}

private void BatchReplaceFTP()
{
ObjectEditor ObjectEditor = (ObjectEditor)ActiveMdiChild;
FolderSelectDialog sfd = new FolderSelectDialog();
if (sfd.ShowDialog() == DialogResult.OK)
{
foreach (TreeNode node in ObjectEditor.GetNodes())
{
TreeNode foundNode = FindNodeByText(node, "Texture Pattern Animations");

// Skip if no Texture Pattern Animation node
if (foundNode == null)
{
continue;
}

string parentName = foundNode.FullPath.Split('\\')[0];
string sourcePath = Path.Combine(sfd.SelectedPath, parentName + ".bfres");

// Skip if no path found
if (!Directory.Exists(sourcePath))
{
continue;
}

BFRESGroupNode groupNode = (BFRESGroupNode)foundNode;
groupNode.ReplaceAll(sourcePath);
}
}
}

private TreeNode FindNodeByText(TreeNode treeNode, string searchText)
{
// Check if the current node matches the searchText.
if (treeNode.Text == searchText)
{
return treeNode; // Found a match, return the current node.
}

// Recursively search in each child node.
foreach (TreeNode tn in treeNode.Nodes)
{
TreeNode result = FindNodeByText(tn, searchText);
if (result != null)
{
return result; // If a match is found in the child nodes, return it.
}
}

// If no match is found in this subtree, return null.
return null;
}

private void batchRenameBNTXToolStripMenuItem_Click(object sender, EventArgs e)
{
ObjectEditor ObjectEditor = (ObjectEditor)ActiveMdiChild;

foreach (TreeNode node in ObjectEditor.GetNodes())
{
FirstPlugin.BNTX foundNode = (FirstPlugin.BNTX)node;

// Skip if no BNTX
if (foundNode == null)
{
continue;
}

string fileName = Path.GetFileNameWithoutExtension(foundNode.FilePath).Split('.')[0];

// Rename file
foundNode.Text = fileName;
if (foundNode.BinaryTexFile != null)
{
foundNode.BinaryTexFile.Name = fileName;
}

string textureKey = foundNode.Textures.Keys.FirstOrDefault();
TextureData textureData = foundNode.Textures.Values.FirstOrDefault();
if (textureData != null)
{
textureData.Text = fileName;
textureData.Name = fileName;
textureData.Texture.Name = fileName;
foundNode.Textures.Remove(textureKey);
foundNode.Textures.Add(fileName, textureData);
}
}
ObjectEditor.Update();
}

private List<string> failedFiles = new List<string>();
private List<string> batchExportFileList = new List<string>();
private void BatchExportModels(string[] files, string outputFolder)
Expand Down
1 change: 1 addition & 0 deletions Toolbox/Toolbox.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<HintPath>Lib\OpenTK.GLControl.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Syroot.NintenTools.NSW.Bntx, Version=1.2.3.0, Culture=neutral, PublicKeyToken=null" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
Expand Down

0 comments on commit 9842158

Please sign in to comment.