private void addImageButton_Click(object sender, EventArgs e) { if (nameTextBox.Text.Length == 0) { MessageBox.Show("Every tile must have a distinct name.", "Name empty"); } else if(dataGridView1.Columns.Count == 0) { MessageBox.Show("Tile must have at least one image.", "No images"); } else { Tile tile = new Tile(); if (animationCheck.Checked) { Image[] frames = new Image[dataGridView1.Columns.Count]; int tps = 100; Int32.TryParse(tpsTextBox.Text, out tps); int startFrame = 0; if (randomStartFrameCheck.Checked) { Random r = new Random(); startFrame = r.Next(0, dataGridView1.Columns.Count + 1); } bool loop = loopCheck.Checked; int i = 0; foreach (DataGridViewImageCell cell in dataGridView1.Rows[0].Cells) { frames[i] = (Image)cell.Value; i++; } currentAnimation = new Animation(nameTextBox.Text, frames, tps, loop, startFrame); tile.isAnimation = true; tile.image = null; tile.animation = currentAnimation; } else { if (dataGridView1.Rows.Count > 0 && dataGridView1.Rows[0].Cells.Count == 1 && dataGridView1.Rows[0].Cells[0] != null) { currentImage = (Image)dataGridView1.Rows[0].Cells[0].Value; tile.isAnimation = false; tile.image = currentImage; tile.animation = null; } } int alphaR = 0; Int32.TryParse(alphaRTextBox.Text, out alphaR); tile.alphaR = alphaR; int alphaG = 0; Int32.TryParse(alphaGTextBox.Text, out alphaG); tile.alphaG = alphaG; int alphaB = 0; Int32.TryParse(alphaBTextBox.Text, out alphaB); tile.alphaB = alphaB; tile.blocksGroundUnits = blocksGroundUnitsCheck.Checked; tile.blocksFlyingUnits = blocksFlyingUnitsCheck.Checked; tile.blocksProjectiles = blocksProjectilesCheck.Checked; tile.isSlope = isSlopeCheck.Checked; tile.name = nameTextBox.Text; currentTileList.Add(tile); refreshTileSetLayout(); updateSelectedStuff(-2); } }
public void drawTile(Tile tile, int x, int y) { if(tile != null && tile.isAnimation && tile.animation != null && tile.animation.frames != null && tile.animation.frames.Length > 0) { offScreenDC.DrawImage(tile.animation.frames[tile.animation.currentFrame], new Rectangle(x, y, tile.animation.frames[tile.animation.currentFrame].Width, tile.animation.frames[tile.animation.currentFrame].Height), 0, 0, tile.animation.frames[tile.animation.currentFrame].Width, tile.animation.frames[tile.animation.currentFrame].Height, GraphicsUnit.Pixel, imageAttributes); } else if (tile != null && tile.image != null) { offScreenDC.DrawImage(tile.image, new Rectangle(x, y, tile.image.Width, tile.image.Height), 0, 0, tile.image.Width, tile.image.Height, GraphicsUnit.Pixel, imageAttributes); } else { offScreenDC.FillRectangle(Brushes.Black, x, y, Common.MAX_TILE_SIZE, Common.MAX_TILE_SIZE); } }
private void addOrUpdateTileSet(Tile tile) { Tile aux = existsTile(tile.name); if (aux != null) { int pos = currentTileList.IndexOf(aux); currentTileList.Insert(pos, tile); } else { currentTileList.Add(tile); } }