void MakeShiny_Click(object sender, EventArgs e) { if (OpenPngs.Enabled == false) { return; } OpenPngs.Enabled = false; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Choose the base image"; openFileDialog.CheckPathExists = true; openFileDialog.Filter = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png"; openFileDialog.ShowHelp = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { OpenPngs.Enabled = true; return; } string filename = openFileDialog.FileName; openFileDialog.Title = "Choose the shiny image"; openFileDialog.CheckPathExists = true; openFileDialog.Filter = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png"; openFileDialog.ShowHelp = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { OpenPngs.Enabled = true; return; } Bitmap parent = new Bitmap(filename); Bitmap child = new Bitmap(openFileDialog.FileName); IndexedBitmapHandler Handler = new IndexedBitmapHandler(); ColorPalette temp = Handler.AlternatePalette(parent, child); if (temp != null) { CurrentSprites.Shiny = temp; } else { MessageBox.Show("Failed!", "Failed"); } OpenPngs.Enabled = true; LoadImages(); }
void OpenPng_Click(object sender, EventArgs e) { if (OpenPngs.Enabled == false) { return; } OpenPngs.Enabled = false; LoadingForm Open = new LoadingForm(); var result = Open.ShowDialog(); if (result == DialogResult.Cancel) { OpenPngs.Enabled = true; return; } string[] filenames = Open.files; bool Autofill = Open.result; int shinymatch = Open.shinymatch; bool paletteMatch = Open.paletteMatch; Open.Dispose(); SpriteSet temp = new SpriteSet(); Bitmap image; for (int i = 0; i < 4; i++) { if (filenames[i] == "") { continue; } image = new Bitmap(filenames[i]); temp.Sprites[i] = CheckSize(image, filenames[i], names[i], i); } bool[] tempUsed = null; if (paletteMatch) { temp.Normal = CurrentSprites.Normal; tempUsed = used; } for (int i = 0; i < 4; i++) { if (temp.Sprites[i] == null) { continue; } if (temp.Normal == null) { temp.Normal = temp.Sprites[i].Palette; tempUsed = Handler.IsUsed(temp.Sprites[i]); } else { bool match = Handler.PaletteEquals(temp.Normal, temp.Sprites[i]); if (!match) { temp.Sprites[i] = Handler.PaletteMatch(temp.Normal, temp.Sprites[i], tempUsed); temp.Normal = temp.Sprites[i].Palette; } tempUsed = Handler.IsUsed(temp.Sprites[i], tempUsed); } } used = tempUsed; if (filenames[4] != "") { image = new Bitmap(filenames[4]); image = CheckSize(image, filenames[4], names[4], 4); if ((shinymatch < 4) && (temp.Sprites[shinymatch] != null)) { temp.Shiny = Handler.AlternatePalette(temp.Sprites[shinymatch], image); } else { temp.Shiny = image.Palette; } } if (Autofill) { if (temp.Sprites[0] == null) { temp.Sprites[0] = temp.Sprites[1]; } if (temp.Sprites[1] == null) { temp.Sprites[1] = temp.Sprites[0]; } if (temp.Sprites[2] == null) { temp.Sprites[2] = temp.Sprites[3]; } if (temp.Sprites[3] == null) { temp.Sprites[3] = temp.Sprites[2]; } if (filenames[4] == "") { temp.Shiny = temp.Normal; } } for (int i = 0; i < 4; i++) { if (temp.Sprites[i] != null) { CurrentSprites.Sprites[i] = temp.Sprites[i]; } } if (temp.Normal != null) { CurrentSprites.Normal = temp.Normal; } if (temp.Shiny != null) { CurrentSprites.Shiny = temp.Shiny; } LoadImages(); OpenPngs.Enabled = true; }
void btnLoadSheet_Click(object sender, EventArgs e) { if (OpenPngs.Enabled == false) { return; } OpenPngs.Enabled = false; OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Select a sprite sheet"; openFileDialog.CheckPathExists = true; openFileDialog.Filter = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png"; openFileDialog.ShowHelp = true; if (openFileDialog.ShowDialog() != DialogResult.OK) { OpenPngs.Enabled = true; return; } Bitmap image = new Bitmap(openFileDialog.FileName); if ((image.Width != 256) || (image.Height != 64)) { MessageBox.Show("The sprite sheet should be 256x64."); return; } IndexedBitmapHandler Handler = new IndexedBitmapHandler(); image = Handler.Convert(image, PixelFormat.Format8bppIndexed); image.Palette = StandardizeColors(image); Bitmap[] tiles = Handler.Split(image, 64, 64); SpriteSet sprites = new SpriteSet(); bool[] used = Handler.IsUsed(tiles[0]); used = Handler.IsUsed(tiles[2], used); Bitmap temp = Handler.ShrinkPalette(tiles[0], used); sprites.Normal = temp.Palette; temp = Handler.Resize(temp, 8, 8, 8, 8); temp = Handler.Concat(temp, temp); sprites.Sprites[2] = temp; sprites.Sprites[3] = temp; temp = Handler.ShrinkPalette(tiles[2], used); temp = Handler.Resize(temp, 8, 8, 8, 8); if (DPCheck.Checked) { temp = Handler.Resize(temp, 0, 0, 0, 80); } else { temp = Handler.Concat(temp, temp); } sprites.Sprites[0] = temp; sprites.Sprites[1] = temp; temp = Handler.ShrinkPalette(tiles[1], used); temp = Handler.Resize(temp, 8, 8, 8, 8); temp = Handler.Concat(temp, temp); sprites.Shiny = Handler.AlternatePalette(sprites.Sprites[2], temp); CurrentSprites = sprites; OpenPngs.Enabled = true; LoadImages(); }
void Picturebox_Click(object sender, EventArgs e) { if (OpenPngs.Enabled == false) { return; } OpenPngs.Enabled = false; PictureBox source = sender as PictureBox; int index = Convert.ToInt32(source.Name); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Title = "Choose an image"; openFileDialog.CheckPathExists = true; openFileDialog.Filter = "Supported fomats: *.bmp, *.gif, *.png | *.bmp; *.gif; *.png"; openFileDialog.ShowHelp = true; Bitmap image; if (openFileDialog.ShowDialog() != DialogResult.OK) { OpenPngs.Enabled = true; return; } image = new Bitmap(openFileDialog.FileName); IndexedBitmapHandler Handler = new IndexedBitmapHandler(); if (index > 3) { image = CheckSize(image, openFileDialog.FileName, "Shiny"); if (image == null) { OpenPngs.Enabled = true; return; } ColorPalette temp = Handler.AlternatePalette(CurrentSprites.Sprites[index % 4], image); if (temp != null) { CurrentSprites.Shiny = temp; } else { CurrentSprites.Shiny = image.Palette; } } else { image = CheckSize(image, openFileDialog.FileName, names[index], index); if (image == null) { OpenPngs.Enabled = true; return; } bool match = Handler.PaletteEquals(CurrentSprites.Normal, image); if (!match) { DialogResult yesno = MessageBox.Show("Image's palette does not match the current palette. Use PaletteMatch?", "Palette mismatch", MessageBoxButtons.YesNo); if (yesno == DialogResult.Yes) { image = Handler.PaletteMatch(CurrentSprites.Normal, image, used); used = Handler.IsUsed(image, used); } else { used = Handler.IsUsed(image); } CurrentSprites.Normal = image.Palette; } CurrentSprites.Sprites[index] = image; } OpenPngs.Enabled = true; LoadImages(); }