/// <summary>
 /// User clicked on a different SPR2 or DGRP chunk.
 /// </summary>
 private void LstSPR2s_SelectedValueChanged(object sender, EventArgs e)
 {
     if (RdiSPR.Checked)
     {
         m_CurrentSPR = m_CurrentArchive.SPRs[LstSPR2s.SelectedIndex];
         PictCurrentFrame.Image = m_CurrentSPR.GetFrame(0).BitmapData.BitMap;
         m_CurrentSPRFrame = 0;
     }
     else if (RdiSpr2.Checked)
     {
         m_CurrentSPR2 = m_CurrentArchive.SPR2s[LstSPR2s.SelectedIndex];
         PictCurrentFrame.Image = m_CurrentSPR2.GetFrame(0).BitmapData.BitMap;
         m_CurrentSPR2Frame = 0;
     }
     else if(RdiDgrp.Checked)
     {
         m_CurrentGroup = m_CurrentArchive.DrawGroups[LstSPR2s.SelectedIndex];
         PictCurrentFrame.Image = m_CurrentGroup.GetImage(0).CompiledBitmap;
         m_CurrentGroupFrame = 0;
     }
 }
        /// <summary>
        /// User clicked on the button to view the next frame in a SPR2 or DGRP chunk.
        /// </summary>
        private void BtnNextFrame_Click(object sender, EventArgs e)
        {
            if (m_CurrentArchive != null)
            {
                if (RdiSPR.Checked)
                {
                    m_CurrentSPRFrame++;

                    if (m_CurrentArchive.SPRs.Count > 0)
                    {
                        if (m_CurrentSPRFrame < m_CurrentSPR.FrameCount)
                        {
                            if (m_CurrentSPR.FrameCount > 0)
                                PictCurrentFrame.Image = m_CurrentSPR.GetFrame(m_CurrentSPRFrame).BitmapData.BitMap;
                            else if (m_CurrentSPR2Frame < 0)
                                m_CurrentSPRFrame = 0;
                        }
                        else if (m_CurrentSPRFrame > m_CurrentSPR.FrameCount)
                            m_CurrentSPRFrame = (int)m_CurrentSPR.FrameCount - 1;
                    }
                }
                else if (RdiSpr2.Checked)
                {
                    m_CurrentSPR2Frame++;

                    if (!ChkZBuffer.Checked)
                    {
                        if (m_CurrentArchive.SPR2s.Count > 0)
                        {
                            if (m_CurrentSPR2Frame < m_CurrentSPR2.FrameCount)
                            {
                                if (m_CurrentSPR2.FrameCount > 0)
                                    PictCurrentFrame.Image = m_CurrentSPR2.GetFrame(m_CurrentSPR2Frame).BitmapData.BitMap;
                                else if (m_CurrentSPR2Frame < 0)
                                    m_CurrentSPR2Frame = 0;
                            }
                            else if (m_CurrentSPR2Frame < 0)
                                m_CurrentSPR2Frame = 0;
                            else if (m_CurrentSPR2Frame > m_CurrentSPR2.FrameCount)
                                m_CurrentSPR2Frame = (int)m_CurrentSPR2.FrameCount - 1;
                        }
                    }
                    else
                    {
                        if (m_CurrentArchive.SPR2s.Count > 0)
                        {
                            if (m_CurrentSPR2Frame < m_CurrentSPR2.FrameCount)
                            {
                                if (m_CurrentSPR2.FrameCount > 0)
                                {
                                    if(m_CurrentSPR2.GetFrame(m_CurrentSPR2Frame).HasZBuffer)
                                        PictCurrentFrame.Image = m_CurrentSPR2.GetFrame(m_CurrentSPR2Frame).ZBuffer.BitMap;
                                    else
                                        PictCurrentFrame.Image = m_CurrentSPR2.GetFrame(m_CurrentSPR2Frame).BitmapData.BitMap;
                                }
                                else if (m_CurrentSPR2Frame < 0)
                                    m_CurrentSPR2Frame = 0;
                            }
                            else if (m_CurrentSPR2Frame < 0)
                                m_CurrentSPR2Frame = 0;
                            else if (m_CurrentSPR2Frame > m_CurrentSPR2.FrameCount)
                                m_CurrentSPR2Frame = (int)m_CurrentSPR2.FrameCount - 1;
                        }
                    }
                }
                else if (RdiDgrp.Checked)
                {
                    m_CurrentGroupFrame++;

                    if (m_CurrentArchive.DrawGroups.Count > 0)
                    {
                        if (m_CurrentGroup == null)
                        {
                            if (LstSPR2s.SelectedIndex < m_CurrentArchive.DrawGroups.Count)
                                m_CurrentGroup = m_CurrentArchive.DrawGroups[LstSPR2s.SelectedIndex];
                            else
                                m_CurrentGroup = m_CurrentArchive.DrawGroups[m_CurrentArchive.DrawGroups.Count - 1];
                        }

                        if (m_CurrentGroupFrame < m_CurrentGroup.ImageCount && m_CurrentGroup.ImageCount > 0)
                            PictCurrentFrame.Image = m_CurrentGroup.GetImage(m_CurrentGroupFrame).CompiledBitmap;
                        else if (m_CurrentGroupFrame < 0)
                            m_CurrentGroupFrame = 0;
                    }
                    else if (m_CurrentGroupFrame < 0)
                        m_CurrentGroupFrame = 0;
                    else if (m_CurrentGroupFrame > m_CurrentGroup.ImageCount)
                        m_CurrentGroupFrame = (int)m_CurrentGroup.ImageCount - 1;
                }
            }
        }
        /// <summary>
        /// User clicked on the list of sprites.
        /// </summary>
        private void LstSPR2s_Click(object sender, EventArgs e)
        {
            if (m_CurrentArchive != null)
            {
                if (RdiSPR.Checked)
                {
                    string Caption = (string)LstSPR2s.SelectedItem;
                    int ID = 0;
                    string Name = "";

                    if (Caption.Contains("ID: "))
                        ID = int.Parse(Caption.Replace("ID: ", ""));
                    else
                        Name = Caption.Replace("Name: ", "");

                    foreach (SPRParser Sprite in m_CurrentArchive.SPRs)
                    {
                        if (ID != 0)
                        {
                            if (Sprite.ID == ID)
                            {
                                m_CurrentSPR = Sprite;
                                PictCurrentFrame.Image = m_CurrentSPR.GetFrame(m_CurrentSPR2Frame).BitmapData.BitMap;
                                break;
                            }
                        }
                        else
                        {
                            if (Sprite.NameString == Name)
                            {
                                m_CurrentSPR = Sprite;
                                PictCurrentFrame.Image = m_CurrentSPR.GetFrame(m_CurrentSPR2Frame).BitmapData.BitMap;
                                break;
                            }
                        }
                    }
                }
                else if (RdiSpr2.Checked)
                {
                    string Caption = (string)LstSPR2s.SelectedItem;
                    int ID = 0;
                    string Name = "";

                    if (Caption.Contains("ID: "))
                        ID = int.Parse(Caption.Replace("ID: ", ""));
                    else
                        Name = Caption.Replace("Name: ", "");

                    foreach (SPR2Parser Sprite in m_CurrentArchive.SPR2s)
                    {
                        if (ID != 0)
                        {
                            if (Sprite.ID == ID)
                            {
                                m_CurrentSPR2 = Sprite;
                                PictCurrentFrame.Image = m_CurrentSPR2.GetFrame(m_CurrentSPR2Frame).BitmapData.BitMap;
                                break;
                            }
                        }
                        else
                        {
                            if (Sprite.NameString == Name)
                            {
                                m_CurrentSPR2 = Sprite;
                                PictCurrentFrame.Image = m_CurrentSPR2.GetFrame(m_CurrentSPR2Frame).BitmapData.BitMap;
                                break;
                            }
                        }
                    }
                }
                else if (RdiStr.Checked)
                {
                    if (m_CurrentArchive.StringTables.Count > 0)
                    {
                        string Str = (string)LstSPR2s.SelectedItem;
                        Str = Str.Replace("String: ", "");
                        Str = Str.Replace("String2: ", "");

                        MessageBox.Show(Str);
                    }
                }
                else if (RdiBhavs.Checked)
                {
                    if (m_CurrentArchive.BHAVs.Count > 0)
                    {
                        BHAVEdit Editor = new BHAVEdit(m_CurrentArchive, m_CurrentArchive.BHAVs[LstSPR2s.SelectedIndex]);
                        Editor.Show();
                    }
                }
                else if (RdiDgrp.Checked)
                {
                    string Caption = (string)LstSPR2s.SelectedItem;
                    int ID = 0;
                    string Name = "";

                    if (Caption.Contains("ID: "))
                        ID = int.Parse(Caption.Replace("ID: ", ""));
                    else
                        Name = Caption.Replace("Name: ", "");

                    foreach (DrawGroup DGRP in m_CurrentArchive.DrawGroups)
                    {
                        if (ID != 0)
                        {
                            if (DGRP.ID == ID)
                            {
                                m_CurrentGroup = DGRP;
                                if (m_CurrentGroupFrame < m_CurrentGroup.ImageCount)
                                    PictCurrentFrame.Image = m_CurrentGroup.GetImage(m_CurrentGroupFrame).CompiledBitmap;
                                else
                                {
                                    m_CurrentGroupFrame = m_CurrentGroup.ImageCount - 1;
                                    PictCurrentFrame.Image = m_CurrentGroup.GetImage(m_CurrentGroupFrame).CompiledBitmap;
                                }
                                break;
                            }
                        }
                        else
                        {
                            if (DGRP.NameString == Name)
                            {
                                m_CurrentGroup = DGRP;
                                if (m_CurrentGroupFrame < m_CurrentGroup.ImageCount)
                                    PictCurrentFrame.Image = m_CurrentGroup.GetImage(m_CurrentGroupFrame).CompiledBitmap;
                                else
                                {
                                    m_CurrentGroupFrame = m_CurrentGroup.ImageCount - 1;
                                    PictCurrentFrame.Image = m_CurrentGroup.GetImage(m_CurrentGroupFrame).CompiledBitmap;
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }