public void Test_LoadXML_OLD_map_valid() { Palette p = m_doc.BackgroundPalettes.AddPalette16(Options.DefaultBgPaletteName, 0, ""); Assert.IsNotNull(p); Spriteset ss = m_doc.BackgroundSpritesets.AddSpriteset(Options.DefaultBgTilesetName, 0, "", p); Assert.IsNotNull(ss); // Valid old map. XmlElement xnMap = m_xd.CreateElement("map"); for (int id = 0; id < 32; id++) { Test_LoadXML_OLD_map_AddRow(xnMap, id, 32); } Assert.IsTrue(m_filer.LoadXML_OLD_map(xnMap.ChildNodes)); Assert.AreEqual(1, m_doc.BackgroundMaps.NumMaps); Map m = m_doc.BackgroundMaps.GetMap(0); Assert.IsNotNull(m); int nTileId, nSubpaletteId; m.GetTile(2, 4, out nTileId, out nSubpaletteId); Assert.AreEqual(6, nTileId); m.GetTile(7, 9, out nTileId, out nSubpaletteId); Assert.AreEqual(16, nTileId); m.GetTile(31, 31, out nTileId, out nSubpaletteId); Assert.AreEqual(62, nTileId); }
public void Test_LoadXML_map16_32x32() { Palette p = m_doc.BackgroundPalettes.AddPalette16(Options.DefaultBgPaletteName, 0, ""); Assert.IsNotNull(p); Spriteset ss = m_doc.BackgroundSpritesets.AddSpriteset(Options.DefaultBgTilesetName, 0, "", p); Assert.IsNotNull(ss); Map m = m_doc.BackgroundMaps.AddMap("map", 0, "", ss); Assert.AreEqual(1, m_doc.BackgroundMaps.NumMaps); Assert.IsNotNull(m); // Valid map. XmlElement xnMap = m_xd.CreateElement("map16"); Test_LoadXML_map16_AddBlock(xnMap, 0, 32, 32); // <map16> attributes are not needed for test. Assert.IsTrue(m.LoadXML_map16(xnMap, 0)); int nTileId, nSubpaletteId; bool fHorizontal, fVertical; m.GetTile(2, 4, out nTileId, out nSubpaletteId); m.GetFlip(2, 4, out fHorizontal, out fVertical); Assert.AreEqual(6, nTileId); Assert.AreEqual(0, nSubpaletteId); m.GetTile(7, 9, out nTileId, out nSubpaletteId); Assert.AreEqual(16, nTileId); Assert.AreEqual(0, nSubpaletteId); m.GetTile(31, 31, out nTileId, out nSubpaletteId); Assert.AreEqual(62, nTileId); Assert.AreEqual(1, nSubpaletteId); // x==y, so subpalette=1 m.GetFlip(0, 0, out fHorizontal, out fVertical); Assert.IsTrue(fHorizontal); Assert.IsTrue(fVertical); m.GetFlip(0, 5, out fHorizontal, out fVertical); Assert.IsFalse(fHorizontal); Assert.IsTrue(fVertical); m.GetFlip(5, 0, out fHorizontal, out fVertical); Assert.IsTrue(fHorizontal); Assert.IsFalse(fVertical); m.GetFlip(5, 5, out fHorizontal, out fVertical); Assert.IsFalse(fHorizontal); Assert.IsFalse(fVertical); }
private void pbMap_Paint(object sender, PaintEventArgs e) { Graphics g = e.Graphics; int pxX = 0; int pxY = 0; for (int ix = 0; ix < k_nMaxMapTilesX; ix++) { pxY = 0; for (int iy = 0; iy < k_nMaxMapTilesY; iy++) { bool fDrawn = false; int nTileId, nSubpalette; m_map.GetTile(ix, iy, out nTileId, out nSubpalette); Sprite s = m_map.Spriteset.FindSprite(nTileId); if (s != null) { Tile t = s.GetTile(nTileId - s.FirstTileId); if (t != null) { t.DrawSmallTile(g, pxX, pxY); fDrawn = true; } } if (!fDrawn) { int pxInset = Tile.SmallBitmapScreenSize / 4; int pxX0i = pxX + pxInset; int pxY0i = pxY + pxInset; int pxX1i = pxX + Tile.SmallBitmapScreenSize - pxInset; int pxY1i = pxY + Tile.SmallBitmapScreenSize - pxInset; g.DrawLine(Pens.Firebrick, pxX0i, pxY0i, pxX1i, pxY1i); g.DrawLine(Pens.Firebrick, pxX0i, pxY1i, pxX1i, pxY0i); } pxY += Tile.SmallBitmapScreenSize; } pxX += Tile.SmallBitmapScreenSize; } // Draw the grid and border. int pxTileSize = Tile.SmallBitmapScreenSize; pxX = 0; pxY = 0; int pxWidth = pxTileSize * k_nMaxMapTilesX; int pxHeight = pxTileSize * k_nMaxMapTilesY; if (Options.BackgroundMap_ShowGrid) { Pen penTileBorder = Pens.LightGray; // Draw a border around each tile. for (int i = pxX + pxTileSize; i < pxWidth; i += pxTileSize) { g.DrawLine(penTileBorder, i, pxY, i, pxHeight); } for (int i = pxY + pxTileSize; i < pxHeight; i += pxTileSize) { g.DrawLine(penTileBorder, pxX, i, pxWidth, i); } } // Draw the outer border. g.DrawRectangle(Pens.Black, pxX, pxY, pxWidth, pxHeight); if (Options.BackgroundMap_ShowScreen) { if (Options.Platform == Options.PlatformType.GBA) { pxWidth = pxTileSize * k_nGBAScreenTilesX; pxHeight = pxTileSize * k_nGBAScreenTilesY; } else { pxWidth = pxTileSize * k_nNDSScreenTilesX; pxHeight = pxTileSize * k_nNDSScreenTilesY; } g.DrawRectangle(m_penHilight, pxX, pxY, pxWidth, pxHeight); g.DrawRectangle(m_penHilight2, pxX, pxY, pxWidth, pxHeight); } // Draw a border around the current background "sprite". Sprite spriteSelected = m_ss.CurrentSprite; if (m_tileSpriteX != -1 && m_tileSpriteY != -1 && spriteSelected != null) { pxX = m_tileSpriteX * pxTileSize; pxY = m_tileSpriteY * pxTileSize; pxWidth = spriteSelected.TileWidth * pxTileSize; pxHeight = spriteSelected.TileHeight * pxTileSize; g.DrawRectangle(m_penHilight, pxX, pxY, pxWidth, pxHeight); g.DrawRectangle(m_penHilight2, pxX, pxY, pxWidth, pxHeight); } }