public BattleScreen(Bitmap image, Palette[] palettes) : base(WIDTH, HEIGHT) { if (image.Width != Width || image.Height != Height) { throw new Exception("Image given has invalid dimensions, should be " + Width + "x" + Height + " pixels."); } Palettes = palettes; Graphics = new Tileset(WIDTH * HEIGHT); Tiling = new TSA_Array(WIDTH, HEIGHT); const int X_L_NAME = 1; const int X_L_WEAPON = 8; int X_R_NAME = Core.CurrentROM is FE8 ? 24 : 25; const int X_R_WEAPON = 18; const int Y_NAME = 1; const int Y_WEAPON = 8; Tile tile; byte paletteIndex; System.Drawing.Rectangle region; for (int y = 0; y < HEIGHT; y++) { for (int x = 0; x < WIDTH; x++) { if (x >= HALFWIDTH) { if ((x >= X_R_NAME && x < X_R_NAME + NAME_WIDTH && y >= Y_NAME && y < Y_NAME + 2) || (x >= X_R_WEAPON && x < X_R_WEAPON + 6 && y >= Y_WEAPON && y < Y_WEAPON + 2)) { continue; } paletteIndex = 0; } else { if ((x >= X_L_NAME && x < X_L_NAME + NAME_WIDTH && y >= Y_NAME && y < Y_NAME + 2) || (x >= X_L_WEAPON && x < X_L_WEAPON + WEAPON_WIDTH && y >= Y_WEAPON && y < Y_WEAPON + 2)) { continue; } paletteIndex = 1; } region = new System.Drawing.Rectangle(x * Tile.SIZE, y * Tile.SIZE, Tile.SIZE, Tile.SIZE); tile = new Tile(new Image(image, region, palettes[paletteIndex])); if (Graphics.Count == EMPTY_TILE) { Graphics.Add(Tile.Empty); } if (Graphics.Count == TILE_LIMIT) { for (int i = 0; TILE_LIMIT + i < TILE_LIMIT_END; i++) { Graphics.Add(Tile.Empty); } } if (Graphics.Count >= 128) { throw new Exception("Battle Screen Frame cannot have more than 128 tiles."); } if (tile.IsEmpty()) { Tiling[x, y] = new TSA(EMPTY_TILE, paletteIndex, false, false); } else { var match = Graphics.FindMatch(tile); if (match == null) { Tiling[x, y] = new TSA(Graphics.Count, paletteIndex, false, false); Graphics.Add(tile); } else { Tiling[x, y] = new TSA(match.Item1, paletteIndex, match.Item2, match.Item3); } } } } while (Graphics.Count < TILE_LIMIT_END) { Graphics.Add(Tile.Empty); } LoadSecondaryTileset(image, palettes, L_NAME_OFFSET, 1, X_L_NAME, Y_NAME, NAME_WIDTH, 2); LoadSecondaryTileset(image, palettes, L_WEAPON_OFFSET, 1, X_L_WEAPON, Y_WEAPON, WEAPON_WIDTH, 2); LoadSecondaryTileset(image, palettes, R_NAME_OFFSET, 0, X_R_NAME, Y_NAME, NAME_WIDTH, 2); LoadSecondaryTileset(image, palettes, R_WEAPON_OFFSET, 0, X_R_WEAPON, Y_WEAPON, WEAPON_WIDTH, 2); }