//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(); }
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; } }