using System; using System.Collections.Generic; using System.Windows.Forms; using Toolbox.Library.NodeWrappers; using Toolbox.Library.Animations; using Toolbox.Library.Forms; using Toolbox.Library; using ResU = Syroot.NintenTools.Bfres; using ResNX = Syroot.NintenTools.NSW.Bfres; using FirstPlugin; namespace Bfres.Structs { public class BFRESAnimFolder : STGenericWrapper, IContextMenuNode { public BFRESAnimFolder() { Text = "Animations"; } public bool IsWiiU { get; set; } public override void OnClick(TreeView treeview) { if (Parent is BFRES) ((BFRES)Parent).LoadEditors(this); else if (Parent.Parent is BFRES) { ((BFRES)Parent.Parent).LoadEditors(this); } else { ((BFRES)Parent.Parent.Parent).LoadEditors(this); } } public ResNX.ResFile GetResFile() { return ((BFRES)Parent).resFile; } public ResU.ResFile GetResFileU() { return ((BFRES)Parent).resFileU; } public void AddNode(BFRESGroupNode node) { Nodes.Add(node); } public void LoadMenus(bool isWiiUBfres) { IsWiiU = isWiiUBfres; } public ToolStripItem[] GetContextMenuItems() { List Items = new List(); Items.Add(new ToolStripMenuItem("New", null, new ToolStripMenuItem("Skeletal Animation", null, NewSkeletalAnimAction), new ToolStripMenuItem("Shader Param Animation", null, NewShaderParamAnimAction), new ToolStripMenuItem("Color Animation", null, NewColorAnimAction), new ToolStripMenuItem("Texture SRT Animations", null, NewTexSrtAnimAction), new ToolStripMenuItem("Texture Pattern Animation", null, NewTexPatAnimAction), new ToolStripMenuItem("Bone Visibility Animation", null, NewBoneVisAnimAction), new ToolStripMenuItem("Material Visibility Animation", null, NewMatVisAnimAction), new ToolStripMenuItem("Shape Animation", null, NewShapeAnimAction), new ToolStripMenuItem("Scene Animation", null, NewSceneAnimAction) )); Items.Add(new ToolStripMenuItem("Import", null, new ToolStripMenuItem("Skeletal Animation", null, ImportSkeletalAnimAction), new ToolStripMenuItem("Shader Param Animation", null, ImportShaderParamAnimAction), new ToolStripMenuItem("Color Animation", null, ImportColorAnimAction), new ToolStripMenuItem("Texture SRT Animations", null, ImportTexSrtAnimAction), new ToolStripMenuItem("Texture Pattern Animation", null, ImportTexPatAnimAction), new ToolStripMenuItem("Bone Visibility Animation", null, ImportBoneVisAnimAction), new ToolStripMenuItem("Material Visibility Animation", null, ImportMatVisAnimAction), new ToolStripMenuItem("Shape Animation", null, ImportShapeAnimAction), new ToolStripMenuItem("Scene Animation", null, ImportSceneAnimAction) )); Items.Add(new ToolStripMenuItem("Clear", null, ClearAction, Keys.Control | Keys.C)); return Items.ToArray(); } protected void NewSkeletalAnimAction(object sender, EventArgs e) { NewSkeletalAnim(); } protected void NewShaderParamAnimAction(object sender, EventArgs e) { NewShaderParamAnim(); } protected void NewColorAnimAction(object sender, EventArgs e) { NewColorAnim(); } protected void NewTexSrtAnimAction(object sender, EventArgs e) { NewTexSrtAnim(); } protected void NewTexPatAnimAction(object sender, EventArgs e) { NewTexPatAnim(); } protected void NewBoneVisAnimAction(object sender, EventArgs e) { NewBoneVisAnim(); } protected void NewMatVisAnimAction(object sender, EventArgs e) { NewMatVisAnim(); } protected void NewShapeAnimAction(object sender, EventArgs e) { NewShapeAnim(); } protected void NewSceneAnimAction(object sender, EventArgs e) { NewSceneAnim(); } protected void ImportSkeletalAnimAction(object sender, EventArgs e) { ImportSkeletalAnim(); } protected void ImportShaderParamAnimAction(object sender, EventArgs e) { ImportShaderParamAnim(); } protected void ImportColorAnimAction(object sender, EventArgs e) { ImportColorAnim(); } protected void ImportTexSrtAnimAction(object sender, EventArgs e) { ImportTexSrtAnim(); } protected void ImportTexPatAnimAction(object sender, EventArgs e) { ImportTexPatAnim(); } protected void ImportBoneVisAnimAction(object sender, EventArgs e) { ImportBoneVisAnim(); } protected void ImportMatVisAnimAction(object sender, EventArgs e) { ImportMatVisAnim(); } protected void ImportShapeAnimAction(object sender, EventArgs e) { ImportShapeAnim(); } protected void ImportSceneAnimAction(object sender, EventArgs e) { ImportSceneAnim(); } public void ImportSkeletalAnim() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileFilters.FSKA_REPLACE; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = GetOrCreateFolder(); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportShaderParamAnim() { OpenFileDialog ofd = new OpenFileDialog(); if (IsWiiU) ofd.Filter = FileFilters.GetFilter(typeof(FSHU), MaterialAnimation.AnimationType.ShaderParam); else ofd.Filter = FileFilters.FMAA; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = null; if (IsWiiU) group = GetOrCreateFolder(MaterialAnimation.AnimationType.ShaderParam); else group = GetOrCreateFolder(MaterialAnimation.AnimationType.ShaderParam); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportColorAnim() { OpenFileDialog ofd = new OpenFileDialog(); if (IsWiiU) ofd.Filter = FileFilters.GetFilter(typeof(FSHU), MaterialAnimation.AnimationType.Color); else ofd.Filter = FileFilters.FMAA; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = null; if (IsWiiU) group = GetOrCreateFolder(MaterialAnimation.AnimationType.Color); else group = GetOrCreateFolder(MaterialAnimation.AnimationType.Color); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportTexSrtAnim() { OpenFileDialog ofd = new OpenFileDialog(); if (IsWiiU) ofd.Filter = FileFilters.GetFilter(typeof(FSHU), MaterialAnimation.AnimationType.TextureSrt); else ofd.Filter = FileFilters.FMAA; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = null; if (IsWiiU) group = GetOrCreateFolder(MaterialAnimation.AnimationType.TextureSrt); else group = GetOrCreateFolder(MaterialAnimation.AnimationType.TextureSrt); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportTexPatAnim() { OpenFileDialog ofd = new OpenFileDialog(); if (IsWiiU) ofd.Filter = FileFilters.FTXP; else ofd.Filter = FileFilters.FMAA; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = null; if (IsWiiU) group = GetOrCreateFolder(); else group = GetOrCreateFolder(MaterialAnimation.AnimationType.TexturePattern); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportBoneVisAnim() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileFilters.FBNV; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = GetOrCreateFolder(VisibiltyAnimType.Bone); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportMatVisAnim() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileFilters.FBNV; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = null; if (IsWiiU) group = GetOrCreateFolder(VisibiltyAnimType.Material); else group = GetOrCreateFolder(MaterialAnimation.AnimationType.Visibilty); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportSceneAnim() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileFilters.FSCN; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = GetOrCreateFolder(); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void ImportShapeAnim() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = FileFilters.FSHA; ofd.Multiselect = true; if (ofd.ShowDialog() != DialogResult.OK) return; BFRESGroupNode group = GetOrCreateFolder(); group.Import(ofd.FileNames, GetResFile(), GetResFileU()); AddFolder(group); } public void NewSkeletalAnim() { BFRESGroupNode group = GetOrCreateFolder(); FSKA anim = null; if (IsWiiU) anim = new FSKA(new ResU.SkeletalAnim()); else anim = new FSKA(new ResNX.SkeletalAnim()); group.AddNode(anim, "NewSkeletalAnim"); AddFolder(group); } public void NewShaderParamAnim() { var type = MaterialAnimation.AnimationType.ShaderParam; BFRESGroupNode group = null; if (IsWiiU) { group = GetOrCreateFolder(type); FSHU fshu = new FSHU(new ResU.ShaderParamAnim(), type); group.AddNode(fshu, "NewShaderParamAnim_fsp"); } else { group = GetOrCreateFolder(type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); group.AddNode(fmaa, "NewShaderParamAnim_fsp"); } AddFolder(group); } public void NewColorAnim() { var type = MaterialAnimation.AnimationType.Color; BFRESGroupNode group = null; if (IsWiiU) { group = GetOrCreateFolder(type); FSHU fshu = new FSHU(new ResU.ShaderParamAnim(), type); group.AddNode(fshu, "NewColorAnim_fcl"); } else { group = GetOrCreateFolder(type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); group.AddNode(fmaa, "NewColorAnim_fcl"); } AddFolder(group); } public void NewTexSrtAnim() { var type = MaterialAnimation.AnimationType.TextureSrt; BFRESGroupNode group = null; if (IsWiiU) { group = GetOrCreateFolder(type); FSHU fshu = new FSHU(new ResU.ShaderParamAnim(), type); group.AddNode(fshu, "NewTextureTransformAnim_fts"); } else { group = GetOrCreateFolder(type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); group.AddNode(fmaa, "NewTextureTransformAnim_fts"); } AddFolder(group); } public void NewTexPatAnim() { var type = MaterialAnimation.AnimationType.TexturePattern; BFRESGroupNode group = null; if (IsWiiU) { group = GetOrCreateFolder(); FTXP anim = new FTXP(new ResU.TexPatternAnim()); group.AddNode(anim, "NewTexturePatternAnim_ftp"); } else { group = GetOrCreateFolder(type); FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), type); group.AddNode(fmaa, "NewTexturePatternAnim_ftp"); } AddFolder(group); } public void NewBoneVisAnim() { BFRESGroupNode group = GetOrCreateFolder(VisibiltyAnimType.Bone); FVIS anim = null; if (IsWiiU) { anim = new FVIS(new ResU.VisibilityAnim() { Type = ResU.VisibilityAnimType.Bone }); } else { anim = new FVIS(new ResNX.VisibilityAnim()); } group.AddNode(anim, "NewBoneVisAnim"); AddFolder(group); } public void NewMatVisAnim() { BFRESGroupNode group = null; if (IsWiiU) { group = GetOrCreateFolder(VisibiltyAnimType.Material); FVIS anim = new FVIS(new ResU.VisibilityAnim() { Type = ResU.VisibilityAnimType.Material }); group.AddNode(anim, "NewMatVisAnim_fvm"); } else { group = GetOrCreateFolder(MaterialAnimation.AnimationType.Visibilty); FMAA fmaa = new FMAA(new ResNX.MaterialAnim(), MaterialAnimation.AnimationType.Visibilty); group.AddNode(fmaa, "NewMatVisAnim_fvm"); } AddFolder(group); } public void NewShapeAnim() { BFRESGroupNode group = GetOrCreateFolder(); FSHA anim = null; if (IsWiiU) anim = new FSHA(new ResU.ShapeAnim()); else anim = new FSHA(new ResNX.ShapeAnim()); group.AddNode(anim, "NewShapeAnim"); AddFolder(group); } public void NewSceneAnim() { BFRESGroupNode group = GetOrCreateFolder(); FSCN fshu = null; if (IsWiiU) fshu = new FSCN(new ResU.SceneAnim()); else fshu = new FSCN(new ResNX.SceneAnim()); group.AddNode(fshu, "NewSceneVisAnim"); AddFolder(group); } private void AddFolder(BFRESGroupNode group) { if (!Nodes.Contains(group)) Nodes.Add(group); } public BFRESGroupNode GetOrCreateFolder(object CheckAnimEffect = null) where T : STGenericWrapper { BFRESGroupNode group = new BFRESGroupNode(IsWiiU); if (typeof(T) == typeof(FSKA)) { group.Type = BRESGroupType.SkeletalAnim; } if (typeof(T) == typeof(FMAA)) { group.Type = BRESGroupType.MaterialAnim; } if (typeof(T) == typeof(FSHU)) { group.Type = BRESGroupType.ShaderParamAnim; } if (typeof(T) == typeof(FVIS)) { group.Type = BRESGroupType.BoneVisAnim; } if (typeof(T) == typeof(FSHA)) { group.Type = BRESGroupType.ShapeAnim; } if (typeof(T) == typeof(FSCN)) { group.Type = BRESGroupType.SceneAnim; } if (typeof(T) == typeof(FTXP)) { group.Type = BRESGroupType.TexPatAnim; } if (CheckAnimEffect != null) { if (CheckAnimEffect is MaterialAnimation.AnimationType) { var type = (MaterialAnimation.AnimationType)CheckAnimEffect; if (type == MaterialAnimation.AnimationType.Color) { group.Type = BRESGroupType.ColorAnim; } if (type == MaterialAnimation.AnimationType.TextureSrt) { group.Type = BRESGroupType.TexSrtAnim; } if (type == MaterialAnimation.AnimationType.ShaderParam) { group.Type = BRESGroupType.ShaderParamAnim; } if (type == MaterialAnimation.AnimationType.TexturePattern) { group.Type = BRESGroupType.TexPatAnim; } if (type == MaterialAnimation.AnimationType.Visibilty) { group.Type = BRESGroupType.MatVisAnim; } } if (CheckAnimEffect is VisibiltyAnimType) { var type = (VisibiltyAnimType)CheckAnimEffect; if (type == VisibiltyAnimType.Bone) { group.Type = BRESGroupType.BoneVisAnim; } if (type == VisibiltyAnimType.Material) { group.Type = BRESGroupType.MatVisAnim; } } } group.SetNameByType(); foreach (BFRESGroupNode node in Nodes) { if (node.Type == group.Type) return node; } return group; } } }