예제 #1
0
        private void DrawRectangle(DrawnRectangle rectangle)
        {
            DrawnLine top = new DrawnLine
            {
                Name = rectangle.Name,
                Color = rectangle.Color,
                X = rectangle.X,
                Y = rectangle.Y,
                EndX = rectangle.X + rectangle.Size.Width,
                EndY = rectangle.Y,
                Thickness = rectangle.Thickness
            };

            DrawnLine right = new DrawnLine
            {
                Name = rectangle.Name,
                Color = rectangle.Color,
                X = rectangle.X + rectangle.Size.Width,
                Y = rectangle.Y,
                EndX = rectangle.X + rectangle.Size.Width,
                EndY = rectangle.Y + rectangle.Size.Height,
                Thickness = rectangle.Thickness
            };

            DrawnLine bottom = new DrawnLine
            {
                Name = rectangle.Name,
                Color = rectangle.Color,
                X = rectangle.X + rectangle.Size.Width,
                Y = rectangle.Y + rectangle.Size.Height,
                EndX = rectangle.X,
                EndY = rectangle.Y + rectangle.Size.Height,
                Thickness = rectangle.Thickness
            };

            DrawnLine left = new DrawnLine
            {
                Name = rectangle.Name,
                Color = rectangle.Color,
                X = rectangle.X,
                Y = rectangle.Y + rectangle.Size.Height,
                EndX = rectangle.X,
                EndY = rectangle.Y,
                Thickness = rectangle.Thickness
            };

            DrawLine(top);
            DrawLine(right);
            DrawLine(bottom);
            DrawLine(left);
        }
        //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();
        }