private void OnShown(object sender, EventArgs e)
        {
            previewGame = new AnimationGame(pictureBox_AnimationPreview.Handle, this, pictureBox_AnimationPreview, new Vector2(pictureBox_AnimationPreview.Width, pictureBox_AnimationPreview.Height));
            previewManager = new GraphicsManager(previewGame.gameGraphics);
            previewGame.gameForm.GotFocus += delegate(object o, EventArgs args)
            {
                this.Focus();
            };
            previewGame.gameGraphics.GraphicsManager.DeviceCreated += delegate(object o, EventArgs args)
            {
                previewGame.gameGraphics.AddTexture(animationTexture.Name, TextureManager.ConvertDataToTexture(animationTexture, previewGame.GraphicsDevice));
                previewGame.gameGraphics.AddDrawable(previewAnimation);
                Vector2 center = StaticMethods.GetCenter(new Vector2(previewAnimation.Frames[1].TextureSource.Width,previewAnimation.Frames[1].TextureSource.Height));
                Vector2 position = StaticMethods.GetDrawPosition(new Vector2(panel_AnimationPreview.Width, panel_AnimationPreview.Height), center);
                previewGame.gameGraphics.AddToDrawList(new DrawParam(previewAnimation.Name, previewAnimation.Name,position, DrawnType.Animation));
                LoopAction loopActon = new LoopAction
                {
                    Name = previewAnimation.Name,
                    Drawable = previewAnimation.Name,
                    Value = true
                };
                previewManager.ExecuteAction(loopActon);

            };
            previewGame.Run();
        }
Esempio n. 2
0
 private void MainWindow_Shown(object sender, EventArgs e)
 {
     Game = new AnimationGame(picBox_AnimationPreview.Handle, this, picBox_AnimationPreview, new Vector2(0, 0));
     Game.gameGraphics.GraphicsManager.DeviceCreated += delegate(object gsender, EventArgs gargs)
     {
         graphicsManager = new GraphicsManager(Game.gameGraphics);
     };
     Game.Run();
 }
        //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();
        }
        //Same as LoadFrameGame, but you're able to run some stuff before starting the game. This way things for the game can be created, but  other things can be done right before we start the game since nothing can be done after less it be an event
        private void LoadFrameGame(Action action)
        {
            _frameGame = new AnimationGame(pictureBox_FrameDisplay.Handle, this, pictureBox_FrameDisplay, new Vector2(pictureBox_FrameDisplay.Width, pictureBox_FrameDisplay.Height));
            animationManager = new GraphicsManager(_frameGame.gameGraphics);
            pictureBox_TextureDisplay.Width = _frameGame.gameGraphics.GraphicsManager.PreferredBackBufferWidth;
            pictureBox_TextureDisplay.Height = _frameGame.gameGraphics.GraphicsManager.PreferredBackBufferHeight;

            _frameGame.gameForm.GotFocus += delegate(object o, EventArgs args)
            {
                this.Focus();
            };
            _frameGameLoaded = true;
            _frameGame.gameGraphics.GraphicsManager.DeviceCreated += delegate(object o, EventArgs args)
            {
                foreach (BinaryTexture texture in _binaryTextures)
                {
                    _frameGame.gameGraphics.textureManager.Textures.Add(texture.Name, TextureManager.ConvertDataToTexture(texture, _frameGame.gameGraphics.GraphicsManager.GraphicsDevice));
                }
            };
            Vector2 position = Vector2.Zero;
            if (ReturnAnimation.Frames[1].TextureSource.Width <= panel_FrameDisplay.Width || ReturnAnimation.Frames[1].TextureSource.Height <= panel_FrameDisplay.Height)
            {
                Vector2 center = StaticMethods.GetCenter(new Vector2(((ReturnAnimation.Frames[1].TextureSource.Width) * ReturnAnimation.Scale), (ReturnAnimation.Frames[1].TextureSource.Height) * ReturnAnimation.Scale));
                position = StaticMethods.GetDrawPosition(new Vector2(panel_FrameDisplay.Width, panel_FrameDisplay.Height), center);
            }
            _frameGame.gameGraphics.AddDrawable(ReturnAnimation);
            _frameGame.gameGraphics.AddToDrawList(new DrawParam(ReturnAnimation.Name, ReturnAnimation.Name, position, DrawnType.Animation));
            action();
            _frameGame.Run();
        }
        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();
        }