//Constructor for Existing animation
 public EditAnimationWindow(List<BinaryTexture> binaryTextures, List<string> animationNames, Animation animation)
 {
     InitializeComponent();
     _animationNames = animationNames;
     ReturnAnimation = animation;
     _binaryTextures = binaryTextures;
 }
 private void AddTextureToList(Texture2D texture)
 {
     AddTextureLabelToList(texture.Name);
     Game.gameGraphics.textureManager.Textures.Add(texture.Name, texture);
     Animation textureAnimation = new Animation(texture.Name, texture.Name, 0, 1, 1, new Vector2(0,0), new Vector2(0,0),1, new Collidable());
     textureAnimation.AddFrame(new Frame(new GameRectangle(0, 0, texture.Width, texture.Height)));
     Game.gameGraphics.AddDrawable(textureAnimation);
 }
示例#3
0
 /*
 public Animation CloneAnimation(string name)
 {
     return new Animation(name, GetTextureData(), framecount, Rotation, Scale, Depth, GetPosition(), GetOrigin(), FramesPerSecond);
 }
  */
 public Animation CloneAnimation(string name)
 {
     Animation returnAnimation = new Animation(name, Texture, Rotation, Scale, Depth, GetPosition(), GetOrigin(), FramesPerSecond);
     foreach (KeyValuePair<int, Frame> pair in Frames)
     {
         returnAnimation.AddFrame(pair.Value);
     }
     returnAnimation.IsLoop = IsLoop;
     return returnAnimation;
 }
 //Set text boxes to Animation properties
 private void SetAnimationFields(Animation animation)
 {
     txtBox_AnimationName.Text = animation.Name;
     txtBox_Depth.Text = animation.Depth.ToString();
     txtBox_Scale.Text = animation.Scale.ToString();
     txtBox_Speed.Text = animation.FramesPerSecond.ToString();
     txtBox_DefaultHeight.Text = animation.DefaultHeight.ToString();
     txtBox_DefaultWidth.Text = animation.DefaultWidth.ToString();
     if (animation.FrameCount <= 0) return;
     for (int i = 1; i <= animation.FrameCount; i++)
     {
         listBox_Frames.Items.Add(i);
     }
     lbl_CurrentFrameCount.Text = animation.FrameCount.ToString();
 }
        //Have to start a game on the OnShown event, do a bunch of game stuff while we're at it.
        public void OnShown_Window(object sender, EventArgs e)
        {
            if (_binaryTextures.Count <= 0)
            {
                MessageBox.Show("You must load sprite sheets before creating an animation", "No sprite sheets",
                    MessageBoxButtons.OK);
                Close();
                DialogResult = DialogResult.Cancel;
                return;
            }
            DialogResult = DialogResult.Cancel;
            DisableFrameButtons();
            panel_XNA.Controls.Add(pictureBox_TextureDisplay);
            panel_FrameDisplay.Controls.Add(pictureBox_FrameDisplay);
            string textureName = "";
            panel_XNA.AutoScroll = true;

            _textureGame = new TextureGame(pictureBox_TextureDisplay.Handle, this, pictureBox_TextureDisplay, new Vector2(pictureBox_TextureDisplay.Width, pictureBox_TextureDisplay.Height), lbl_MouseState);
            textureManager = new GraphicsManager(_textureGame.gameGraphics);

            _textureGame.gameForm.GotFocus += delegate(object o, EventArgs args)
            {
                this.Focus();
            };
            if (NewAnimation)
            {
                NewNameWindow newAnimationNameWindow = new NewNameWindow(_animationNames, "Animation");
                newAnimationNameWindow.FormClosed += delegate(object o, FormClosedEventArgs args)
                {
                    switch (newAnimationNameWindow.DialogResult)
                    {
                        case DialogResult.OK:
                            ReturnAnimation = new Animation(newAnimationNameWindow.ReturnName, "", 0, 1, 1, Vector2.Zero,
                                Vector2.Zero, 1, new CollisionEngineLib.Objects.Collidable(0,0,0,0,false));
                            txtBox_AnimationName.Text = ReturnAnimation.Name;
                            SetAnimationFields(ReturnAnimation);
                            originalName = newAnimationNameWindow.ReturnName;
                            return;
                        case DialogResult.Cancel:
                            DialogResult = DialogResult.Cancel;
                            return;
                        default:
                            return;
                    }
                };
                newAnimationNameWindow.ShowDialog();
                if (newAnimationNameWindow.DialogResult == DialogResult.Cancel)
                {
                    DialogResult = DialogResult.Cancel;
                    Close();
                    return;
                }
                List<string> textureNames = _binaryTextures.Select(texture => texture.Name).ToList();

                SetSpriteSheetWindow setTextureWindow = new SetSpriteSheetWindow(textureNames);
                switch (setTextureWindow.ShowDialog())
                {
                    case DialogResult.OK:
                        textureName = setTextureWindow.SelectedTexture;
                        ReturnAnimation.Texture = textureName;
                        break;
                    case DialogResult.Cancel:
                        DialogResult = DialogResult.Cancel;
                        Close();
                        return;
                }
                DialogResult = DialogResult.OK;
            }
            else
            {
                BinaryTexture texture = _binaryTextures.FirstOrDefault(t => t.Name == ReturnAnimation.Texture);
                if (texture == null)
                {
                    switch(MessageBox.Show("Sprite sheet is invalid, please choose a new spritesheet", "Invalid SpriteSheet", MessageBoxButtons.OKCancel))
                    {
                        case DialogResult.OK:
                            List<string> textureNames = _binaryTextures.Select(txt => txt.Name).ToList();
                            SetSpriteSheetWindow setSpriteSheet = new SetSpriteSheetWindow(textureNames);
                            switch (setSpriteSheet.ShowDialog())
                            {
                                case DialogResult.OK:
                                    ReturnAnimation.Texture = setSpriteSheet.SelectedTexture;
                                    break;
                                case DialogResult.Cancel:
                                    DialogResult = DialogResult.Cancel;
                                    Close();
                                    return;
                            }
                            break;
                        case DialogResult.Cancel:
                            DialogResult = DialogResult.Cancel;
                            Close();
                            return;
                    }

                }
                originalName = ReturnAnimation.Name;
            }
            SetAnimationFields(ReturnAnimation);
            _textureGame.gameGraphics.GraphicsManager.DeviceCreated += delegate(object o, EventArgs args)
            {
                foreach (BinaryTexture texture in _binaryTextures)
                {
                    _textureGame.gameGraphics.textureManager.Textures.Add(texture.Name, TextureManager.ConvertDataToTexture(texture, _textureGame.gameGraphics.GraphicsManager.GraphicsDevice));
                    Animation textureAnimation = new Animation(texture.Name, texture.Name, 0, 1, 1, new Vector2(0, 0), new Vector2(0, 0), 1, new CollisionEngineLib.Objects.Collidable(0,0,1,1, true));
                    textureAnimation.AddFrame(new Frame(new GameRectangle(0, 0, texture.Width, texture.Height)));
                    _textureGame.gameGraphics.AddDrawable(textureAnimation);
                }
                _textureGame.gameGraphics.AddToDrawList(new DrawParam(CurrentTextureAnimationName, ReturnAnimation.Texture, Vector2.Zero, DrawnType.Animation));

                BinaryTexture animationTexture = _binaryTextures.FirstOrDefault(t => t.Name == ReturnAnimation.Texture);
                if (animationTexture != null)
                {
                    if (animationTexture.Height > panel_XNA.Height || animationTexture.Width > panel_XNA.Width)
                    {
                        panel_XNA.AutoScrollMinSize = new Size(animationTexture.Width, animationTexture.Height);
                        pictureBox_TextureDisplay.Location = new System.Drawing.Point(0, 0);
                    }
                }

                DrawnRectangle frameRectangle = new DrawnRectangle
                {
                    Name = FrameRectangleName,
                    X = 0,
                    Y = 0,
                    Size = new Size(0, 0),
                    Thickness = 1,
                    Color = GameGraphics.ConvertSystemColorToXNA(System.Drawing.Color.Fuchsia)
                };
                _textureGame.gameGraphics.AddDrawable(frameRectangle);
                _textureGame.gameGraphics.AddToDrawList(new DrawParam(FrameRectangleName, FrameRectangleName,new Vector2(frameRectangle.X, frameRectangle.Y), DrawnType.Shape));
                MakeTextureLoopFrame(CurrentTextureAnimationName);
                SetAnimationTexture(textureName);
            };
            //TODO: This is here to prevent _textueGame from malfunctioning when tabbing through text fields. Not sure why, probably should look at that later.
            SendKeys.Send("{TAB}");

             _textureGame.Run();
        }
 public PreviewAnimationWindow(Animation animation, BinaryTexture texture)
 {
     InitializeComponent();
     previewAnimation = animation;
     animationTexture = texture;
 }
        private void OnShown(object sender, EventArgs e)
        {
            panel_SpriteSheetPreview.AutoScroll = true;

            this.Game = new TextureGame(this.pictureBox_SpriteSheetPreview.Handle, this, this.pictureBox_SpriteSheetPreview, new Vector2(this.pictureBox_SpriteSheetPreview.Width, this.pictureBox_SpriteSheetPreview.Height), lbl_MouseState);
            graphicsManager = new GraphicsManager(Game.gameGraphics);

            pictureBox_SpriteSheetPreview.Width = Game.gameGraphics.GraphicsManager.PreferredBackBufferWidth;
            pictureBox_SpriteSheetPreview.Height = Game.gameGraphics.GraphicsManager.PreferredBackBufferHeight;

            Game.gameForm.GotFocus += delegate(object o, EventArgs args)
            {
                this.Focus();
            };
            Game.gameGraphics.GraphicsManager.DeviceCreated += delegate(object o, EventArgs args)
            {
                foreach (KeyValuePair<string, BinaryTexture> pair in ReturnTextures)
                {
                    Game.gameGraphics.textureManager.Textures.Add(pair.Key, TextureManager.ConvertDataToTexture(pair.Value, Game.gameGraphics.GraphicsManager.GraphicsDevice));
                    AddTextureLabelToList(pair.Value.Name);
                    Animation textureAnimation = new Animation(pair.Value.Name, pair.Value.Name, 0, 1, 1, new Vector2(0, 0), new Vector2(0, 0), 1, new Collidable(0,0,0,0, false));
                    textureAnimation.AddFrame(new Frame(new GameRectangle(0, 0, pair.Value.Width, pair.Value.Height)));
                    Game.gameGraphics.AddDrawable(textureAnimation);
                }
            };
            this.Game.Run();
        }
 private void btn_New_Click(object sender, EventArgs e)
 {
     OpenFileDialog getImage = new OpenFileDialog();
     getImage.Filter = "PNG Files (.png)| *.png|All Files (*.*)| *.*";
     DialogResult result = getImage.ShowDialog();
     switch (result)
     {
         case DialogResult.OK:
             Texture2D newTexture = Game.gameGraphics.LoadTexture(getImage.FileName);
             if (newTexture != null)
             {
                 List<string> textureNames = Game.gameGraphics.textureManager.Textures.Keys.ToList();
                 string defaultName = getImage.SafeFileName.Remove(getImage.SafeFileName.Length - 4);
                 NewNameWindow spriteSheetName = new NewNameWindow(textureNames, "Sprite Sheet", defaultName);
                 spriteSheetName.ShowDialog();
                 switch (spriteSheetName.DialogResult)
                 {
                     case DialogResult.OK:
                         if (newTexture.Width > 4096 || newTexture.Height > 4096)
                         {
                             throw new Exception("Sprite sheets cannot be bigger than 4096 x 4096 pixels");
                         }
                         newTexture.Name = spriteSheetName.ReturnName;
                         AddTextureToList(newTexture);
                         Animation textureAnimation = new Animation(newTexture.Name,
                             newTexture.Name, 0, 1, 1, new Vector2(0, 0), new Vector2(0, 0), 1, new Collidable());
                         /*{
                             IsLoop = true
                         };
                          */
                         textureAnimation.AddFrame(new Frame(new GameRectangle(0, 0, newTexture.Width, newTexture.Height )));
                         Game.gameGraphics.AddDrawable(textureAnimation);
                         break;
                     default:
                         return;
                 }
             }
             break;
         default:
             return;
     }
 }