示例#1
0
        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
        private void button1_Click(object sender, EventArgs e)
        {
            Animations anim = new Animations();

            lAnimations.Add(anim);

            listBox1.Items.Clear();
            listBox1.SelectedIndex = listBox1.Items.Count - 1;

            int num = 0;

            foreach (Animations curranim in lAnimations)
            {
                curranim.Ordernumber = num;
                listBox1.Items.Add(curranim);
                num += 1;
            }

            listBox2.ClearSelected();
            listBox2.Items.Clear();
            listBox1.Invalidate();
            listBox2.Invalidate();
        }