//
//  BWEnemyCell.m
//  ZIIGameEditor
//
//  Created by Simon on 28/02/16.
//  Copyright (c) 2016 Trax. All rights reserved.
//

#import "BWEnemyMatrix.h"
#import "BWSideView.h"

@implementation BWEnemyMatrix

- (void)awakeFromNib
{
	lastIndex = -1;
	
	NSTrackingAreaOptions options = (NSTrackingActiveAlways | NSTrackingInVisibleRect | NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved);
	NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:options owner:self userInfo:nil];
	[self addTrackingArea:area];
}

- (void)mouseMoved:(NSEvent *)event
{
	NSInteger r,c;
	NSInteger cellIndex;
	BOOL hit;
	NSPoint mc = [self convertPoint:[[self window] mouseLocationOutsideOfEventStream] fromView:[[self window] contentView]];
	
	hit = [self getRow:&r column:&c forPoint:mc];
	cellIndex = ((r * [self numberOfColumns]) + c);
	
	if (hit == NO || cellIndex > 0x23) {
		lastIndex = -1;
		[fieldEnemyName setStringValue:@""];
		return;
	}
	
	if (lastIndex == cellIndex) return;
	
	lastIndex = cellIndex;
	
	NSString *name = [objSideView getEnemyName:cellIndex world:[objSideView currentWorld]];
	[fieldEnemyName setStringValue:name];
}

- (void)mouseExited:(NSEvent *)event
{
	lastIndex = -1;
	[fieldEnemyName setStringValue:@""];
}

@end
