private void exportRawPaletteDataToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Raw Palette File (*.rawpalette)|*.rawpalette|All Files (*.*)|*.*"; sfd.Title = "Select a Raw Palette File"; sfd.FileName = Path.GetFileNameWithoutExtension(activeChild.Filename); var result = sfd.ShowDialog(); if (result == DialogResult.OK) { FileUtilities.WriteAllBytes(sfd.FileName, activeChild.loadedSprite.PaletteData); MessageBox.Show($"Created {sfd.FileName}", "File Saved"); } } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm newMDI = new SpriteForm(); newMDI.MdiParent = this; newMDI.Show(); }
private void ZSpriteToolForm_MdiChildActivate(object sender, EventArgs e) { if (this.ActiveMdiChild == null) { DisableSave(); DisableSaveAs(); DisableEditExportImport(); DisableExport(); DisableImport(); UpdateCurrentSprite(null); } else { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; this.displayTextTextBox.Text = activeChild.loadedSprite.DisplayText; this.authorTextBox.Text = activeChild.loadedSprite.Author; this.authorRomDisplayTextBox.Text = activeChild.loadedSprite.AuthorRomDisplay; EnableSave(); EnableSaveAs(); EnableEditExportImport(); EnableExport(); EnableImport(); UpdateCurrentSprite(activeChild.loadedSprite); } }
private void exportPNGToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "PNG File (*.png)|*.png|All Files (*.*)|*.*"; sfd.Title = "Select a PNG File"; sfd.FileName = Path.GetFileNameWithoutExtension(activeChild.Filename); var result = sfd.ShowDialog(); if (result == DialogResult.OK) { ExportPng(activeChild.loadedSprite, sfd.FileName); MessageBox.Show($"Created {sfd.FileName}", "File Saved"); } } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void importRawPaletteDataToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Raw Palette File (*.rawpalette)|*.rawpalette|All Files (*.*)|*.*"; ofd.Title = "Select a Raw Palette File"; var result = ofd.ShowDialog(); if (result == DialogResult.OK) { var rawFile = File.ReadAllBytes(ofd.FileName); activeChild.ImportRawPalette(rawFile); UpdateCurrentSprite(activeChild.loadedSprite); } } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void glovesPalettePictureBox_DoubleClick(object sender, EventArgs e) { var mouseE = e as MouseEventArgs; var x = mouseE.X / paletteSquareSize; var y = mouseE.Y / paletteSquareSize; if (x >= 2 || y >= 1) { // clicked outside palette area (control is too big) return; } ColorDialog colorDialog = new ColorDialog(); colorDialog.Color = currentSprite.GlovePalette[x]; if (colorDialog.ShowDialog() == DialogResult.OK) { currentSprite.GlovePalette[x] = colorDialog.Color; } BuildPalette(paletteComboBox.SelectedIndex); if (this.ActiveMdiChild != null) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; activeChild.UpdateForm(); } }
private void authorRomDisplayTextBox_TextChanged(object sender, EventArgs e) { if (this.ActiveMdiChild != null) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; activeChild.loadedSprite.AuthorRomDisplay = authorRomDisplayTextBox.Text; } }
private void palettePictureBox_DoubleClick(object sender, EventArgs e) { var mouseE = e as MouseEventArgs; var x = mouseE.X / paletteSquareSize; var y = mouseE.Y / paletteSquareSize; if (x >= 8 || y >= 2) { // clicked outside palette area (control is too big) return; } SpriteLibrary.Palette palette = null; switch (paletteComboBox.SelectedIndex) { case 0: palette = currentSprite.GreenMailPalette; break; case 1: palette = currentSprite.BlueMailPalette; break; case 2: palette = currentSprite.RedMailPalette; break; case 3: palette = currentSprite.BunnyPalette; break; default: return; } int index = x + y * 8; ColorDialog colorDialog = new ColorDialog(); colorDialog.Color = palette[index]; if (colorDialog.ShowDialog() == DialogResult.OK) { palette[index] = colorDialog.Color; } BuildPalette(paletteComboBox.SelectedIndex); if (this.ActiveMdiChild != null) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; activeChild.UpdateForm(); } }
private void exportCopyToNewROMToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Rom File (*.sfc)|*.sfc|All Files (*.*)|*.*"; ofd.Title = "Select a Base Rom File"; var result = ofd.ShowDialog(); if (result != DialogResult.OK) { return; } string filename = activeChild.Filename; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Rom File (*.sfc)|*.sfc|All Files (*.*)|*.*"; sfd.Title = "Select a New Rom File"; sfd.FileName = String.IsNullOrEmpty(filename) ? activeChild.loadedSprite.DisplayText : Path.GetFileNameWithoutExtension(filename); sfd.FileName += " - " + Path.GetFileNameWithoutExtension(ofd.FileName); result = sfd.ShowDialog(); if (result != DialogResult.OK) { return; } filename = sfd.FileName; var rom = new SpriteLibrary.Rom(ofd.FileName); rom.InjectSprite(activeChild.loadedSprite); FileUtilities.WriteAllBytes(filename, rom.RomData); MessageBox.Show($"Created {filename}", "File Saved"); } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void importGraphicsGalePaletteToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { string filename = activeChild.Filename; // new file, or old format file need to show save box OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Graphics Gale Palette File (*.pal)|*.pal|All Files (*.*)|*.*"; ofd.Title = "Select a Graphics Gale Palette File"; var result = ofd.ShowDialog(); if (result != DialogResult.OK) { return; } filename = ofd.FileName; var pal = SpriteLibrary.GraphicsGalePalette.BuildSpritePaletteColorsFromStringArray(File.ReadAllLines(filename)); if (pal.Length < 60) { MessageBox.Show("Palette is not long enough. Character Sprites require at least 60 entries.", "Error"); return; } activeChild.loadedSprite.SetPalette(pal); activeChild.UpdateForm(); UpdateCurrentSprite(activeChild.loadedSprite); } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void clearPNGPaletteTileToolStripMenuItem_Click(object sender, EventArgs e) { if (currentSprite == null) { return; } var empty = new byte[32]; var pixels = currentSprite.PixelData; Array.Copy(empty, 0, pixels, 0x7000 - 32, 32); currentSprite.PixelData = pixels; if (this.ActiveMdiChild != null) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; activeChild.UpdateForm(); } }
private void importRomToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Rom File (*.sfc)|*.sfc|All Files (*.*)|*.*"; ofd.Title = "Select a Rom File"; var result = ofd.ShowDialog(); if (result == DialogResult.OK) { var rom = new SpriteLibrary.Rom(ofd.FileName); var sprite = rom.GetSprite(); SpriteForm newMDI = new SpriteForm(ofd.FileName, sprite); newMDI.MdiParent = this; newMDI.Show(); UpdateCurrentSprite(newMDI.loadedSprite); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { string filename = activeChild.Filename; if (String.IsNullOrEmpty(filename) || Path.GetExtension(filename) != ".zspr") { // new file, or old format file need to show save box SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "ZSprite File (*.zspr)|*.zspr|All Files (*.*)|*.*"; sfd.Title = "Select a Sprite File"; sfd.FileName = String.IsNullOrEmpty(filename) ? activeChild.loadedSprite.DisplayText : Path.GetFileNameWithoutExtension(filename); var result = sfd.ShowDialog(); if (result != DialogResult.OK) { return; } filename = sfd.FileName; } var spriteData = activeChild.loadedSprite.ToByteArray(); FileUtilities.WriteAllBytes(filename, spriteData); activeChild.UpdateFilename(filename); } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void exportGraphicsGalePaletteToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { string filename = activeChild.Filename; // new file, or old format file need to show save box SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Graphics Gale Palette File (*.pal)|*.pal|All Files (*.*)|*.*"; sfd.Title = "Select a Graphics Gale Palette File"; sfd.FileName = String.IsNullOrEmpty(filename) ? activeChild.loadedSprite.DisplayText : Path.GetFileNameWithoutExtension(filename); var result = sfd.ShowDialog(); if (result != DialogResult.OK) { return; } filename = sfd.FileName; var pal = SpriteLibrary.GraphicsGalePalette.BuildPaletteFromColorArray(activeChild.loadedSprite.Palette); FileUtilities.WriteAllText(filename, pal); MessageBox.Show($"Created {filename}", "File Saved"); } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
public void LoadFile(string fileName) { try { var spriteFile = File.ReadAllBytes(fileName); var loadedSprite = new SpriteLibrary.PlayerSprite(spriteFile); if (loadedSprite.Version == 0) { loadedSprite.DisplayText = Path.GetFileNameWithoutExtension(fileName); } SpriteForm newMDI = new SpriteForm(fileName, loadedSprite); newMDI.MdiParent = this; newMDI.Show(); UpdateCurrentSprite(newMDI.loadedSprite); } catch (Exception ex) { logger.Error(ex); MessageBox.Show($"Failed to load file {fileName}. Make sure it's a sprite file.", "Error"); } }
private void exportRomToolStripMenuItem_Click(object sender, EventArgs e) { SpriteForm activeChild = (SpriteForm)this.ActiveMdiChild; if (activeChild != null) { try { string filename = activeChild.Filename; SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Rom File (*.sfc)|*.sfc|All Files (*.*)|*.*"; sfd.Title = "Select a Rom File"; var result = sfd.ShowDialog(); if (result != DialogResult.OK) { return; } filename = sfd.FileName; var rom = new SpriteLibrary.Rom(filename); rom.InjectSprite(activeChild.loadedSprite); FileUtilities.WriteAllBytes(filename, rom.RomData); MessageBox.Show($"Modified sprite in {filename}", "File Saved"); } catch (Exception ex) { logger.Error(ex); MessageBox.Show(OopsMessage, "Error"); } } }
private void importPNGToolStripMenuItem_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.Filter = "PNG File (*.png)|*.png|All Files (*.*)|*.*"; ofd.Title = "Select a PNG File"; var invalidPixelsFound = false; var result = ofd.ShowDialog(); if (result == DialogResult.OK) { Bitmap tempBitmap = (Bitmap)Image.FromFile(ofd.FileName); if (tempBitmap.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb) { var clone = new Bitmap(tempBitmap.Width, tempBitmap.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb); using (Graphics gr = Graphics.FromImage(clone)) { gr.DrawImage(tempBitmap, new Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height)); } tempBitmap = clone; } if (tempBitmap.Width != 128 || tempBitmap.Height != 448) { MessageBox.Show("Invalid PNG image. Must be 128 x 448 pixels", "Error"); return; } var sprite = new SpriteLibrary.PlayerSprite(); sprite.DisplayText = Path.GetFileNameWithoutExtension(ofd.FileName); var bitmapData = tempBitmap.LockBits(new Rectangle(0, 0, tempBitmap.Width, tempBitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, tempBitmap.PixelFormat); var totalBytes = bitmapData.Stride * bitmapData.Height; var pixels = new byte[totalBytes]; Marshal.Copy(bitmapData.Scan0, pixels, 0, totalBytes); tempBitmap.UnlockBits(bitmapData); // load palette from png int xoffset = 120; int yoffset = 440; var colors = new Color[8 * 8]; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { int pixelPosition = (y + yoffset) * bitmapData.Stride + ((x + xoffset) * 4); int b = pixels[pixelPosition + 0]; int g = pixels[pixelPosition + 1]; int r = pixels[pixelPosition + 2]; int a = pixels[pixelPosition + 3]; colors[x + y * 8] = Color.FromArgb(a, r, g, b); } } var palette = new Color[62]; for (int i = 0; i < 15; i++) { palette[i] = colors[i + 1]; } for (int i = 15; i < 30; i++) { palette[i] = colors[i + 2]; } for (int i = 30; i < 45; i++) { palette[i] = colors[i + 3]; } for (int i = 45; i < 60; i++) { palette[i] = colors[i + 4]; } palette[60] = colors[16]; palette[61] = colors[32]; sprite.SetPalette(palette); // load pixel data var pixelBytes = new byte[128 * 448]; var greenPalette = new Dictionary <int, Color>(); for (int i = 0; i < 16; i++) { greenPalette[i] = colors[i]; } for (int y = 0; y < 448; y++) { for (int x = 0; x < 128; x++) { int pixelPosition = y * bitmapData.Stride + (x * 4); int b = pixels[pixelPosition + 0]; int g = pixels[pixelPosition + 1]; int r = pixels[pixelPosition + 2]; int a = pixels[pixelPosition + 3]; var pixel = Color.FromArgb(a, r, g, b); if (y >= 440 && x >= 120) { // palette data, skip it pixelBytes[x + y * 128] = 0; continue; } if (a == 0 || greenPalette[0] == pixel) { pixelBytes[x + y * 128] = 0; } else { var pixelValue = greenPalette.FirstOrDefault(c => c.Value == pixel); if (pixelValue.Key > 0) { pixelBytes[x + y * 128] = (byte)pixelValue.Key; } else { invalidPixelsFound = true; //logger.Debug($"Import PNG: Bad pixel value found. File: {ofd.FileName}, Pixel: [{x + y * 128}] {pixel.ToString()}"); } } } } List <byte[]> tiles = new List <byte[]>(); for (int yTile = 0; yTile < 56; yTile++) { for (int xTile = 0; xTile < 16; xTile++) { var currentTile = new byte[8 * 8]; for (int y = 0; y < 8; y++) { for (int x = 0; x < 8; x++) { currentTile[x + y * 8] = pixelBytes[(xTile * 8 + x) + (yTile * 8 + y) * 128]; } } tiles.Add(currentTile); } } byte[] pixels4bpp = new byte[0x7000]; int offset = 0; foreach (var tile in tiles) { var four = SpriteLibrary.Utilities.Tile8x8To4Bpp(tile); Array.Copy(four, 0, pixels4bpp, offset, 32); offset += 32; } sprite.Set4bppPixelData(pixels4bpp); if (invalidPixelsFound) { MessageBox.Show("PNG contains pixels that do not use the first 16 colors of the embedded palette. Pixels have been made transparent. Please verify your source file.", "Error"); } SpriteForm newMDI = new SpriteForm(ofd.FileName, sprite); newMDI.MdiParent = this; newMDI.Show(); UpdateCurrentSprite(newMDI.loadedSprite); } } }