예제 #1
0
파일: Form1.cs 프로젝트: CSPshala/BeatWars
        private void laodAnimationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "All Files(*.*)|*.*|XML Files(*.xml)|*.xml";
            dlg.FilterIndex = 2;
            dlg.DefaultExt = "xml";

            if( dlg.ShowDialog() == DialogResult.OK)
            {

                XElement root = XElement.Load(dlg.FileName);

                IEnumerable<XElement> animations = root.Elements("Animation");

                if (animations != null)
                {
                    lAnimations.Clear();
                    int last = -1;

                    foreach (XElement X in animations)
                    {
                        XAttribute A;
                        Animations anim = new Animations();
                        last = lAnimations.Count;

                        //name
                        A = X.Attribute("Name");
                        anim.Name = Convert.ToString(A.Value);

                        //file
                        A = X.Attribute("File");
                        texture = Convert.ToString(A.Value);

                        nID = TextureManager.LoadTexture(texture,0);
                        if (nID == -1)
                        {
                            OpenFileDialog opdlg = new OpenFileDialog();

                            if (DialogResult.OK == opdlg.ShowDialog())
                            {
                                nID = TextureManager.LoadTexture(opdlg.FileName.ToString(), 0);

                                Size nSize = new Size(TextureManager.GetTextureWidth(nID), TextureManager.GetTextureHeight(nID));

                                texture = opdlg.FileName;

                                panel1.Size = nSize;
                            }
                        }

                        anim.Ordernumber = last;

                        IEnumerable<XElement> frames = X.Elements("Frames");

                        if (frames != null)
                        {
                            int framenumber = -1;

                            foreach (XElement Z in frames)
                            {
                                if (anim.lFrames == null)
                                {
                                    anim.lFrames = new List<Frame>();
                                }

                                framenumber += 1;
                                XAttribute B;
                                Frame frame = new Frame();

                                frame.FrameNumber = framenumber;

                                //Duration
                                B = Z.Attribute("Duration");
                                frame.Duration = ((float)Convert.ToDecimal(B.Value)) * 1000;

                                fDuration = frame.Duration;

                                //FrameY
                                B = Z.Attribute("FrameY");
                                frame.DrawY = Convert.ToInt32(B.Value);
                                dY = frame.DrawY;

                                //FrameX
                                B = Z.Attribute("FrameX");
                                frame.DrawX = Convert.ToInt32(B.Value);
                                dX = frame.DrawX;

                                //AnchorY
                                B = Z.Attribute("AnchorY");
                                frame.AnchorY = Convert.ToInt32(B.Value) + frame.DrawY;
                                anchorY = frame.AnchorY + frame.DrawY;

                                //AnchorX
                                B = Z.Attribute("AnchorX");
                                frame.AnchorX = Convert.ToInt32(B.Value) + frame.DrawX;
                                anchorX = frame.AnchorX + frame.DrawX;

                                //Width
                                B = Z.Attribute("Width");
                                frame.DrawWidth = Convert.ToInt32(B.Value);
                                dWidth = frame.DrawWidth;

                                //Height
                                B = Z.Attribute("Height");
                                frame.DrawHeight = Convert.ToInt32(B.Value);
                                dHeight = frame.DrawHeight;

                                //Event
                                //B = Z.Attribute("Event");
                                //frame.TriggerEvent = Convert.ToString(B.Value);
                                //textBox1.Text = frame.TriggerEvent;

                                //CollisionHeigh
                                B = Z.Attribute("CollisionHeight");
                                frame.CollisionHeight = Convert.ToInt32(B.Value);
                                cHeight = frame.CollisionHeight;

                                //CollisionWidth
                                B = Z.Attribute("CollisionWidth");
                                frame.CollisionWidth = Convert.ToInt32(B.Value);
                                cWidth = frame.CollisionWidth;

                                //CollisionFrameX
                                B = Z.Attribute("CollisionFrameX");
                                frame.CollisionX = Convert.ToInt32(B.Value);
                                cX = frame.CollisionX;

                                //CollisionFrameY
                                B = Z.Attribute("CollisionFrameY");
                                frame.CollisionY = Convert.ToInt32(B.Value);
                                cY = frame.CollisionY;

                                anim.lFrames.Add(frame);
                                listBox2.Items.Add(anim.lFrames[framenumber]);

                            }

                        }
                            lAnimations.Add(anim);
                            listBox1.Items.Add(lAnimations[last]);

                    }

                }

            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: CSPshala/BeatWars
        private void button2_Click(object sender, EventArgs e)
        {
            if(listBox1.SelectedIndex > -1)
            {
                if (textBox2.Text == "")
                {
                    if (MessageBox.Show("The Animation has no name. Please name the Animation.") == DialogResult.OK)
                    {

                    }
                }
                else
                {
                    Frame newFrame = new Frame();

                    if (lAnimations[listBox1.SelectedIndex].lFrames == null)
                        lAnimations[listBox1.SelectedIndex].lFrames = new List<Frame>();

                    lAnimations[listBox1.SelectedIndex].lFrames.Add(newFrame);

                    listBox2.Items.Clear();

                    int num = 0;

                    foreach (Frame f in lAnimations[listBox1.SelectedIndex].lFrames)
                    {
                        f.FrameNumber = num;
                        f.Duration = fDuration;
                        listBox2.Items.Add(f);
                        num += 1;
                    }

                    listBox2.SelectedIndex = listBox2.Items.Count - 1;
                    listBox2.Invalidate();
                }
            }
        }