8 |
8 |
9 #import "WeaponCellView.h" |
9 #import "WeaponCellView.h" |
10 #import "CommodityFunctions.h" |
10 #import "CommodityFunctions.h" |
11 |
11 |
12 @implementation WeaponCellView |
12 @implementation WeaponCellView |
13 @synthesize delegate, weaponName, weaponIcon, initialQt, probabilityQt, delayQt, crateQt, |
13 @synthesize delegate, weaponName, weaponIcon, initialSli, probabilitySli, delaySli, crateSli, helpLabel, |
14 initialImg, probabImg, delayImg, crateImg, initialLab, probLab, delLab, craLab; |
14 initialImg, probabilityImg, delayImg, crateImg, initialLab, probabilityLab, delayLab, crateLab; |
15 |
15 |
16 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { |
16 -(id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { |
17 if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { |
17 if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { |
18 delegate = nil; |
18 delegate = nil; |
19 |
19 |
20 weaponName = [[UILabel alloc] init]; |
20 weaponName = [[UILabel alloc] init]; |
21 weaponName.backgroundColor = [UIColor clearColor]; |
21 weaponName.backgroundColor = [UIColor clearColor]; |
22 weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
22 weaponName.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
23 weaponIcon = [[UIImageView alloc] init]; |
23 weaponIcon = [[UIImageView alloc] init]; |
24 |
24 |
25 initialQt = [[UISlider alloc] init]; |
25 initialSli = [[UISlider alloc] init]; |
26 [initialQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
26 [initialSli addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
27 initialQt.maximumValue = 9; |
27 [initialSli addTarget:self action:@selector(startDragging:) forControlEvents:UIControlEventTouchDown]; |
28 initialQt.minimumValue = 0; |
28 [initialSli addTarget:self action:@selector(stopDragging:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; |
29 |
29 initialSli.maximumValue = 9; |
30 probabilityQt = [[UISlider alloc] init]; |
30 initialSli.minimumValue = 0; |
31 [probabilityQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
31 initialSli.tag = 100; |
32 probabilityQt.maximumValue = 9; |
32 |
33 probabilityQt.minimumValue = 0; |
33 probabilitySli = [[UISlider alloc] init]; |
34 |
34 [probabilitySli addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
35 delayQt = [[UISlider alloc] init]; |
35 [probabilitySli addTarget:self action:@selector(startDragging:) forControlEvents:UIControlEventTouchDown]; |
36 [delayQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
36 [probabilitySli addTarget:self action:@selector(stopDragging:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; |
37 delayQt.maximumValue = 9; |
37 probabilitySli.maximumValue = 9; |
38 delayQt.minimumValue = 0; |
38 probabilitySli.minimumValue = 0; |
39 |
39 probabilitySli.tag = 200; |
40 crateQt = [[UISlider alloc] init]; |
40 |
41 [crateQt addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
41 delaySli = [[UISlider alloc] init]; |
42 crateQt.maximumValue = 9; |
42 [delaySli addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
43 crateQt.minimumValue = 0; |
43 [delaySli addTarget:self action:@selector(startDragging:) forControlEvents:UIControlEventTouchDown]; |
|
44 [delaySli addTarget:self action:@selector(stopDragging:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; |
|
45 delaySli.maximumValue = 9; |
|
46 delaySli.minimumValue = 0; |
|
47 delaySli.tag = 300; |
|
48 |
|
49 crateSli = [[UISlider alloc] init]; |
|
50 [crateSli addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged]; |
|
51 [crateSli addTarget:self action:@selector(startDragging:) forControlEvents:UIControlEventTouchDown]; |
|
52 [crateSli addTarget:self action:@selector(stopDragging:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside]; |
|
53 crateSli.maximumValue = 9; |
|
54 crateSli.minimumValue = 0; |
|
55 crateSli.tag = 400; |
44 |
56 |
45 NSString *imgAmmoStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()]; |
57 NSString *imgAmmoStr = [NSString stringWithFormat:@"%@/iconAmmo.png",BTN_DIRECTORY()]; |
46 NSString *imgDamageStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()]; |
58 NSString *imgDamageStr = [NSString stringWithFormat:@"%@/iconDamage.png",BTN_DIRECTORY()]; |
47 NSString *imgTimeStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()]; |
59 NSString *imgTimeStr = [NSString stringWithFormat:@"%@/iconTime.png",BTN_DIRECTORY()]; |
48 NSString *imgBoxStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()]; |
60 NSString *imgBoxStr = [NSString stringWithFormat:@"%@/iconBox.png",BTN_DIRECTORY()]; |
49 |
61 |
50 initialImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgAmmoStr]]; |
62 initialImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgAmmoStr]]; |
51 probabImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgDamageStr]]; |
63 probabilityImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgDamageStr]]; |
52 delayImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgTimeStr]]; |
64 delayImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgTimeStr]]; |
53 crateImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgBoxStr]]; |
65 crateImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:imgBoxStr]]; |
54 |
66 |
55 initialLab = [[UILabel alloc] init]; |
67 initialLab = [[UILabel alloc] init]; |
56 initialLab.backgroundColor = [UIColor clearColor]; |
68 initialLab.backgroundColor = [UIColor clearColor]; |
57 initialLab.textColor = [UIColor grayColor]; |
69 initialLab.textColor = [UIColor grayColor]; |
58 initialLab.textAlignment = UITextAlignmentCenter; |
70 initialLab.textAlignment = UITextAlignmentCenter; |
59 |
71 |
60 probLab = [[UILabel alloc] init]; |
72 probabilityLab = [[UILabel alloc] init]; |
61 probLab.backgroundColor = [UIColor clearColor]; |
73 probabilityLab.backgroundColor = [UIColor clearColor]; |
62 probLab.textColor = [UIColor grayColor]; |
74 probabilityLab.textColor = [UIColor grayColor]; |
63 probLab.textAlignment = UITextAlignmentCenter; |
75 probabilityLab.textAlignment = UITextAlignmentCenter; |
64 |
76 |
65 delLab = [[UILabel alloc] init]; |
77 delayLab = [[UILabel alloc] init]; |
66 delLab.backgroundColor = [UIColor clearColor]; |
78 delayLab.backgroundColor = [UIColor clearColor]; |
67 delLab.textColor = [UIColor grayColor]; |
79 delayLab.textColor = [UIColor grayColor]; |
68 delLab.textAlignment = UITextAlignmentCenter; |
80 delayLab.textAlignment = UITextAlignmentCenter; |
69 |
81 |
70 craLab = [[UILabel alloc] init]; |
82 crateLab = [[UILabel alloc] init]; |
71 craLab.backgroundColor = [UIColor clearColor]; |
83 crateLab.backgroundColor = [UIColor clearColor]; |
72 craLab.textColor = [UIColor grayColor]; |
84 crateLab.textColor = [UIColor grayColor]; |
73 craLab.textAlignment = UITextAlignmentCenter; |
85 crateLab.textAlignment = UITextAlignmentCenter; |
74 |
86 |
75 [self.contentView addSubview:weaponName]; // [weaponName release]; |
87 helpLabel = [[UILabel alloc] init]; |
76 [self.contentView addSubview:weaponIcon]; // [weaponIcon release]; |
88 helpLabel.backgroundColor = [UIColor clearColor]; |
77 |
89 helpLabel.textColor = [UIColor grayColor]; |
78 [self.contentView addSubview:initialQt]; // [initialQt release]; |
90 helpLabel.textAlignment = UITextAlignmentRight; |
79 [self.contentView addSubview:probabilityQt]; // [probabilityQt release]; |
91 helpLabel.font = [UIFont italicSystemFontOfSize:[UIFont smallSystemFontSize]]; |
80 [self.contentView addSubview:delayQt]; // [delayQt release]; |
92 |
81 [self.contentView addSubview:crateQt]; // [crateQt release]; |
93 [self.contentView addSubview:weaponName]; |
82 |
94 [self.contentView addSubview:weaponIcon]; |
83 [self.contentView addSubview:initialImg]; // [initialImg release]; |
95 |
84 [self.contentView addSubview:probabImg]; // [probabImg release]; |
96 [self.contentView addSubview:initialSli]; |
85 [self.contentView addSubview:delayImg]; // [delayImg release]; |
97 [self.contentView addSubview:probabilitySli]; |
86 [self.contentView addSubview:crateImg]; // [crateImg release]; |
98 [self.contentView addSubview:delaySli]; |
87 |
99 [self.contentView addSubview:crateSli]; |
88 [self.contentView addSubview:initialLab]; // [initialLab release]; |
100 |
89 [self.contentView addSubview:probLab]; // [probLab release]; |
101 [self.contentView addSubview:initialImg]; |
90 [self.contentView addSubview:delLab]; // [delLab release]; |
102 [self.contentView addSubview:probabilityImg]; |
91 [self.contentView addSubview:craLab]; // [craLab release]; |
103 [self.contentView addSubview:delayImg]; |
|
104 [self.contentView addSubview:crateImg]; |
|
105 |
|
106 [self.contentView addSubview:initialLab]; |
|
107 [self.contentView addSubview:probabilityLab]; |
|
108 [self.contentView addSubview:delayLab]; |
|
109 [self.contentView addSubview:crateLab]; |
|
110 |
|
111 [self.contentView addSubview:helpLabel]; |
92 } |
112 } |
93 return self; |
113 return self; |
94 } |
114 } |
95 |
115 |
96 -(void) layoutSubviews { |
116 -(void) layoutSubviews { |
97 [super layoutSubviews]; |
117 [super layoutSubviews]; |
98 |
118 |
99 CGRect contentRect = self.contentView.bounds; |
119 CGRect contentRect = self.contentView.bounds; |
100 CGFloat boundsX = contentRect.origin.x; |
120 CGFloat shiftSliders = contentRect.origin.x; |
101 |
121 CGFloat shiftLabel = 0; |
102 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) |
122 |
103 boundsX += 65; |
123 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
104 else |
124 shiftSliders += 65; |
105 boundsX -= 9; |
125 shiftLabel += 165; |
|
126 } else |
|
127 shiftSliders -= 13; |
106 |
128 |
107 weaponIcon.frame = CGRectMake(5, 5, 32, 32); |
129 weaponIcon.frame = CGRectMake(5, 5, 32, 32); |
108 weaponName.frame = CGRectMake(45, 8, 200, 25); |
130 weaponName.frame = CGRectMake(45, 8, 200, 25); |
|
131 |
|
132 helpLabel.frame = CGRectMake(shiftLabel + 200, 8, 250, 15); |
109 |
133 |
110 // second line |
134 // second line |
111 initialImg.frame = CGRectMake(boundsX+20, 40, 32, 32); |
135 initialImg.frame = CGRectMake(shiftSliders + 20, 40, 32, 32); |
112 initialLab.frame = CGRectMake(boundsX+56, 40, 20, 32); |
136 initialLab.frame = CGRectMake(shiftSliders + 56, 40, 20, 32); |
113 initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value]; |
137 initialLab.text = ((int)initialSli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialSli.value]; |
114 initialQt.frame = CGRectMake(boundsX+80, 40, 150, 32); |
138 initialSli.frame = CGRectMake(shiftSliders + 80, 40, 150, 32); |
115 |
139 |
116 probabImg.frame = CGRectMake(boundsX+255, 40, 32, 32); |
140 probabilityImg.frame = CGRectMake(shiftSliders + 255, 40, 32, 32); |
117 probLab.frame = CGRectMake(boundsX+291, 40, 20, 32); |
141 probabilityLab.frame = CGRectMake(shiftSliders + 291, 40, 20, 32); |
118 probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value]; |
142 probabilityLab.text = ((int)probabilitySli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilitySli.value]; |
119 probabilityQt.frame = CGRectMake(boundsX+314, 40, 150, 32); |
143 probabilitySli.frame = CGRectMake(shiftSliders + 314, 40, 150, 32); |
120 |
144 |
121 // third line |
145 // third line |
122 delayImg.frame = CGRectMake(boundsX+20, 80, 32, 32); |
146 delayImg.frame = CGRectMake(shiftSliders + 20, 80, 32, 32); |
123 delLab.frame = CGRectMake(boundsX+56, 80, 20, 32); |
147 delayLab.frame = CGRectMake(shiftSliders + 56, 80, 20, 32); |
124 delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value]; |
148 delayLab.text = ((int)delaySli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delaySli.value]; |
125 delayQt.frame = CGRectMake(boundsX+80, 80, 150, 32); |
149 delaySli.frame = CGRectMake(shiftSliders + 80, 80, 150, 32); |
126 |
150 |
127 crateImg.frame = CGRectMake(boundsX+255, 80, 32, 32); |
151 crateImg.frame = CGRectMake(shiftSliders + 255, 80, 32, 32); |
128 craLab.frame = CGRectMake(boundsX+291, 80, 20, 32); |
152 crateLab.frame = CGRectMake(shiftSliders + 291, 80, 20, 32); |
129 craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value]; |
153 crateLab.text = ((int)crateSli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateSli.value]; |
130 crateQt.frame = CGRectMake(boundsX+314, 80, 150, 32); |
154 crateSli.frame = CGRectMake(shiftSliders + 314, 80, 150, 32); |
131 } |
155 } |
132 |
156 |
133 /* |
157 /* |
134 -(void) setSelected:(BOOL)selected animated:(BOOL)animated { |
158 -(void) setSelected:(BOOL)selected animated:(BOOL)animated { |
135 [super setSelected:selected animated:animated]; |
159 [super setSelected:selected animated:animated]; |
137 } |
161 } |
138 */ |
162 */ |
139 |
163 |
140 -(void) valueChanged:(id) sender { |
164 -(void) valueChanged:(id) sender { |
141 if (self.delegate != nil) { |
165 if (self.delegate != nil) { |
142 initialLab.text = ((int)initialQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialQt.value]; |
166 initialLab.text = ((int)initialSli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)initialSli.value]; |
143 probLab.text = ((int)probabilityQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilityQt.value]; |
167 probabilityLab.text = ((int)probabilitySli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)probabilitySli.value]; |
144 delLab.text = ((int)delayQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delayQt.value]; |
168 delayLab.text = ((int)delaySli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)delaySli.value]; |
145 craLab.text = ((int)crateQt.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateQt.value]; |
169 crateLab.text = ((int)crateSli.value == 9) ? @"∞" : [NSString stringWithFormat:@"%d",(int)crateSli.value]; |
146 |
170 |
147 [delegate updateValues:[NSArray arrayWithObjects: |
171 [delegate updateValues:[NSArray arrayWithObjects: |
148 [NSNumber numberWithInt:(int)initialQt.value], |
172 [NSNumber numberWithInt:(int)initialSli.value], |
149 [NSNumber numberWithInt:(int)probabilityQt.value], |
173 [NSNumber numberWithInt:(int)probabilitySli.value], |
150 [NSNumber numberWithInt:(int)delayQt.value], |
174 [NSNumber numberWithInt:(int)delaySli.value], |
151 [NSNumber numberWithInt:(int)crateQt.value], nil] |
175 [NSNumber numberWithInt:(int)crateSli.value], nil] |
152 atIndex:self.tag]; |
176 atIndex:self.tag]; |
153 } else |
177 } else |
154 DLog(@"error - delegate = nil!"); |
178 DLog(@"error - delegate = nil!"); |
|
179 } |
|
180 |
|
181 -(void) startDragging:(id) sender { |
|
182 UISlider *slider = (UISlider *)sender; |
|
183 NSString *str = nil; |
|
184 |
|
185 switch (slider.tag) { |
|
186 case 100: |
|
187 str = NSLocalizedString(@"Initial quantity ",@"ammo selection"); |
|
188 break; |
|
189 case 200: |
|
190 str = NSLocalizedString(@"Presence probability in crates ",@"ammo selection"); |
|
191 break; |
|
192 case 300: |
|
193 str = NSLocalizedString(@"Number of turns before you can use it ",@"ammo selection"); |
|
194 break; |
|
195 case 400: |
|
196 str = NSLocalizedString(@"Quantity that you will find in a crate ",@"ammo selection"); |
|
197 break; |
|
198 default: |
|
199 DLog(@"Nope"); |
|
200 break; |
|
201 } |
|
202 self.helpLabel.text = str; |
|
203 } |
|
204 |
|
205 -(void) stopDragging:(id) sender { |
|
206 self.helpLabel.text =@""; |
155 } |
207 } |
156 |
208 |
157 -(void) dealloc { |
209 -(void) dealloc { |
158 self.delegate = nil; |
210 self.delegate = nil; |
159 releaseAndNil(weaponName); |
211 releaseAndNil(weaponName); |
160 releaseAndNil(weaponIcon); |
212 releaseAndNil(weaponIcon); |
161 releaseAndNil(initialQt); |
213 releaseAndNil(initialSli); |
162 releaseAndNil(probabilityQt); |
214 releaseAndNil(probabilitySli); |
163 releaseAndNil(delayQt); |
215 releaseAndNil(delaySli); |
164 releaseAndNil(crateQt); |
216 releaseAndNil(crateSli); |
165 releaseAndNil(initialImg); |
217 releaseAndNil(initialImg); |
166 releaseAndNil(probabImg); |
218 releaseAndNil(probabilityImg); |
167 releaseAndNil(delayImg); |
219 releaseAndNil(delayImg); |
168 releaseAndNil(crateImg); |
220 releaseAndNil(crateImg); |
169 releaseAndNil(initialLab); |
221 releaseAndNil(initialLab); |
170 releaseAndNil(probLab); |
222 releaseAndNil(probabilityLab); |
171 releaseAndNil(delLab); |
223 releaseAndNil(delayLab); |
172 releaseAndNil(craLab); |
224 releaseAndNil(crateLab); |
173 [super dealloc]; |
225 [super dealloc]; |
174 } |
226 } |
175 |
227 |
176 @end |
228 @end |