/* BWOverWorld */

#import <Cocoa/Cocoa.h>

struct sArea
{
	unsigned char x;
	unsigned char y;
	unsigned char z;
	unsigned char w;
};

@interface BWOverWorld : NSMatrix
{
	IBOutlet id objMain;
	
    IBOutlet id matrixTiles;
	IBOutlet id matrixTools;
	IBOutlet id scrollView;
	
	IBOutlet id textPosition;
	IBOutlet id textGroups;
	IBOutlet id fieldGroupsMax;
	
	IBOutlet id menuRegion;
	IBOutlet id menuArea;
	
	IBOutlet id fieldMap;
	IBOutlet id fieldWorld;
	IBOutlet id fieldEnter;
	IBOutlet id matrixFlags;
	
	IBOutlet id matrixPalettes;
	IBOutlet id matrixPalettesTiles;
	IBOutlet id matrixColors;
	IBOutlet id windowColors;
	IBOutlet id boxColor;
	
	NSMutableData *rom;
	NSMutableArray *tiles;
	unsigned const char *ptr;
	
	char currentTool;
	char currentTile;
	unsigned char sr;
	unsigned char cr;			// Current Region (WH, DM, EH, MI)
	
	int sel;		// Current selected area (-1 for Show All)
	
	struct sArea keyAreas[0x3F][4];
	
	unsigned int offSet;
	unsigned short offSetPalaces;
	unsigned short maxGroups[4];
	
	unsigned short g[4];						// Current number of groups for each region
	unsigned char overworldData[4][0x400];		// Current map data for each region
	unsigned char overworldGrid[4][0x10000];	// Current matrix data for each region
	unsigned char brackets[4][0x10000];
	
	unsigned char palettes[0x10];
	unsigned char palettesCodes[0x10];
	unsigned char selPalette;					// Selected Palette
	unsigned char selColor;						// Selected Color
	
	BOOL useDefaultTiles;
	BOOL showGrid;
}

- (void)open:(NSMutableData *)theRom;
- (void)save;

- (void)loadPalettes;
- (void)loadTiles;
- (void)loadPalettesWindow;
- (void)loadRegions;
- (void)loadAreas;

- (NSImage *)tileWithOffset:(int)os palette:(struct sCol *)pal data:(NSData *)data;
- (NSImage *)graphicWithTiles:(NSArray *)tilesList type:(unsigned char)size;

- (IBAction)changeRegion:(id)sender;
- (IBAction)changeArea:(id)sender;

- (IBAction)changeTile:(id)sender;
- (IBAction)changeTool:(id)sender;
- (IBAction)actionMaxGroups:(id)sender;
- (IBAction)actionFields:(id)sender;
- (IBAction)actionFlags:(id)sender;

- (IBAction)changeSelectedPalette:(id)sender;
- (IBAction)changeColor:(id)sender;
- (IBAction)changePaletteCode:(id)sender;

- (void)changeTileWithTag:(int)tag;
- (void)recalculate;
- (void)palacePointers;

- (IBAction)exportRegion:(id)sender;

- (unsigned int)stringToHex:(NSString *)str;
- (NSString *)hexToString:(unsigned int)hex;

@end
