5 // Created by Killery on 2012/12/15.
6 // Copyright (c) 2012年 Killery. All rights reserved.
11 @implementation ChipView
13 - (id)initWithFrame:(NSRect)frame
15 self = [super initWithFrame:frame];
19 scheduledTimerWithTimeInterval:1.0/30
21 selector:@selector(EventLoop:)
28 chip = [[self LoadImage:@"マス.png"] retain];
29 chip2 = [[self LoadImage:@"セレクター.png"] retain];
30 chipA = [[self LoadImage:@"cc旗青.png"] retain];
31 chipB = [[self LoadImage:@"cc旗青2.png"] retain];
32 chipC = [[self LoadImage:@"cc旗赤.png"] retain];
33 chipD = [[self LoadImage:@"cc旗赤2.png"] retain];
34 chipE = [[self LoadImage:@"cc旗黄.png"] retain];
35 chipF = [[self LoadImage:@"cc旗黄2.png"] retain];
36 chipa = [[self LoadImage:@"ccはた青.png"] retain];
37 chipb = [[self LoadImage:@"ccはた青2.png"] retain];
38 chipc = [[self LoadImage:@"ccはた赤.png"] retain];
39 chipd = [[self LoadImage:@"ccはた赤2.png"] retain];
40 chipe = [[self LoadImage:@"ccはた黄.png"] retain];
41 chipf = [[self LoadImage:@"ccはた黄2.png"] retain];
44 seRect.size.height = 20*32;
45 seRect.size.width = 20*32;
51 -(void)EventLoopChipView{
53 SLindex = (SLy*3 + SLx)+(MapChipListIndex-1)*24;
54 SLindexB = (SLy*3 + SLx)+(BuildChipListIndex-1)*24;
55 SLindexU = (SLy*3 + SLx)+(UnitChipListIndex-1)*24;
56 SLindexL = (SLy*3 + SLx)+(LoadChipListIndex-1)*24;
58 [self setNeedsDisplay:YES];
65 -(NSImage*)LoadImage:(NSString*)name{
66 NSImage *image = [NSImage imageNamed:name];
67 if(image == nil) return nil;
68 //[image setFlipped:[self isFlipped]];
72 -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y cx:(int)cx cy:(int)cy{
74 frRect.size.height = image.size.height;
75 frRect.size.width = image.size.width;
83 drRect.size.height = 32;
84 drRect.size.width = 32;
86 [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
90 -(void)mouseDown:(NSEvent *)theEvent{
91 selectPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
93 SLx = (int)selectPoint.x/32;
94 SLy = (int)selectPoint.y/32;
96 CommandSelected = false;
100 - (void)drawRect:(NSRect)dirtyRect
105 if(SLCy == 1 && SLSx == 0){
108 [self DrawImage:chip x:bx*32 y:by*32 cx:bx cy:by];
109 [self DrawImage:chipa x:0*32 y:0*32 cx:bx cy:by];
110 [self DrawImage:chipb x:1*32 y:0*32 cx:bx cy:by];
111 [self DrawImage:chipc x:2*32 y:0*32 cx:bx cy:by];
112 [self DrawImage:chipd x:0*32 y:1*32 cx:bx cy:by];
113 [self DrawImage:chipe x:1*32 y:1*32 cx:bx cy:by];
114 [self DrawImage:chipf x:2*32 y:1*32 cx:bx cy:by];
117 }else if(SLCy == 2 && SLSx == 0){
120 [self DrawImage:chip x:bx*32 y:by*32 cx:bx cy:by];
121 [self DrawImage:chipA x:0*32 y:0*32 cx:bx cy:by];
122 [self DrawImage:chipB x:1*32 y:0*32 cx:bx cy:by];
123 [self DrawImage:chipC x:2*32 y:0*32 cx:bx cy:by];
124 [self DrawImage:chipD x:0*32 y:1*32 cx:bx cy:by];
125 [self DrawImage:chipE x:1*32 y:1*32 cx:bx cy:by];
126 [self DrawImage:chipF x:2*32 y:1*32 cx:bx cy:by];
129 }else if (SLSx == 0) {
132 [self DrawImage:chip x:bx*32 y:by*32 cx:bx cy:by];
133 NSImage *MCI = MC[(by*3 + bx)+(MapChipListIndex-1)*24].img;
134 //[MCI setFlipped:[self isFlipped]];
135 [self DrawImage:MCI x:bx*32 y:by*32 cx:bx cy:by];
141 [self DrawImage:chip x:bx*32 y:by*32 cx:bx cy:by];
142 NSImage *BCI = BC[(by*3 + bx)+(BuildChipListIndex-1)*24].img;
144 [self DrawImage:BCI x:bx*32 y:by*32 cx:bx cy:by];
150 [self DrawImage:chip x:bx*32 y:by*32 cx:bx cy:by];
151 NSImage *UCI = UC[(by*3 + bx)+(UnitChipListIndex-1)*24].img;
153 [self DrawImage:UCI x:bx*32 y:by*32 cx:bx cy:by];
159 [self DrawImage:chip x:bx*32 y:by*32 cx:bx cy:by];
160 NSImage *LCI = LC[(by*3 + bx)+(LoadChipListIndex-1)*24].img;
162 [self DrawImage:LCI x:bx*32 y:by*32 cx:bx cy:by];
168 if(!CommandSelected) [self DrawImage:chip2 x:SLx*32 y:SLy*32 cx:SLx cy:SLy];