OSDN Git Service

ver0.631
[awarsiii/AwarsIV.git] / Awars III / ChipView.m
1 //
2 //  ChipView.m
3 //  Awars III
4 //
5 //  Created by Killery on 2012/12/15.
6 //  Copyright (c) 2012年 Killery. All rights reserved.
7 //
8
9 #import "ChipView.h"
10
11 @implementation ChipView
12
13 - (id)initWithFrame:(NSRect)frame
14 {
15     self = [super initWithFrame:frame];
16     if (self) {
17         /*
18         time  = [NSTimer
19                  scheduledTimerWithTimeInterval:1.0/30
20                  target:self
21                  selector:@selector(EventLoop:)
22                  userInfo:nil
23                  repeats:YES
24                  ];*/
25         
26         ChipViewInst = self;
27         
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];
42         
43         NSRect seRect;
44         seRect.size.height = 20*32;
45         seRect.size.width = 20*32;
46     }
47     
48     return self;
49 }
50
51 -(void)EventLoopChipView{
52     
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;
57     
58     [self setNeedsDisplay:YES];
59 }
60
61 -(BOOL)isFlipped{
62     return YES;
63 }
64
65 -(NSImage*)LoadImage:(NSString*)name{
66     NSImage *image = [NSImage imageNamed:name];
67     if(image == nil) return nil;
68     //[image setFlipped:[self isFlipped]];
69     
70     return image;
71 }
72 -(void)DrawImage:(NSImage*)image x:(float)x y:(float)y cx:(int)cx cy:(int)cy{
73     NSRect frRect;
74     frRect.size.height = image.size.height;
75     frRect.size.width = image.size.width;
76     
77     frRect.origin.x = 0;
78     frRect.origin.y = 0;
79     
80     NSRect drRect;
81     drRect.origin.x = x;
82     drRect.origin.y = y;
83     drRect.size.height = 32;
84     drRect.size.width = 32;
85     
86     [image drawInRect:drRect fromRect:frRect operation:NSCompositeSourceOver fraction:1.0f respectFlipped:YES hints:nil];
87     
88 }
89
90 -(void)mouseDown:(NSEvent *)theEvent{
91     selectPoint = [self convertPoint:[theEvent locationInWindow] fromView:nil];
92     
93     SLx = (int)selectPoint.x/32;
94     SLy = (int)selectPoint.y/32;
95     
96     CommandSelected = false;
97     
98 }
99
100 - (void)drawRect:(NSRect)dirtyRect
101 {
102     int bx, by;
103     
104     
105     if(SLCy == 1 && SLSx == 0){
106         for(bx=0;bx<3;bx++){
107             for(by=0;by<8;by++){
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];
115             }
116         }
117     }else if(SLCy == 2 && SLSx == 0){
118         for(bx=0;bx<3;bx++){
119             for(by=0;by<8;by++){
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];
127             }
128         }
129     }else if (SLSx == 0) {
130     for(bx=0;bx<3;bx++){
131         for(by=0;by<8;by++){
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];
136         }
137     }
138     }else if(SLSx == 1){
139         for(bx=0;bx<3;bx++){
140             for(by=0;by<8;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;
143                 
144                 [self DrawImage:BCI x:bx*32 y:by*32 cx:bx cy:by];
145             }
146         }
147     }else if(SLSx == 2){
148         for(bx=0;bx<3;bx++){
149             for(by=0;by<8;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;
152                 
153                 [self DrawImage:UCI x:bx*32 y:by*32 cx:bx cy:by];
154             }
155         }
156     }else if(SLSx == 3){
157     for(bx=0;bx<3;bx++){
158         for(by=0;by<8;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;
161             
162             [self DrawImage:LCI x:bx*32 y:by*32 cx:bx cy:by];
163             }
164         }
165     }
166
167
168     if(!CommandSelected) [self DrawImage:chip2 x:SLx*32 y:SLy*32 cx:SLx cy:SLy];
169 }
170
171 @end