//================================================
 //  Copy Frame Info ~ Function
 //================================================
 private AnimatedFrameInfo CopyAnimFrameInfo(AnimatedFrameInfo CopySource, AnimatedFrameInfo TargetSource = null)
 {
     if (TargetSource == null)
     {
         TargetSource = new AnimatedFrameInfo();
     }
     foreach (SpriteInfo SprInfo in CopySource.m_SpriteInfoList)
     {
         SpriteInfo Sprite = new SpriteInfo();
         Sprite.ID          = SprInfo.ID;
         Sprite.X           = SprInfo.X;
         Sprite.Y           = SprInfo.Y;
         Sprite.W           = SprInfo.W;
         Sprite.H           = SprInfo.H;
         Sprite.Texture     = SprInfo.Texture;
         Sprite.TextureName = SprInfo.TextureName;
         Sprite.BlitRect    = SprInfo.BlitRect;
         TargetSource.m_SpriteInfoList.Add(Sprite);
     }
     TargetSource.m_bTintScreen                  = CopySource.m_bTintScreen;
     TargetSource.m_iTintScreenRed               = CopySource.m_iTintScreenRed;
     TargetSource.m_iTintScreenGreen             = CopySource.m_iTintScreenGreen;
     TargetSource.m_iTintScreenBlue              = CopySource.m_iTintScreenBlue;
     TargetSource.m_iTintScreenAlpha             = CopySource.m_iTintScreenAlpha;
     TargetSource.m_bTintCharacter               = CopySource.m_bTintCharacter;
     TargetSource.m_iTintCharacterRed            = CopySource.m_iTintCharacterRed;
     TargetSource.m_iTintCharacterGreen          = CopySource.m_iTintCharacterGreen;
     TargetSource.m_iTintCharacterBlue           = CopySource.m_iTintCharacterBlue;
     TargetSource.m_bAnimationPartiallyCompleted = CopySource.m_bAnimationPartiallyCompleted;
     return(TargetSource);
 }
        //====================================
        //  Reset Everything
        //====================================
        private bool ResetEverything()
        {
            string sWarning = "WARNING, by performing this action you will lose any unsaved progress, would you like to continue?";

            if (MessageBox.Show(sWarning, "Warning!", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                /////////////////////////////////
                m_AnimationFrameInfoList.Clear();
                AnimationFrames_Listview.Clear();
                /////////////////////////////////
                m_AnimationFrameInfoList.Add(new AnimatedFrameInfo());
                AnimationFrames_Listview.Items.Add("Frame01");
                /////////////////////////////////
                m_AnimFrameInfo_ClipboardCopy = new AnimatedFrameInfo();
                m_bMoveSpriteMode             = false;
                m_iCurrentFrameIndex          = 0;
                m_iCurrentlySelectedTextureID = -1;
                /////////////////////////////////
                return(true);
            }
            return(false);
        }
        //================================================
        //  Add Frame Button
        //================================================
        private void Add_Frame_Button_Click(object sender, EventArgs e)
        {
            int Count = AnimationFrames_Listview.Items.Count;

            AnimationFrames_Listview.Items.Add("Frame" + (Count + 1 < 10 ? "0" : "") + (Count + 1).ToString());

            // Create New Info Class, and fill it up with the same information as the previous Frame.
            AnimatedFrameInfo AnimFrameInfo = CopyAnimFrameInfo(m_AnimationFrameInfoList.ElementAt(m_iCurrentFrameIndex));

            // Increment Frame Index
            m_iCurrentFrameIndex++;

            // Deselect Any Textures
            m_iCurrentlySelectedTextureID = -1;

            // Make Selection Visible in the ListView
            AnimationFrames_Listview.Items[m_iCurrentFrameIndex].Selected = true;

            // Add New Info Class to the Correct Insertion Location
            m_AnimationFrameInfoList.Insert(m_iCurrentFrameIndex, AnimFrameInfo);


            // Modify Main Control Options to Show updated selection
            Tint_screen_Checkbox.Checked        = AnimFrameInfo.m_bTintScreen;
            TintScreenRed_numericUpDown.Value   = AnimFrameInfo.m_iTintScreenRed;
            TintScreenGreen_numericUpDown.Value = AnimFrameInfo.m_iTintScreenGreen;
            TintScreenBlue_numericUpDown.Value  = AnimFrameInfo.m_iTintScreenBlue;
            TintScreenAlpha_numericUpDown.Value = AnimFrameInfo.m_iTintScreenAlpha;

            TintCharacter_CheckBox.Checked         = AnimFrameInfo.m_bTintCharacter;
            TintCharacterRed_NumericUpDown.Value   = AnimFrameInfo.m_iTintCharacterRed;
            TintCharacterGreen_NumericUpDown.Value = AnimFrameInfo.m_iTintCharacterGreen;
            TintCharacterBlue_NumericUpDown.Value  = AnimFrameInfo.m_iTintCharacterBlue;

            Sounds_ComboBox.Text = AnimFrameInfo.m_sSoundFilename;
            Sounds_ComboBox.Text = Sounds_ComboBox.Text != "" ? Sounds_ComboBox.Text : "(No Sound)";
        }
Exemple #4
0
    public void ReadFromXML(string sFileName)
    {
        m_AnimFrameInfoList.Clear();
        m_AnimFrameInfoList = new List <AnimatedFrameInfo>();

        int iTotalFrames            = 0;
        int iPartialCompletionFrame = 0;
        int iCurrentFrameElement    = 1;

        System.Xml.XmlTextReader XmlReader = new System.Xml.XmlTextReader(sFileName);
        System.Xml.XmlNodeType   XmlType;


        while (XmlReader.Read())
        {
            XmlReader.ReadAttributeValue();
            XmlType = XmlReader.NodeType;


            if (XmlType == System.Xml.XmlNodeType.Element)
            {
                //===========================================
                //          Get Main Info
                //===========================================
                if (XmlReader.Name == "AnimationInfo")
                {
                    iTotalFrames            = Convert.ToInt32(XmlReader.GetAttribute("TotalFrames"));
                    iPartialCompletionFrame = Convert.ToInt32(XmlReader.GetAttribute("PartialAnimationCompletionFrame"));
                    m_bRelativeToScreen     = XmlReader.GetAttribute("RelativeToScreen") == "1";
                }

                //===========================================
                //          Get Frame Info
                //===========================================
                if (XmlReader.Name == "Frame" + iCurrentFrameElement.ToString())
                {
                    AnimatedFrameInfo AFI = new AnimatedFrameInfo();
                    AFI.m_bTintScreen      = XmlReader.GetAttribute("TintScreen") == "1";
                    AFI.m_iTintScreenRed   = Convert.ToInt32(XmlReader.GetAttribute("ScreenTintRed"));
                    AFI.m_iTintScreenGreen = Convert.ToInt32(XmlReader.GetAttribute("ScreenTintGreen"));
                    AFI.m_iTintScreenBlue  = Convert.ToInt32(XmlReader.GetAttribute("ScreenTintBlue"));
                    AFI.m_iTintScreenAlpha = Convert.ToInt32(XmlReader.GetAttribute("ScreenTintAlpha"));

                    AFI.m_bTintCharacter      = XmlReader.GetAttribute("TintCharacter") == "1";
                    AFI.m_iTintCharacterRed   = Convert.ToInt32(XmlReader.GetAttribute("CharacterTintRed"));
                    AFI.m_iTintCharacterGreen = Convert.ToInt32(XmlReader.GetAttribute("CharacterTintGreen"));
                    AFI.m_iTintCharacterBlue  = Convert.ToInt32(XmlReader.GetAttribute("CharacterTintBlue"));

                    AFI.m_iWaitTimeTillNextFrame = Convert.ToInt32(XmlReader.GetAttribute("WaitTillNextFrame"));
                    AFI.m_sSoundFilename         = XmlReader.GetAttribute("SoundFilename");

                    int iTotalSprites = Convert.ToInt32(XmlReader.GetAttribute("TotalSprites"));
                    for (int i = 0; i < iTotalSprites;)
                    {
                        XmlReader.Read();
                        if (XmlReader.Name == "Sprite" + (i + 1).ToString())
                        {
                            SpriteInfo SprInfo = new SpriteInfo();
                            SprInfo.ID          = (uint)AFI.m_SpriteInfoList.Count;
                            SprInfo.TextureName = XmlReader.GetAttribute("TextureName");
                            SprInfo.X           = Convert.ToInt32(XmlReader.GetAttribute("X"));
                            SprInfo.Y           = Convert.ToInt32(XmlReader.GetAttribute("Y"));
                            SprInfo.W           = Convert.ToInt32(XmlReader.GetAttribute("W"));
                            SprInfo.H           = Convert.ToInt32(XmlReader.GetAttribute("H"));

                            // Multiplying By 1000 Because the Game uses a float value of 0-1, whereas this program uses whole pixels.
                            // Therefore it is saved in game format, but when being read back into this program, the float is multiplied
                            // by 1000 to give an integer pass value, which is corrected by a SpriteChecker function outside of this class.
                            int RectX = (int)(Convert.ToDouble(XmlReader.GetAttribute("UVCoordStartX")) * 1000.0);
                            int RectY = (int)(Convert.ToDouble(XmlReader.GetAttribute("UVCoordStartY")) * 1000.0);
                            int RectW = (int)(Convert.ToDouble(XmlReader.GetAttribute("UVCoordEndX")) * 1000.0);
                            int RectH = (int)(Convert.ToDouble(XmlReader.GetAttribute("UVCoordEndY")) * 1000.0);
                            SprInfo.BlitRect = new Rectangle(RectX, RectY, RectW, RectH);

                            AFI.m_SpriteInfoList.Add(SprInfo);
                            i++;
                        }
                    }
                    m_AnimFrameInfoList.Add(AFI);
                    iCurrentFrameElement++;
                }
            }
        }

        //===========================================
        //          Finish Up
        //===========================================
        if ((iPartialCompletionFrame + 1) < m_AnimFrameInfoList.Count)
        {
            m_AnimFrameInfoList.ElementAt(iPartialCompletionFrame - 1).m_bAnimationPartiallyCompleted = true;
        }
        XmlReader.Close();
    }
Exemple #5
0
    //////////////////////////////////////////
    public void WriteToXML(List <AnimatedFrameInfo> AnimFrameInfoList, bool bRelativeToScreen)
    {
        //===========================================
        //          Get Save Location
        //===========================================
        SaveFileDialog SaveFD = new SaveFileDialog();

        SaveFD.Title    = "Select a Save Location";
        SaveFD.FileName = "";
        SaveFD.Filter   = "XML File (*.xml)|*.xml";
        if (SaveFD.ShowDialog() != System.Windows.Forms.DialogResult.OK)
        {
            return;
        }

        int iPartialCompletionFrame = 0;

        for (; iPartialCompletionFrame < AnimFrameInfoList.Count; iPartialCompletionFrame++)
        {
            if (AnimFrameInfoList.ElementAt(iPartialCompletionFrame).m_bAnimationPartiallyCompleted)
            {
                break;
            }
        }

        System.Xml.XmlTextWriter XmlWriter = new System.Xml.XmlTextWriter(SaveFD.FileName, null);
        XmlWriter.Formatting = System.Xml.Formatting.Indented;

        XmlWriter.WriteStartDocument();
        XmlWriter.WriteStartElement("Animation");
        //===========================================
        //          Write Frame Count
        //===========================================
        XmlWriter.WriteStartElement("AnimationInfo");
        XmlWriter.WriteStartAttribute("TotalFrames");
        XmlWriter.WriteString(AnimFrameInfoList.Count.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("PartialAnimationCompletionFrame");
        XmlWriter.WriteString(iPartialCompletionFrame.ToString());
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteStartAttribute("RelativeToScreen");
        XmlWriter.WriteString(bRelativeToScreen ? "1" : "0");
        XmlWriter.WriteEndAttribute();
        XmlWriter.WriteEndElement();
        //===========================================
        //          Write FrameInfo
        //===========================================
        for (int i = 0; i < AnimFrameInfoList.Count(); i++)
        {
            AnimatedFrameInfo AFI = AnimFrameInfoList.ElementAt(i);
            ///////////////////////////////////////////////////////
            XmlWriter.WriteStartElement("Frame" + (i + 1).ToString());
            XmlWriter.WriteStartAttribute("TotalSprites");
            XmlWriter.WriteString(AFI.m_SpriteInfoList.Count().ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("WaitTillNextFrame");
            XmlWriter.WriteString(AFI.m_iWaitTimeTillNextFrame.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("TintScreen");
            XmlWriter.WriteString(AFI.m_bTintScreen ? "1" : "0");
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintRed");
            XmlWriter.WriteString(AFI.m_iTintScreenRed.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintGreen");
            XmlWriter.WriteString(AFI.m_iTintScreenGreen.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintBlue");
            XmlWriter.WriteString(AFI.m_iTintScreenBlue.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("ScreenTintAlpha");
            XmlWriter.WriteString(AFI.m_iTintScreenAlpha.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("TintCharacter");
            XmlWriter.WriteString(AFI.m_bTintCharacter ? "1" : "0");
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("CharacterTintRed");
            XmlWriter.WriteString(AFI.m_iTintCharacterRed.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("CharacterTintGreen");
            XmlWriter.WriteString(AFI.m_iTintCharacterGreen.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("CharacterTintBlue");
            XmlWriter.WriteString(AFI.m_iTintCharacterBlue.ToString());
            XmlWriter.WriteEndAttribute();
            XmlWriter.WriteStartAttribute("SoundFilename");
            XmlWriter.WriteString(AFI.m_sSoundFilename);
            XmlWriter.WriteEndAttribute();

            //===========================================
            //          Write Sprite Info
            //===========================================
            for (int j = 0; j < AFI.m_SpriteInfoList.Count(); j++)
            {
                SpriteInfo Sprite = AFI.m_SpriteInfoList.ElementAt(j);
                //////////////////////////////////////////////////////
                XmlWriter.WriteStartElement("Sprite" + (j + 1).ToString());
                XmlWriter.WriteStartAttribute("TextureName");
                XmlWriter.WriteString(System.IO.Path.GetFileName(Sprite.TextureName));
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("X");
                XmlWriter.WriteString(Sprite.X.ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("Y");
                XmlWriter.WriteString(Sprite.Y.ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("W");
                XmlWriter.WriteString(Sprite.W.ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("H");
                XmlWriter.WriteString(Sprite.H.ToString());
                XmlWriter.WriteEndAttribute();
                ///////////////////////////////////////////////
                XmlWriter.WriteStartAttribute("UVCoordStartX");
                XmlWriter.WriteString(((float)Sprite.BlitRect.X / (float)Sprite.Texture.Width).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("UVCoordStartY");
                XmlWriter.WriteString(((float)Sprite.BlitRect.Y / (float)Sprite.Texture.Height).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("UVCoordEndX");
                XmlWriter.WriteString((((float)Sprite.BlitRect.X + (float)Sprite.BlitRect.Width) / (float)Sprite.Texture.Width).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteStartAttribute("UVCoordEndY");
                XmlWriter.WriteString((((float)Sprite.BlitRect.Y + (float)Sprite.BlitRect.Height) / (float)Sprite.Texture.Height).ToString());
                XmlWriter.WriteEndAttribute();
                XmlWriter.WriteEndElement();
            }
            XmlWriter.WriteEndElement();
        }
        //===========================================
        //          Finish Up
        //===========================================
        XmlWriter.WriteEndElement();     // Animation
        XmlWriter.WriteEndDocument();
        XmlWriter.Close();
    }
        private List <AnimatedFrameInfo> ConvertListValuesBetweenGameandEditor(List <AnimatedFrameInfo> AFIL, bool ConvertingtoGame = true, bool RelativeToScreen = false)
        {
            List <AnimatedFrameInfo> ReturnAFIL = new List <AnimatedFrameInfo>();

            foreach (AnimatedFrameInfo CopyAFI in AFIL)
            {
                AnimatedFrameInfo AFI = new AnimatedFrameInfo();
                AFI.m_bAnimationPartiallyCompleted = CopyAFI.m_bAnimationPartiallyCompleted;
                AFI.m_bTintScreen            = CopyAFI.m_bTintScreen;
                AFI.m_iTintScreenAlpha       = CopyAFI.m_iTintScreenAlpha;
                AFI.m_iTintScreenBlue        = CopyAFI.m_iTintScreenBlue;
                AFI.m_iTintScreenGreen       = CopyAFI.m_iTintScreenGreen;
                AFI.m_iTintScreenRed         = CopyAFI.m_iTintScreenRed;
                AFI.m_bTintCharacter         = CopyAFI.m_bTintCharacter;
                AFI.m_iTintCharacterBlue     = CopyAFI.m_iTintCharacterBlue;
                AFI.m_iTintCharacterGreen    = CopyAFI.m_iTintCharacterGreen;
                AFI.m_iTintCharacterRed      = CopyAFI.m_iTintCharacterRed;
                AFI.m_iWaitTimeTillNextFrame = CopyAFI.m_iWaitTimeTillNextFrame;
                AFI.m_sSoundFilename         = CopyAFI.m_sSoundFilename;
                foreach (SpriteInfo CopySprInfo in CopyAFI.m_SpriteInfoList)
                {
                    SpriteInfo SprInfo = new SpriteInfo();
                    if (!RelativeToScreen)
                    {
                        SprInfo.X = ConvertingtoGame ? CopySprInfo.X - m_EnemySprInfo.X : CopySprInfo.X + m_EnemySprInfo.X;
                        SprInfo.Y = ConvertingtoGame ? CopySprInfo.Y - m_EnemySprInfo.Y : CopySprInfo.Y + m_EnemySprInfo.Y;
                    }
                    else
                    {
                        SprInfo.X = CopySprInfo.X - m_EnemySprInfo.X;
                        SprInfo.Y = CopySprInfo.Y - m_EnemySprInfo.Y;
                    }
                    SprInfo.W           = CopySprInfo.W;
                    SprInfo.H           = CopySprInfo.H;
                    SprInfo.TextureName = CopySprInfo.TextureName;
                    SprInfo.Texture     = CopySprInfo.Texture;
                    SprInfo.ID          = CopySprInfo.ID;
                    SprInfo.BlitRect    = CopySprInfo.BlitRect;

                    // If Converting Back into Editor, changes need to be made to the Blitrect and an Image needs to passed in.
                    if (!ConvertingtoGame)
                    {
                        float BlitX = (float)((float)SprInfo.BlitRect.X * 0.001);
                        float BlitY = (float)((float)SprInfo.BlitRect.Y * 0.001);
                        float BlitW = (float)((float)SprInfo.BlitRect.Width * 0.001) - BlitX;
                        float BlitH = (float)((float)SprInfo.BlitRect.Height * 0.001) - BlitY;

                        // Attempt to Get Texture IF there is None
                        if (SprInfo.Texture == null)
                        {
                            SprInfo.Texture = GetImageFromList("./Images/" + SprInfo.TextureName);
                        }
                        if (SprInfo.Texture != null)
                        {
                            SprInfo.BlitRect.X      = (int)(BlitX * SprInfo.Texture.Width);
                            SprInfo.BlitRect.Y      = (int)(BlitY * SprInfo.Texture.Height);
                            SprInfo.BlitRect.Width  = (int)(BlitW * SprInfo.Texture.Width);
                            SprInfo.BlitRect.Height = (int)(BlitH * SprInfo.Texture.Height);
                        }
                    }
                    AFI.m_SpriteInfoList.Add(SprInfo);
                }
                ReturnAFIL.Add(AFI);
            }


            // Another Conversion Between the Game and this Editor.
            // The game skips the first frame due to the way the Update and Draw functions are set up,
            // so we add in a new frame to the first element before saving.
            // When returning we simply remove that element.
            if (ConvertingtoGame)
            {
                ReturnAFIL.Insert(0, new AnimatedFrameInfo());
            }
            else
            {
                ReturnAFIL.RemoveAt(0);
            }
            return(ReturnAFIL);
        }