public void SetTileset(NSMBTileset t) { this.t = t; tileCount = t.Map16Buffer.Width / 16; map16Image = Image2D.CutImage(t.Map16Buffer, 256, 1); pictureBox1.Size = map16Image.Size; pictureBox1.Invalidate(true); }
private void editZone_Paint(object sender, PaintEventArgs e) { if (tls == null) { return; } if (obj == null) { return; } Graphics g = e.Graphics; g.FillRectangle(Brushes.LightSteelBlue, 0, 0, editZone.Width, editZone.Height); int x = 16; int y = 0; foreach (List <NSMBTileset.ObjectDefTile> row in obj.tiles) { foreach (NSMBTileset.ObjectDefTile t in row) { if (t.controlTile) { g.FillRectangle(Brushes.White, x, y, 15, 15); g.DrawRectangle(Pens.Black, x, y, 15, 15); g.DrawString(String.Format("{0:X2}", t.controlByte), NSMBGraphics.InfoFont, Brushes.Black, x, y); } else if (!t.emptyTile) { g.DrawImage(tls.Map16Buffer, x, y, Image2D.getTileRectangle(tls.Map16Buffer, 16, t.tileID), GraphicsUnit.Pixel); if ((t.controlByte & 1) != 0) { g.DrawRectangle(Pens.Red, x, y, 15, 15); } if ((t.controlByte & 2) != 0) { g.DrawRectangle(Pens.Blue, x + 1, y + 1, 13, 13); } } if (t == selTile) { g.DrawRectangle(Pens.White, x, y, 15, 15); } x += 16; } g.DrawString((y / 16) + "", NSMBGraphics.InfoFont, Brushes.White, 0, y); if (selRow == row && selTile == null) { g.DrawRectangle(Pens.White, 0, y, 15, 15); } x = 16; y += 16; } }
public Bitmap reRender(int xMin, int yMin, int width, int height) { for (int x = xMin; x < xMin + width; x++) { for (int y = yMin; y < yMin + height; y++) { if (x >= this.width) { continue; } if (y >= this.height) { continue; } Tile t = tiles[x, y]; if (t.tileNum < 0 || t.tileNum >= tileCount) { bufferGx.FillRectangle(Brushes.Transparent, x * 8, y * 8, 8, 8); continue; } if (t.palNum >= palettes.Length) { continue; } if (t.palNum < 0) { continue; } // if (t.hflip == false && t.vflip == false) Rectangle rect = Image2D.getTileRectangle(buffers[t.palNum], 8, t.tileNum); Bitmap tile = new Bitmap(8, 8, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); Graphics g = Graphics.FromImage(tile); g.DrawImage(buffers[t.palNum], new Rectangle(0, 0, 8, 8), rect, GraphicsUnit.Pixel); if (t.hflip == true && t.vflip == false) { tile.RotateFlip(RotateFlipType.RotateNoneFlipX); } else if (t.hflip == false && t.vflip == true) { tile.RotateFlip(RotateFlipType.RotateNoneFlipY); } else if (t.hflip == true && t.vflip == true) { tile.RotateFlip(RotateFlipType.RotateNoneFlipXY); } bufferGx.DrawImage(tile, new Rectangle(x * 8, y * 8, 8, 8), new Rectangle(0, 0, 8, 8), GraphicsUnit.Pixel); } } return(buffer); }
public Tilemap(File f, int tileWidth, Image2D i, Palette[] pals, int tileOffset, int paletteOffset) { this.f = f; this.width = tileWidth; this.tileOffset = tileOffset; this.paletteOffset = paletteOffset; this.tileset = i; this.palettes = pals; this.tileCount = tileset.getWidth() * tileset.getHeight() / 64; load(); }
public void load() { //Palettes int palCount = ROM.LZ77_GetDecompressedSize(PalFile.getContents(), false) / 512; palettes = new Palette[palCount]; CompressedFile PalFileLz = new CompressedFile(PalFile, CompressedFile.CompressionType.LZ); for (int i = 0; i < palCount; i++) { palettes[i] = new FilePalette(new InlineFile(PalFileLz, i * 512, 512, "Palette " + i)); } //Graphics CompressedFile GFXFileLz = new CompressedFile(GFXFile, CompressedFile.CompressionType.LZ); graphics = new Image2D(GFXFileLz, 256, false); //Map16 map16 = new Map16Tilemap(Map16File, 32, graphics, palettes, Map16TileOffset, Map16PaletteOffset); Overrides = new short[map16.getMap16TileCount()]; Map16Buffer = map16.render(); /* * TilemapEditorTest t = new TilemapEditorTest(); * t.load(map16); * t.Show(); */ //Tile Behaviors loadTileBehaviors(); //Objects loadObjects(); /* // Finally, load overrides * if (overrideFlag) * { * UseOverrides = true; * OverrideBitmap = Properties.Resources.tileoverrides; * * Overrides = new short[Map16.Length]; * EditorOverrides = new short[Map16.Length]; * * for (int idx = 0; idx < Map16.Length; idx++) * { * Overrides[idx] = -1; * EditorOverrides[idx] = -1; * } * }*/ }
private Bitmap RenderBackground(File GFXFile, File PalFile, File LayoutFile, int offs, int palOffs) { LayoutFile = new CompressedFile(LayoutFile, CompressedFile.CompressionType.LZ); PalFile = new CompressedFile(PalFile, CompressedFile.CompressionType.LZ); Image2D i = new Image2D(GFXFile, 256, false); Palette pal1 = new FilePalette(new InlineFile(PalFile, 0, 512, PalFile.name)); Palette pal2 = new FilePalette(new InlineFile(PalFile, 512, 512, PalFile.name)); Tilemap t = new Tilemap(LayoutFile, 64, i, new Palette[] { pal1, pal2 }, offs, palOffs); t.render(); return(t.buffer); }
public static void gotSection(File f, int offs, int size) { uint magic = f.getUintAt(offs); if (magic == 0x504C5454) //PLTT { new PaletteViewer(new InlineFile(f, offs + 0x18, size - 0x18, f.name)).Show(); } else if (magic == 0x43484152) //CHAR { LevelChooser.showImgMgr(); int tileWidth = f.getUshortAt(offs + 0xA); if (tileWidth == 0xFFFF) { tileWidth = 8; } LevelChooser.imgMgr.m.addImage(new Image2D(new InlineFile(f, offs + 0x20, size - 0x20, f.name), 8 * tileWidth, true)); } else if (magic == 0x5343524E) //SCRN { if (LevelChooser.imgMgr == null) { return; } Image2D img = LevelChooser.imgMgr.m.getSelectedImage(); Palette[] pals = LevelChooser.imgMgr.m.getPalettes(); if (img == null) { return; } if (pals == null) { return; } if (pals.Length == 0) { return; } InlineFile ff = new InlineFile(f, offs + 0x14, size - 0x14, f.name); Tilemap t = new Tilemap(ff, 32, img, pals, 0, 0); new TilemapEditorWindow(t).Show(); } else { Console.WriteLine(String.Format("Unknown magic: {0:X8}", magic)); } }
private Tilemap getTilemap() { getFiles(); if (GFXFile == null) { return(null); } if (PalFile == null) { return(null); } if (LayoutFile == null) { return(null); } LayoutFile = new CompressedFile(LayoutFile, CompressedFile.CompressionType.LZ); Image2D image = new Image2D(new CompressedFile(GFXFile, CompressedFile.CompressionType.MaybeCompressed), 256, false); CompressedFile paletteFile = new CompressedFile(PalFile, CompressedFile.CompressionType.MaybeCompressed); int palSize = 256; Color[] pal = FilePalette.arrayToPalette(paletteFile.getContents()); if (pal.Length < 256) { palSize = 16; } List <Palette> palettes = new List <Palette>(); for (int i = 0; i + palSize <= pal.Length; i += palSize) { int palOffs = i; int palLen = palSize; if (palOffs + palLen > pal.Length) { palLen = pal.Length - palOffs; } palettes.Add(new FilePalette(new InlineFile(paletteFile, palOffs * 2, palLen * 2, paletteFile.name))); } Tilemap t = new Tilemap(LayoutFile, 64, image, palettes.ToArray(), bg.BitmapOffset, bg.PaletteOffsets); return(t); }
public Map16Tilemap(File f, int tileWidth, Image2D i, Palette[] pals, int a, int b) : base(f, tileWidth, i, pals, a, b) { }