Add quick access menu for gfpak
This commit is contained in:
parent
0190aef233
commit
ac474b1754
@ -12,7 +12,7 @@ using Toolbox.Library.Forms;
|
||||
|
||||
namespace FirstPlugin
|
||||
{
|
||||
public class GFPAK : IArchiveFile, IFileFormat
|
||||
public class GFPAK : TreeNodeFile, IArchiveFile, IFileFormat
|
||||
{
|
||||
public FileType FileType { get; set; } = FileType.Archive;
|
||||
|
||||
@ -23,6 +23,22 @@ namespace FirstPlugin
|
||||
public string FilePath { get; set; }
|
||||
public IFileInfo IFileInfo { get; set; }
|
||||
|
||||
public Dictionary<string, string> CategoryLookup
|
||||
{
|
||||
get {
|
||||
return new Dictionary<string, string>()
|
||||
{
|
||||
{ ".bnsh_vsh", "VertexShader" },
|
||||
{ ".bnsh_fsh", "FragmentShader" },
|
||||
{ ".bntx", "Textures" },
|
||||
{ ".gfbmdl", "Models" },
|
||||
{ ".gfbanm", "Animations" },
|
||||
{ ".gfbanmcfg", "AnimationConfigs" },
|
||||
{ ".gfbpokecfg", "PokemonConfigs" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private string FindMatch(byte[] f)
|
||||
{
|
||||
if (f.Matches("SARC")) return ".szs";
|
||||
@ -107,6 +123,237 @@ namespace FirstPlugin
|
||||
CanSave = true;
|
||||
|
||||
Read(new FileReader(stream));
|
||||
|
||||
TreeNode node = new TreeNode("Quick access");
|
||||
Nodes.Add(node);
|
||||
Dictionary<string, TreeNode> folders = new Dictionary<string, TreeNode>();
|
||||
foreach (var file in files)
|
||||
{
|
||||
string ext = Utils.GetExtension(file.FileName);
|
||||
string folderName = "Other";
|
||||
if (CategoryLookup.ContainsKey(ext))
|
||||
folderName = CategoryLookup[ext];
|
||||
|
||||
if (!folders.ContainsKey(folderName))
|
||||
{
|
||||
TreeNode folder = new TreeNode(folderName);
|
||||
if (folderName == "Textures")
|
||||
folder = new TextureFolder(this, "Textures");
|
||||
if (folderName == "Models")
|
||||
folder = new ModelFolder("Models");
|
||||
|
||||
node.Nodes.Add(folder);
|
||||
folders.Add(folderName, folder);
|
||||
}
|
||||
|
||||
string name = Path.GetFileName(file.FileName).Split('[').FirstOrDefault();
|
||||
|
||||
string imageKey = "fileBlank";
|
||||
switch (ext)
|
||||
{
|
||||
case ".bntx": imageKey = "bntx"; break;
|
||||
case ".gfbmdl": imageKey = "model"; break;
|
||||
}
|
||||
|
||||
TreeNode fodlerNode = folders[folderName];
|
||||
fodlerNode.Nodes.Add(new QuickAccessFile(name)
|
||||
{
|
||||
Tag = file,
|
||||
ImageKey = imageKey,
|
||||
SelectedImageKey = imageKey,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class QuickAccessFile : TreeNodeCustom
|
||||
{
|
||||
public QuickAccessFile(string text) {
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override void OnClick(TreeView treeview)
|
||||
{
|
||||
ArchiveFilePanel editor = (ArchiveFilePanel)LibraryGUI.GetActiveContent(typeof(ArchiveFilePanel));
|
||||
if (editor == null)
|
||||
{
|
||||
editor = new ArchiveFilePanel();
|
||||
editor.Dock = DockStyle.Fill;
|
||||
LibraryGUI.LoadEditor(editor);
|
||||
}
|
||||
|
||||
editor.LoadFile((ArchiveFileInfo)Tag);
|
||||
editor.UpdateEditor();
|
||||
}
|
||||
}
|
||||
|
||||
public class ModelFolder : TreeNodeCustom
|
||||
{
|
||||
private bool HasExpanded = false;
|
||||
|
||||
public ModelFolder(string text) {
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public override void OnExpand()
|
||||
{
|
||||
if (HasExpanded) return;
|
||||
|
||||
List<GFBMDL> models = new List<GFBMDL>();
|
||||
foreach (TreeNode node in Nodes)
|
||||
{
|
||||
var file = (ArchiveFileInfo)node.Tag;
|
||||
if (file.FileFormat == null)
|
||||
file.FileFormat = file.OpenFile();
|
||||
|
||||
var model = file.FileFormat as GFBMDL;
|
||||
if (model != null) {
|
||||
model.Tag = file;
|
||||
model.ImageKey = "model";
|
||||
model.SelectedImageKey = "model";
|
||||
models.Add(model);
|
||||
}
|
||||
}
|
||||
|
||||
Nodes.Clear();
|
||||
Nodes.AddRange(models.ToArray());
|
||||
|
||||
HasExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public class TextureFolder : TreeNodeCustom, IContextMenuNode
|
||||
{
|
||||
private bool HasExpanded = false;
|
||||
|
||||
private IArchiveFile ArchiveFile;
|
||||
|
||||
public TextureFolder(IArchiveFile archive, string text) {
|
||||
ArchiveFile = archive;
|
||||
Text = text;
|
||||
}
|
||||
|
||||
public void AddTexture(string fileName)
|
||||
{
|
||||
BNTX bntx = BNTX.CreateBNTXFromTexture(fileName);
|
||||
var mem = new MemoryStream();
|
||||
bntx.Save(mem);
|
||||
|
||||
string filePath = fileName;
|
||||
|
||||
ArchiveFile.AddFile(new ArchiveFileInfo()
|
||||
{
|
||||
FileData = mem.ToArray(),
|
||||
FileFormat = bntx,
|
||||
FileName = filePath,
|
||||
});
|
||||
}
|
||||
|
||||
private void OnTextureDeleted(object sender, EventArgs e)
|
||||
{
|
||||
var tex = (TextureData)sender;
|
||||
foreach (var file in ArchiveFile.Files)
|
||||
{
|
||||
if (file.FileFormat != null && file.FileFormat is BNTX) {
|
||||
var bntx = (BNTX)file.FileFormat;
|
||||
if (bntx.Textures.ContainsKey(tex.Text))
|
||||
{
|
||||
bntx.RemoveTexture(tex);
|
||||
bntx.Unload();
|
||||
ArchiveFile.DeleteFile(file);
|
||||
Nodes.RemoveByKey(tex.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ToolStripItem[] GetContextMenuItems()
|
||||
{
|
||||
List<ToolStripItem> Items = new List<ToolStripItem>();
|
||||
Items.Add(new ToolStripMenuItem("Export All", null, ExportAllAction, Keys.Control | Keys.E));
|
||||
Items.Add(new ToolStripMenuItem("Replace Textures (From Folder)", null, ReplaceAllAction, Keys.Control | Keys.R));
|
||||
|
||||
return Items.ToArray();
|
||||
}
|
||||
|
||||
private void ReplaceAllAction(object sender, EventArgs args) {
|
||||
LoadTextures();
|
||||
|
||||
List<BNTX> bntxFiles = new List<BNTX>();
|
||||
foreach (TextureData node in Nodes)
|
||||
bntxFiles.Add(node.ParentBNTX);
|
||||
|
||||
if (bntxFiles.Count > 0)
|
||||
BNTX.ReplaceAll(bntxFiles.ToArray());
|
||||
}
|
||||
|
||||
private void ExportAllAction(object sender, EventArgs args)
|
||||
{
|
||||
LoadTextures();
|
||||
|
||||
List<string> Formats = new List<string>();
|
||||
Formats.Add("Microsoft DDS (.dds)");
|
||||
Formats.Add("Portable Graphics Network (.png)");
|
||||
Formats.Add("Joint Photographic Experts Group (.jpg)");
|
||||
Formats.Add("Bitmap Image (.bmp)");
|
||||
Formats.Add("Tagged Image File Format (.tiff)");
|
||||
|
||||
FolderSelectDialog sfd = new FolderSelectDialog();
|
||||
|
||||
if (sfd.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
string folderPath = sfd.SelectedPath;
|
||||
|
||||
BatchFormatExport form = new BatchFormatExport(Formats);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
foreach (STGenericTexture tex in Nodes)
|
||||
{
|
||||
if (form.Index == 0)
|
||||
tex.SaveDDS(folderPath + '\\' + tex.Text + ".dds");
|
||||
else if (form.Index == 1)
|
||||
tex.SaveBitMap(folderPath + '\\' + tex.Text + ".png");
|
||||
else if (form.Index == 2)
|
||||
tex.SaveBitMap(folderPath + '\\' + tex.Text + ".jpg");
|
||||
else if (form.Index == 3)
|
||||
tex.SaveBitMap(folderPath + '\\' + tex.Text + ".bmp");
|
||||
else if (form.Index == 4)
|
||||
tex.SaveBitMap(folderPath + '\\' + tex.Text + ".tiff");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnExpand() {
|
||||
LoadTextures();
|
||||
}
|
||||
|
||||
public void LoadTextures()
|
||||
{
|
||||
if (HasExpanded) return;
|
||||
|
||||
List<TreeNode> textures = new List<TreeNode>();
|
||||
foreach (TreeNode node in Nodes)
|
||||
{
|
||||
var file = (ArchiveFileInfo)node.Tag;
|
||||
if (file.FileFormat == null)
|
||||
file.FileFormat = file.OpenFile();
|
||||
|
||||
BNTX bntx = file.FileFormat as BNTX;
|
||||
foreach (var tex in bntx.Textures)
|
||||
{
|
||||
tex.Value.OnTextureDeleted += OnTextureDeleted;
|
||||
//Set tree key for deletion
|
||||
tex.Value.Name = tex.Key;
|
||||
tex.Value.Tag = file;
|
||||
textures.Add(tex.Value);
|
||||
}
|
||||
}
|
||||
|
||||
Nodes.Clear();
|
||||
Nodes.AddRange(textures.ToArray());
|
||||
|
||||
HasExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void Unload()
|
||||
|
@ -17,7 +17,8 @@ namespace Toolbox.Library
|
||||
public virtual void OnMouseRightClick(TreeView treeview) { }
|
||||
public virtual void OnDoubleMouseClick(TreeView treeview) { }
|
||||
|
||||
|
||||
public virtual void OnExpand() { }
|
||||
|
||||
public TreeNodeCustom()
|
||||
{
|
||||
}
|
||||
|
@ -56,6 +56,43 @@ namespace Toolbox.Library.Forms
|
||||
FileRoot.Nodes.Add(n);
|
||||
}
|
||||
|
||||
if (FileFormat is IArchiveQuickAccess)
|
||||
{
|
||||
var lookup = ((IArchiveQuickAccess)FileFormat).CategoryLookup;
|
||||
|
||||
TreeNode quickAcessNode = new TreeNode("Quick access");
|
||||
AddNode(quickAcessNode);
|
||||
|
||||
Dictionary<string, TreeNode> folders = new Dictionary<string, TreeNode>();
|
||||
for (int i = 0; i < FileRoot.FileNodes.Count; i++)
|
||||
{
|
||||
string fileName = FileRoot.FileNodes[i].Item1.FileName;
|
||||
string name = System.IO.Path.GetFileName(fileName);
|
||||
string ext = Utils.GetExtension(fileName);
|
||||
|
||||
var fileNode = FileRoot.FileNodes[i].Item2;
|
||||
|
||||
string folder = "Other";
|
||||
if (lookup.ContainsKey(ext))
|
||||
folder = lookup[ext];
|
||||
|
||||
if (!folders.ContainsKey(folder)) {
|
||||
var dirNode = new TreeNode(folder);
|
||||
folders.Add(folder, dirNode);
|
||||
quickAcessNode.Nodes.Add(dirNode);
|
||||
}
|
||||
|
||||
folders[folder].Nodes.Add(new TreeNode()
|
||||
{
|
||||
Tag = fileNode,
|
||||
Text = name,
|
||||
ImageKey = fileNode.ImageKey,
|
||||
SelectedImageKey = fileNode.SelectedImageKey,
|
||||
});
|
||||
// dirNode.Nodes.Add(FileRoot.FileNodes[i].Item2);
|
||||
}
|
||||
}
|
||||
|
||||
SelectNode(FileRoot);
|
||||
|
||||
for (int i = 0; i < FileRoot.FileNodes.Count; i++)
|
||||
@ -271,6 +308,10 @@ namespace Toolbox.Library.Forms
|
||||
{
|
||||
((TreeNodeCustom)treeViewCustom1.SelectedNode).OnDoubleMouseClick(treeViewCustom1);
|
||||
}
|
||||
if (treeViewCustom1.SelectedNode.Tag != null && treeViewCustom1.SelectedNode.Tag is TreeNodeCustom)
|
||||
{
|
||||
((TreeNodeCustom)treeViewCustom1.SelectedNode.Tag).OnDoubleMouseClick(treeViewCustom1);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateTextureIcon(ISingleTextureIconLoader texturIcon, Image image) {
|
||||
@ -314,14 +355,9 @@ namespace Toolbox.Library.Forms
|
||||
ClearNodes();
|
||||
}
|
||||
|
||||
private void GetArchiveMenus(TreeNode node, ArchiveFileInfo info)
|
||||
private ToolStripItem[] GetArchiveMenus(TreeNode node, ArchiveFileInfo info)
|
||||
{
|
||||
STToolStipMenuItem menuItem = new STToolStipMenuItem("Archive");
|
||||
treeNodeContextMenu.Items.Add(menuItem);
|
||||
|
||||
var items = info.FileWrapper.GetContextMenuItems();
|
||||
foreach (var item in items)
|
||||
menuItem.DropDownItems.Add(item);
|
||||
return info.FileWrapper.GetContextMenuItems();
|
||||
}
|
||||
|
||||
private void treeViewCustom1_MouseClick(object sender, TreeNodeMouseClickEventArgs e)
|
||||
@ -329,12 +365,17 @@ namespace Toolbox.Library.Forms
|
||||
if (e.Button == MouseButtons.Right)
|
||||
{
|
||||
treeNodeContextMenu.Items.Clear();
|
||||
|
||||
List<ToolStripItem> archiveMenus = new List<ToolStripItem>();
|
||||
List<ToolStripItem> menuItems = new List<ToolStripItem>();
|
||||
|
||||
if (e.Node.Tag != null && e.Node.Tag is ArchiveFileInfo)
|
||||
{
|
||||
//The tag gets set when an archive is replaced by a treenode
|
||||
//Todo store this in a better place as devs could possiblly replace this
|
||||
//Create menus when an archive node is replaced
|
||||
GetArchiveMenus(e.Node, (ArchiveFileInfo)e.Node.Tag);
|
||||
archiveMenus.AddRange(GetArchiveMenus(e.Node, (ArchiveFileInfo)e.Node.Tag));
|
||||
Console.WriteLine($"archiveMenus {archiveMenus.Count}");
|
||||
}
|
||||
|
||||
bool IsRoot = e.Node.Parent == null;
|
||||
@ -348,6 +389,7 @@ namespace Toolbox.Library.Forms
|
||||
node = (IContextMenuNode)e.Node.Tag;
|
||||
}
|
||||
|
||||
|
||||
if (node != null)
|
||||
{
|
||||
if (IsRoot)
|
||||
@ -355,13 +397,13 @@ namespace Toolbox.Library.Forms
|
||||
foreach (var item in node.GetContextMenuItems())
|
||||
{
|
||||
if (item.Text != "Delete" && item.Text != "Remove")
|
||||
treeNodeContextMenu.Items.Add(item);
|
||||
menuItems.Add(item);
|
||||
}
|
||||
treeNodeContextMenu.Items.Add(new ToolStripMenuItem("Delete", null, DeleteAction, Keys.Control | Keys.Delete));
|
||||
menuItems.Add(new ToolStripMenuItem("Delete", null, DeleteAction, Keys.Control | Keys.Delete));
|
||||
}
|
||||
else
|
||||
{
|
||||
treeNodeContextMenu.Items.AddRange(node.GetContextMenuItems());
|
||||
menuItems.AddRange(node.GetContextMenuItems());
|
||||
}
|
||||
|
||||
bool HasCollpase = false;
|
||||
@ -375,10 +417,21 @@ namespace Toolbox.Library.Forms
|
||||
}
|
||||
|
||||
if (!HasCollpase && HasChildren)
|
||||
treeNodeContextMenu.Items.Add(new ToolStripMenuItem("Collapse All", null, CollapseAllAction, Keys.Control | Keys.Q));
|
||||
menuItems.Add(new ToolStripMenuItem("Collapse All", null, CollapseAllAction, Keys.Control | Keys.Q));
|
||||
|
||||
if (!HasExpand && HasChildren)
|
||||
treeNodeContextMenu.Items.Add(new ToolStripMenuItem("Expand All", null, ExpandAllAction, Keys.Control | Keys.P));
|
||||
menuItems.Add(new ToolStripMenuItem("Expand All", null, ExpandAllAction, Keys.Control | Keys.P));
|
||||
|
||||
if (archiveMenus.Count > 0)
|
||||
{
|
||||
STToolStipMenuItem archiveItem = new STToolStipMenuItem("Archive");
|
||||
treeNodeContextMenu.Items.Add(archiveItem);
|
||||
|
||||
foreach (var item in archiveMenus)
|
||||
archiveItem.DropDownItems.Add(item);
|
||||
}
|
||||
|
||||
treeNodeContextMenu.Items.AddRange(menuItems.ToArray());
|
||||
|
||||
//Select the node without the evemt
|
||||
//We don't want editors displaying on only right clicking
|
||||
@ -386,7 +439,13 @@ namespace Toolbox.Library.Forms
|
||||
treeViewCustom1.SelectedNode = e.Node;
|
||||
SuppressAfterSelectEvent = false;
|
||||
}
|
||||
if (treeNodeContextMenu.Items.Count > 0)
|
||||
else
|
||||
{
|
||||
if (archiveMenus.Count > 0)
|
||||
treeNodeContextMenu.Items.AddRange(archiveMenus.ToArray());
|
||||
}
|
||||
|
||||
if (treeNodeContextMenu.Items.Count > 0)
|
||||
treeNodeContextMenu.Show(Cursor.Position);
|
||||
}
|
||||
else
|
||||
@ -966,6 +1025,12 @@ namespace Toolbox.Library.Forms
|
||||
((ExplorerFolder)e.Node).OnBeforeExpand();
|
||||
treeViewCustom1.EndUpdate();
|
||||
}
|
||||
else if (e.Node is TreeNodeCustom)
|
||||
{
|
||||
treeViewCustom1.BeginUpdate();
|
||||
((TreeNodeCustom)e.Node).OnExpand();
|
||||
treeViewCustom1.EndUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private void treeViewCustom1_AfterCollapse(object sender, TreeViewEventArgs e)
|
||||
|
Loading…
Reference in New Issue
Block a user