From bffa623e01105c6acd4c029f28c972bfe5c5b960 Mon Sep 17 00:00:00 2001 From: KillzXGaming Date: Sat, 15 Feb 2020 18:24:35 -0500 Subject: [PATCH] Some quick bone index fixes --- .../BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs | 23 +++++---- .../Forms/Color/VertexColorBox.cs | 49 +++++++++++++++++++ 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs index 958fec8d..adad631b 100644 --- a/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs +++ b/File_Format_Library/FileFormats/BFRES/Bfres Structs/SubFiles/FMDL/FSHP.cs @@ -994,16 +994,21 @@ namespace Bfres.Structs bool UseRigidSkinning = ob.VertexSkinCount == 1; + if (mdl.Skeleton.Node_Array == null || mdl.Skeleton.Node_Array.Length == 0) + return; + var bones = new Dictionary(); - foreach (var bone in mdl.Skeleton.bones) - { - if (bones.ContainsKey(bone.Text)) - { - STConsole.WriteLine($"There are multiple bones named {bone.Text}. Using the first one.", System.Drawing.Color.Red); - } - else - { - bones.Add(bone.Text, bone); + foreach (var index in mdl.Skeleton.Node_Array) { + if (index < mdl.Skeleton.bones.Count) { + var bone = mdl.Skeleton.bones[index]; + if (bones.ContainsKey(bone.Text)) + { + STConsole.WriteLine($"There are multiple bones named {bone.Text}. Using the first one.", System.Drawing.Color.Red); + } + else + { + bones.Add(bone.Text, bone); + } } } diff --git a/Switch_Toolbox_Library/Forms/Color/VertexColorBox.cs b/Switch_Toolbox_Library/Forms/Color/VertexColorBox.cs index 480fe4fa..77f8731e 100644 --- a/Switch_Toolbox_Library/Forms/Color/VertexColorBox.cs +++ b/Switch_Toolbox_Library/Forms/Color/VertexColorBox.cs @@ -87,6 +87,8 @@ namespace Toolbox.Library.Forms this.BackgroundImage = Properties.Resources.CheckerBackground; this.BackColor = Color.Transparent; this.MouseClick += OnMouseClick; + this.MouseUp += OnMouseUp; + this.MouseHover += new EventHandler(OnMouseHover); this.SetStyle( ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | @@ -103,14 +105,33 @@ namespace Toolbox.Library.Forms } } + + private void OnMouseHover(object sender, EventArgs e) + { + isHovered = true; + mouseLoc = Control.MousePosition; + this.Invalidate(); + } + + private void OnMouseUp(object sender, MouseEventArgs e) { + leftClicked = false; + } + + private bool isHovered; private bool dialogActive; private STColorDialog colorDlg; + private Point mouseLoc; + private bool leftClicked = false; private void OnMouseClick(object sender, MouseEventArgs e) { if (TopLeftHit == null) return; if (e.Button == MouseButtons.Left) { + leftClicked = true; + mouseLoc = e.Location; + this.Invalidate(); + if (TopLeftHit.IsHit(e.Location)) LoadColorDialog(TopLeftColor, 0); if (TopRightHit.IsHit(e.Location)) @@ -156,6 +177,8 @@ namespace Toolbox.Library.Forms ColorChanged(); }; } + + leftClicked = false; } this.Invalidate(); @@ -357,7 +380,33 @@ namespace Toolbox.Library.Forms using (Brush br = new SolidBrush(BottomRightColor.GrayScale(true).Inverse())) pe.Graphics.DrawString("BR", font, br, new Point(RightX, BottomY)); + if (mouseLoc != null) + { + if (AllHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, AllHit); + if (TopLeftHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, TopLeftHit); + if (TopRightHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, TopRightHit); + if (BottomLeftHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, BottomLeftHit); + if (BottomRightHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, BottomRightHit); + if (TopHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, TopHit); + if (BottomHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, BottomHit); + if (RightHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, RightHit); + if (LeftHit.IsHit(mouseLoc)) + DrawSelectionOutline(pe, LeftHit); + } + base.OnPaint(pe); } + + private void DrawSelectionOutline(PaintEventArgs pe, Rectangle rect) { + pe.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black), 1), rect); + } } }