From b5ba944b69efed81a18bb7515ef3b76fde0d1b02 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Fri, 23 Nov 2018 15:39:16 -0500 Subject: [PATCH] Cleanup and some optimizations --- Switch_FileFormatsMain/FileFormats/BFRES.cs | 71 ++++++++++--------- .../FileFormats/BFRES/Bfres Structs/FBNV.cs | 63 +++++++++++++++- .../FileFormats/BFRES/Bfres Structs/FMAA.cs | 36 ++++++++++ .../FileFormats/BFRES/Bfres Structs/FMAT.cs | 14 +++- .../FileFormats/BFRES/Bfres Structs/FMDL.cs | 2 +- .../FileFormats/BFRES/Bfres Structs/FSCN.cs | 11 ++- .../FileFormats/BFRES/Bfres Structs/FSHA.cs | 66 ++++++++++++++++- .../FileFormats/BFRES/Bfres Structs/FSHP.cs | 17 ++++- .../FileFormats/BFRES/Bfres Structs/FSKA.cs | 11 ++- .../FileFormats/BFRES/Bfres Structs/FSKL.cs | 2 +- .../BFRES/Bfres Structs/ResourceFile.cs | 4 +- .../FileFormats/BFRES/BfresSwitch.cs | 39 ++++++++-- .../FileFormats/Texture/BNTX.cs | 31 +++----- Switch_FileFormatsMain/GUI/FormLoader.cs | 18 ----- Switch_Toolbox_Library/GUI.cs | 12 ++-- 15 files changed, 296 insertions(+), 101 deletions(-) diff --git a/Switch_FileFormatsMain/FileFormats/BFRES.cs b/Switch_FileFormatsMain/FileFormats/BFRES.cs index c1ca82f4..7f31a0ad 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES.cs @@ -147,43 +147,44 @@ namespace FirstPlugin { var resFile = bfres.ResFileNode.resFile; - int CurMdl = 0; - foreach (FMDL model in bfres.models) - { - resFile.Models[CurMdl].Shapes.Clear(); - resFile.Models[CurMdl].VertexBuffers.Clear(); - resFile.Models[CurMdl].Materials.Clear(); - - int i = 0; - var duplicates = model.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c); - foreach (var shape in duplicates) - shape.Text += i++; - - foreach (FSHP shape in model.shapes) - { - CheckMissingTextures(shape); - BfresSwitch.SetShape(shape, shape.Shape); - - resFile.Models[CurMdl].Shapes.Add(shape.Shape); - resFile.Models[CurMdl].VertexBuffers.Add(shape.VertexBuffer); - shape.Shape.VertexBufferIndex = (ushort)(resFile.Models[CurMdl].VertexBuffers.Count - 1); - - SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape); - } - foreach (FMAT mat in model.materials.Values) - { - BfresSwitch.SetMaterial(mat, mat.Material); - resFile.Models[CurMdl].Materials.Add(mat.Material); - } - CurMdl++; - } + resFile.Models.Clear(); resFile.SkeletalAnims.Clear(); + resFile.MaterialAnims.Clear(); + resFile.SceneAnims.Clear(); + resFile.ShapeAnims.Clear(); + resFile.BoneVisibilityAnims.Clear(); + + + int CurMdl = 0; + if (EditorRoot.Nodes.ContainsKey("FMDL")) + { + foreach (FMDL model in EditorRoot.Nodes["FMDL"].Nodes) + resFile.Models.Add(BfresSwitch.SetModel(model)); + } if (EditorRoot.Nodes.ContainsKey("FSKA")) { foreach (BfresSkeletonAnim ska in EditorRoot.Nodes["FSKA"].Nodes) - { resFile.SkeletalAnims.Add(ska.SkeletalAnim); - } + } + if (EditorRoot.Nodes.ContainsKey("FMAA")) + { + foreach (FMAA fmaa in EditorRoot.Nodes["FMAA"].Nodes) + resFile.MaterialAnims.Add(fmaa.MaterialAnim); + } + if (EditorRoot.Nodes.ContainsKey("FBNV")) + { + foreach (FBNV fbnv in EditorRoot.Nodes["FBNV"].Nodes) + resFile.BoneVisibilityAnims.Add(fbnv.VisibilityAnim); + } + if (EditorRoot.Nodes.ContainsKey("FSHPA")) + { + foreach (FSHA fsha in EditorRoot.Nodes["FSHPA"].Nodes) + resFile.ShapeAnims.Add(fsha.ShapeAnim); + } + if (EditorRoot.Nodes.ContainsKey("FSCN")) + { + foreach (FSCN fscn in EditorRoot.Nodes["FSCN"].Nodes) + resFile.SceneAnims.Add(fscn.SceneAnim); } ErrorCheck(); @@ -229,7 +230,7 @@ namespace FirstPlugin } } - private void SetShaderAssignAttributes(FMAT.ShaderAssign shd, FSHP shape) + public static void SetShaderAssignAttributes(FMAT.ShaderAssign shd, FSHP shape) { foreach (var att in shape.vertexAttributes) { @@ -259,9 +260,9 @@ namespace FirstPlugin } } - bool ImportMissingTextures = false; - private void CheckMissingTextures(FSHP shape) + public static void CheckMissingTextures(FSHP shape) { + bool ImportMissingTextures = false; foreach (BinaryTextureContainer bntx in PluginRuntime.bntxContainers) { foreach (MatTexture tex in shape.GetMaterial().textures) diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs index 956505fb..871183bb 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FBNV.cs @@ -2,7 +2,7 @@ using Switch_Toolbox.Library; using System.Windows.Forms; using FirstPlugin; - +using Syroot.NintenTools.NSW.Bfres; namespace Bfres.Structs { @@ -30,7 +30,16 @@ namespace Bfres.Structs } public void ExportAll(object sender, EventArgs args) { - + FolderSelectDialog sfd = new FolderSelectDialog(); + if (sfd.ShowDialog() == DialogResult.OK) + { + string folderPath = sfd.SelectedPath; + foreach (FBNV fbnv in Nodes) + { + string FileName = folderPath + '\\' + fbnv.Text + ".bfska"; + ((FBNV)fbnv).VisibilityAnim.Export(FileName, fbnv.GetResFile()); + } + } } public void Clear(object sender, EventArgs args) { @@ -47,4 +56,54 @@ namespace Bfres.Structs FormLoader.LoadEditor(this, Text); } } + public class FBNV : TreeNodeCustom + { + public VisibilityAnim VisibilityAnim; + public FBNV() + { + ImageKey = "visibilityAnim"; + SelectedImageKey = "visibilityAnim"; + + ContextMenu = new ContextMenu(); + MenuItem export = new MenuItem("Export"); + ContextMenu.MenuItems.Add(export); + export.Click += Export; + MenuItem replace = new MenuItem("Replace"); + ContextMenu.MenuItems.Add(replace); + replace.Click += Replace; + } + + public ResFile GetResFile() + { + return ((ResourceFile)Parent.Parent).resFile; + } + + private void Export(object sender, EventArgs args) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "Supported Formats|*.bfvis;"; + sfd.FileName = Text; + sfd.DefaultExt = ".bfvis"; + + if (sfd.ShowDialog() == DialogResult.OK) + { + VisibilityAnim.Export(sfd.FileName, GetResFile()); + } + } + private void Replace(object sender, EventArgs args) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "Supported Formats|*.bfvis;"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + VisibilityAnim.Import(ofd.FileName); + } + VisibilityAnim.Name = Text; + } + public void Read(VisibilityAnim vis) + { + VisibilityAnim = vis; + } + } } diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs index d1c451e9..ed98d9df 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAA.cs @@ -59,6 +59,19 @@ namespace Bfres.Structs { public BFRESRender BFRESRender; public MaterialAnim MaterialAnim; + public FMAA() + { + ImageKey = "materialAnim"; + SelectedImageKey = "materialAnim"; + + ContextMenu = new ContextMenu(); + MenuItem export = new MenuItem("Export"); + ContextMenu.MenuItems.Add(export); + export.Click += Export; + MenuItem replace = new MenuItem("Replace"); + ContextMenu.MenuItems.Add(replace); + replace.Click += Replace; + } public ResFile GetResFile() { @@ -68,5 +81,28 @@ namespace Bfres.Structs { MaterialAnim = anim; } + private void Export(object sender, EventArgs args) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "Supported Formats|*.bfmaa;"; + sfd.FileName = Text; + sfd.DefaultExt = ".bfska"; + + if (sfd.ShowDialog() == DialogResult.OK) + { + MaterialAnim.Export(sfd.FileName, GetResFile()); + } + } + private void Replace(object sender, EventArgs args) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "Supported Formats|*.bfmaa;"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + MaterialAnim.Import(ofd.FileName); + } + MaterialAnim.Name = Text; + } } } diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs index 0328e698..84a9e0df 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMAT.cs @@ -69,7 +69,19 @@ namespace Bfres.Structs public override void OnClick(TreeView treeView) { - FormLoader.LoadMatEditor(this); + UpdateFMATEditor(); + } + public void UpdateFMATEditor() + { + FMATEditor docked = (FMATEditor)LibraryGUI.Instance.GetContentDocked(new FMATEditor()); + if (docked == null) + { + docked = new FMATEditor(); + LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState); + } + docked.Text = Text; + docked.Dock = DockStyle.Fill; + docked.LoadMaterial(this); } public ResFile GetResFile() { diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs index 008fa761..96189abc 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FMDL.cs @@ -18,7 +18,7 @@ namespace Bfres.Structs public FmdlFolder() { Text = "Models"; - Name = "FMDLFolder"; + Name = "FMDL"; ContextMenu = new ContextMenu(); MenuItem import = new MenuItem("Import"); diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs index dfbb9b67..6bfd2ccb 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSCN.cs @@ -30,7 +30,16 @@ namespace Bfres.Structs } private void ExportAll(object sender, EventArgs args) { - + FolderSelectDialog sfd = new FolderSelectDialog(); + if (sfd.ShowDialog() == DialogResult.OK) + { + string folderPath = sfd.SelectedPath; + foreach (FSCN fscn in Nodes) + { + string FileName = folderPath + '\\' + fscn.Text + ".bfscn"; + ((FSCN)fscn).SceneAnim.Export(FileName, fscn.GetResFile()); + } + } } private void Clear(object sender, EventArgs args) { diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs index cd423a38..8dd6ba25 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHA.cs @@ -2,6 +2,7 @@ using System.Windows.Forms; using Switch_Toolbox.Library; using FirstPlugin; +using Syroot.NintenTools.NSW.Bfres; namespace Bfres.Structs { @@ -27,13 +28,22 @@ namespace Bfres.Structs { } - private void ExportAll(object sender, EventArgs args) + public void ExportAll(object sender, EventArgs args) { - + FolderSelectDialog sfd = new FolderSelectDialog(); + if (sfd.ShowDialog() == DialogResult.OK) + { + string folderPath = sfd.SelectedPath; + foreach (FSHA fsha in Nodes) + { + string FileName = folderPath + '\\' + fsha.Text + ".bfshpa"; + ((FSHA)fsha).ShapeAnim.Export(FileName, fsha.GetResFile()); + } + } } private void Clear(object sender, EventArgs args) { - DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all objects? This cannot be undone!", "", MessageBoxButtons.YesNo); + DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove all shape animations? This cannot be undone!", "", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { @@ -45,4 +55,54 @@ namespace Bfres.Structs FormLoader.LoadEditor(this, Text); } } + public class FSHA : TreeNodeCustom + { + public ShapeAnim ShapeAnim; + public FSHA() + { + ImageKey = "shapeAnimation"; + SelectedImageKey = "shapeAnimation"; + + ContextMenu = new ContextMenu(); + MenuItem export = new MenuItem("Export"); + ContextMenu.MenuItems.Add(export); + export.Click += Export; + MenuItem replace = new MenuItem("Replace"); + ContextMenu.MenuItems.Add(replace); + replace.Click += Replace; + } + + public ResFile GetResFile() + { + return ((ResourceFile)Parent.Parent).resFile; + } + + private void Export(object sender, EventArgs args) + { + SaveFileDialog sfd = new SaveFileDialog(); + sfd.Filter = "Supported Formats|*.bfshpa;"; + sfd.FileName = Text; + sfd.DefaultExt = ".bfshpa"; + + if (sfd.ShowDialog() == DialogResult.OK) + { + ShapeAnim.Export(sfd.FileName, GetResFile()); + } + } + private void Replace(object sender, EventArgs args) + { + OpenFileDialog ofd = new OpenFileDialog(); + ofd.Filter = "Supported Formats|*.bfshpa;"; + + if (ofd.ShowDialog() == DialogResult.OK) + { + ShapeAnim.Import(ofd.FileName); + } + ShapeAnim.Name = Text; + } + public void Read(ShapeAnim shapeAnim) + { + ShapeAnim = shapeAnim; + } + } } diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs index b9aa775e..fefc4bf4 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSHP.cs @@ -134,7 +134,6 @@ namespace Bfres.Structs ContextMenu.MenuItems.Add(rename); rename.Click += Rename; } - public FMATEditor editor; public int ModelIndex; //For getting the model the shape is in public VertexBuffer VertexBuffer; @@ -171,7 +170,19 @@ namespace Bfres.Structs public override void OnClick(TreeView treeView) { - FormLoader.LoadShapeEditor(this); + UpdateFSHPEditor(); + } + public void UpdateFSHPEditor() + { + FSHPEditor docked = (FSHPEditor)LibraryGUI.Instance.GetContentDocked(new FSHPEditor()); + if (docked == null) + { + docked = new FSHPEditor(); + LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState); + } + docked.Text = Text; + docked.Dock = DockStyle.Fill; + docked.LoadObject((FMDL)Parent.Parent, this); } private void SmoothNormals(object sender, EventArgs args) { @@ -288,7 +299,7 @@ namespace Bfres.Structs } private void OpenMaterialEditor(object sender, EventArgs args) { - FormLoader.LoadMatEditor(GetMaterial()); + GetMaterial().UpdateFMATEditor(); } private void CalcTansBitans(object sender, EventArgs args) { diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs index 933788bf..bcfe9d62 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKA.cs @@ -33,7 +33,16 @@ namespace Bfres.Structs } public void ExportAll(object sender, EventArgs args) { - + FolderSelectDialog sfd = new FolderSelectDialog(); + if (sfd.ShowDialog() == DialogResult.OK) + { + string folderPath = sfd.SelectedPath; + foreach (BfresSkeletonAnim fska in Nodes) + { + string FileName = folderPath + '\\' + fska.Text + ".bfska"; + ((BfresSkeletonAnim)fska).SkeletalAnim.Export(FileName, fska.GetResFile()); + } + } } private void Clear(object sender, EventArgs args) { diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs index 7db3dd58..b9d7b51a 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/FSKL.cs @@ -71,7 +71,7 @@ namespace Bfres.Structs { node = new fsklNode(); node.Skeleton = skl; - BfresSwitch.SetSkeleton(node, skl, this); + BfresSwitch.ReadSkeleton(node, skl, this); } public FSKL(ResU.Skeleton skl) { diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs index 04a541fc..23119210 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/Bfres Structs/ResourceFile.cs @@ -107,9 +107,9 @@ namespace Bfres.Structs public override void OnClick(TreeView treeView) { //If has models - if (Nodes.ContainsKey("FMDLFolder")) + if (Nodes.ContainsKey("FMDL")) { - if (Nodes["FMDLFolder"].Nodes.ContainsKey("FshpFolder")) + if (Nodes["FMDL"].Nodes.ContainsKey("FshpFolder")) { } diff --git a/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs b/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs index 011782b5..93da7558 100644 --- a/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs +++ b/Switch_FileFormatsMain/FileFormats/BFRES/BfresSwitch.cs @@ -17,6 +17,36 @@ namespace FirstPlugin { public static class BfresSwitch { + public static Model SetModel(FMDL fmdl) + { + Model model = new Model(); + + int i = 0; + var duplicates = fmdl.shapes.GroupBy(c => c.Text).Where(g => g.Skip(1).Any()).SelectMany(c => c); + foreach (var shape in duplicates) + shape.Text += i++; + + foreach (FSHP shape in fmdl.shapes) + { + BFRES.CheckMissingTextures(shape); + SetShape(shape, shape.Shape); + + model.Shapes.Add(shape.Shape); + model.VertexBuffers.Add(shape.VertexBuffer); + + shape.Shape.VertexBufferIndex = (ushort)(model.VertexBuffers.Count - 1); + + BFRES.SetShaderAssignAttributes(shape.GetMaterial().shaderassign, shape); + } + foreach (FMAT mat in fmdl.materials.Values) + { + SetMaterial(mat, mat.Material); + model.Materials.Add(mat.Material); + } + + + return model; + } public static void Read(BFRESRender renderer, ResFile resFile, TreeNode ResFileNode) { int CurMdl = 0; @@ -119,7 +149,6 @@ namespace FirstPlugin } return Shape; } - public static void ReadShapesVertices(FSHP fshp, Shape shp, VertexBuffer vertexBuffer, FMDL model) { fshp.boundingBoxes.Clear(); @@ -448,8 +477,7 @@ namespace FirstPlugin } return curve; } - - public static void SetSkeleton(this TreeNodeCustom skl, Skeleton skeleton, FSKL RenderableSkeleton) + public static void ReadSkeleton(this TreeNodeCustom skl, Skeleton skeleton, FSKL RenderableSkeleton) { if (skeleton.MatrixToBoneList == null) skeleton.MatrixToBoneList = new List(); @@ -465,7 +493,7 @@ namespace FirstPlugin foreach (Bone bone in skeleton.Bones) { BfresBone STBone = new BfresBone(RenderableSkeleton); - SetBone(STBone, bone); + ReadBone(STBone, bone); RenderableSkeleton.bones.Add(STBone); } RenderableSkeleton.update(); @@ -477,7 +505,7 @@ namespace FirstPlugin Runtime.abstractGlDrawables.Add(RenderableSkeleton); } - public static void SetBone(this BfresBone bone, Bone bn) + public static void ReadBone(this BfresBone bone, Bone bn) { bone.Bone = bn; bone.Text = bn.Name; @@ -928,7 +956,6 @@ namespace FirstPlugin mat.ShaderAssign.AttribAssigns.Add(att.Value); } } - public static void WriteExternalFiles(ResFile resFile, TreeNode EditorRoot) { resFile.ExternalFiles.Clear(); diff --git a/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs b/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs index 48cca70d..237b8996 100644 --- a/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs +++ b/Switch_FileFormatsMain/FileFormats/Texture/BNTX.cs @@ -727,30 +727,20 @@ namespace FirstPlugin } public override void OnClick(TreeView treeView) { - if (LibraryGUI.Instance.dockContent != null && !EditorIsActive(LibraryGUI.Instance.dockContent)) - { - BNTXEditor BNTXEditor = new BNTXEditor(); - BNTXEditor.Text = Text; - BNTXEditor.Dock = DockStyle.Fill; - BNTXEditor.LoadProperty(this); - LibraryGUI.Instance.LoadDockContent(BNTXEditor, PluginRuntime.FSHPDockState); - } + UpdateBNTXEditor(); } - public bool EditorIsActive(DockContent dock) + public void UpdateBNTXEditor() { - foreach (Control ctrl in dock.Controls) + BNTXEditor docked = (BNTXEditor)LibraryGUI.Instance.GetContentDocked(new BNTXEditor()); + if (docked == null) { - if (ctrl is BNTXEditor) - { - dock.Text = Text; - ((BNTXEditor)ctrl).LoadProperty(this); - return true; - } + docked = new BNTXEditor(); + LibraryGUI.Instance.LoadDockContent(docked, PluginRuntime.FSHPDockState); } - - return false; + docked.Text = Text; + docked.Dock = DockStyle.Fill; + docked.LoadProperty(this); } - public BRTI_Texture LoadOpenGLTexture() { if (OpenTKSharedResources.SetupStatus == OpenTKSharedResources.SharedResourceStatus.Unitialized) @@ -1121,8 +1111,7 @@ namespace FirstPlugin } Texture.Name = Text; UpdateBfresTextureMapping(); - - //LibraryGUI.Instance.LoadDockContent(BNTXEditor); + UpdateBNTXEditor(); } } private void UpdateBfresTextureMapping() diff --git a/Switch_FileFormatsMain/GUI/FormLoader.cs b/Switch_FileFormatsMain/GUI/FormLoader.cs index e814fb29..0ab93019 100644 --- a/Switch_FileFormatsMain/GUI/FormLoader.cs +++ b/Switch_FileFormatsMain/GUI/FormLoader.cs @@ -69,23 +69,5 @@ namespace FirstPlugin } return false; } - - public static void LoadMatEditor(FMAT mat) - { - FMATEditor editor = new FMATEditor(); - editor.Text = mat.Text; - editor.Dock = DockStyle.Fill; - editor.LoadMaterial(mat); - LibraryGUI.Instance.LoadDockContent(editor, PluginRuntime.FSHPDockState); - } - - public static void LoadShapeEditor(FSHP fshp) - { - FSHPEditor BfresProperties = new FSHPEditor(); - BfresProperties.Text = fshp.Text; - BfresProperties.Dock = DockStyle.Fill; - BfresProperties.LoadObject((FMDL)fshp.Parent.Parent, fshp); - LibraryGUI.Instance.LoadDockContent(BfresProperties, PluginRuntime.FSHPDockState); - } } } diff --git a/Switch_Toolbox_Library/GUI.cs b/Switch_Toolbox_Library/GUI.cs index 93ca255a..38d08bae 100644 --- a/Switch_Toolbox_Library/GUI.cs +++ b/Switch_Toolbox_Library/GUI.cs @@ -29,12 +29,12 @@ namespace Switch_Toolbox.Library } public UserControl GetContentDocked(UserControl control) { - foreach (DockContent dockContent in dockPanel.Contents) - { - foreach (Control ctrl in dockContent.Controls) - if (ctrl.GetType() == control.GetType()) - return (UserControl)ctrl; - } + if (dockContent == null) + return null; + + foreach (Control ctrl in dockContent.Controls) + if (ctrl.GetType() == control.GetType()) + return (UserControl)ctrl; return null; } public DockContent GetContentDocked(DockContent DockContent)