26 #import "PascalImports.h" |
26 #import "PascalImports.h" |
27 |
27 |
28 #define BTNS_PER_ROW 9 |
28 #define BTNS_PER_ROW 9 |
29 |
29 |
30 @implementation AmmoMenuViewController |
30 @implementation AmmoMenuViewController |
31 @synthesize imagesArray, buttonsArray, isVisible; |
31 @synthesize imagesArray, buttonsArray, nameLabel, extraLabel, captionLabel, isVisible; |
32 |
32 |
33 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
33 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
34 return rotationManager(interfaceOrientation); |
34 return rotationManager(interfaceOrientation); |
35 } |
35 } |
36 |
36 |
85 self.isVisible = NO; |
85 self.isVisible = NO; |
86 } |
86 } |
87 |
87 |
88 #pragma mark - |
88 #pragma mark - |
89 #pragma mark drawing |
89 #pragma mark drawing |
|
90 -(void) prepareLabels { |
|
91 int x = 12; |
|
92 int y = (HW_getNumberOfWeapons()/BTNS_PER_ROW)*44 + 18; |
|
93 UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(x, y, 200, 20)]; |
|
94 name.backgroundColor = [UIColor clearColor]; |
|
95 name.textColor = UICOLOR_HW_YELLOW_BODER; |
|
96 name.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
|
97 self.nameLabel = name; |
|
98 [self.view addSubview:self.nameLabel]; |
|
99 [name release]; |
|
100 |
|
101 UILabel *caption = [[UILabel alloc] initWithFrame:CGRectMake(x+200, y, 220, 20)]; |
|
102 caption.backgroundColor = [UIColor clearColor]; |
|
103 caption.textColor = [UIColor whiteColor]; |
|
104 caption.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize]]; |
|
105 caption.adjustsFontSizeToFitWidth = YES; |
|
106 caption.minimumFontSize = 8; |
|
107 self.captionLabel = caption; |
|
108 [self.view addSubview:self.captionLabel]; |
|
109 [caption release]; |
|
110 |
|
111 UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(x+2, y+20, 410, 53)]; |
|
112 description.backgroundColor = [UIColor clearColor]; |
|
113 description.textColor = [UIColor whiteColor]; |
|
114 description.font = [UIFont italicSystemFontOfSize:[UIFont systemFontSize]]; |
|
115 description.adjustsFontSizeToFitWidth = YES; |
|
116 description.minimumFontSize = 8; |
|
117 description.numberOfLines = 0; |
|
118 self.extraLabel = description; |
|
119 [self.view addSubview:self.extraLabel]; |
|
120 [description release]; |
|
121 } |
|
122 |
90 -(void) loadAmmoStuff:(id) object { |
123 -(void) loadAmmoStuff:(id) object { |
91 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
124 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
92 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
125 NSString *str = [NSString stringWithFormat:@"%@/AmmoMenu/Ammos.png",GRAPHICS_DIRECTORY()]; |
93 UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
126 UIImage *ammoStoreImage = [[UIImage alloc] initWithContentsOfFile:str]; |
94 |
127 |
122 button.layer.borderWidth = w; |
155 button.layer.borderWidth = w; |
123 [button.layer setCornerRadius:radius]; |
156 [button.layer setCornerRadius:radius]; |
124 [button.layer setMasksToBounds:YES]; |
157 [button.layer setMasksToBounds:YES]; |
125 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown]; |
158 [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchDown]; |
126 [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside]; |
159 [button addTarget:self action:@selector(buttonReleased:) forControlEvents:UIControlEventTouchUpInside]; |
|
160 [button addTarget:self action:@selector(buttonCancel:) forControlEvents:UIControlEventTouchUpOutside|UIControlEventTouchCancel]; |
127 [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
161 [button setTitleColor:UICOLOR_HW_YELLOW_TEXT forState:UIControlStateNormal]; |
128 button.titleLabel.backgroundColor = [UIColor blackColor]; |
162 button.titleLabel.backgroundColor = [UIColor blackColor]; |
129 button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
163 button.titleLabel.font = [UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]; |
130 [button.titleLabel.layer setCornerRadius:3]; |
164 [button.titleLabel.layer setCornerRadius:3]; |
131 [button.titleLabel.layer setMasksToBounds:YES]; |
165 [button.titleLabel.layer setMasksToBounds:YES]; |
208 loadout = NULL; |
242 loadout = NULL; |
209 } |
243 } |
210 |
244 |
211 #pragma mark - |
245 #pragma mark - |
212 #pragma mark user interaction |
246 #pragma mark user interaction |
213 -(void) buttonPressed:(id) sender { |
247 -(void) buttonPressed:(id) sender { |
214 UIButton *theButton = (UIButton *)sender; |
248 UIButton *theButton = (UIButton *)sender; |
215 if (theButton.currentTitle != nil) { |
249 if (self.nameLabel == nil || self.extraLabel == nil) |
216 DLog(@"eeee"); |
250 [self prepareLabels]; |
217 } |
251 |
|
252 self.nameLabel.text = [NSString stringWithUTF8String:HW_getWeaponNameByIndex(theButton.tag)]; |
|
253 // description contains a lot of unnecessary stuff, we clean it by removing .|, !| and ?| |
|
254 NSString *description = [NSString stringWithUTF8String:HW_getWeaponDescriptionByIndex(theButton.tag)]; |
|
255 NSArray *elements = [description componentsSeparatedByString:@".|"]; |
|
256 NSArray *purgedElements = [[elements objectAtIndex:0] componentsSeparatedByString:@"!|"]; |
|
257 NSArray *morePurgedElements = [[purgedElements objectAtIndex:0] componentsSeparatedByString:@"?|"]; |
|
258 self.extraLabel.text = [[[morePurgedElements objectAtIndex:0] stringByReplacingOccurrencesOfString:@"|" withString:@" "] stringByAppendingString:@"."]; |
|
259 if (theButton.currentTitle != nil) |
|
260 self.captionLabel.text = NSLocalizedString(@"This weapon is locked",@""); |
|
261 else |
|
262 self.captionLabel.text = [NSString stringWithUTF8String:HW_getWeaponCaptionByIndex(theButton.tag)]; |
|
263 } |
|
264 |
|
265 -(void) buttonCancel:(id) sender { |
|
266 self.nameLabel.text = nil; |
|
267 self.extraLabel.text = nil; |
|
268 self.captionLabel.text = nil; |
218 } |
269 } |
219 |
270 |
220 -(void) buttonReleased:(id) sender { |
271 -(void) buttonReleased:(id) sender { |
221 UIButton *theButton = (UIButton *)sender; |
272 UIButton *theButton = (UIButton *)sender; |
|
273 if (self.nameLabel == nil || self.extraLabel == nil) |
|
274 [self prepareLabels]; |
|
275 |
|
276 self.nameLabel.text = nil; |
|
277 self.extraLabel.text = nil; |
|
278 self.captionLabel.text = nil; |
222 if (theButton.currentTitle == nil) { |
279 if (theButton.currentTitle == nil) { |
223 HW_setWeapon(theButton.tag); |
280 HW_setWeapon(theButton.tag); |
224 playSound(@"clickSound"); |
281 playSound(@"clickSound"); |
225 } |
282 } |
226 if (IS_DUALHEAD() == NO) |
283 if (IS_DUALHEAD() == NO) |
265 #pragma mark - |
322 #pragma mark - |
266 #pragma mark memory |
323 #pragma mark memory |
267 -(void) didReceiveMemoryWarning { |
324 -(void) didReceiveMemoryWarning { |
268 self.imagesArray = nil; |
325 self.imagesArray = nil; |
269 self.buttonsArray = nil; |
326 self.buttonsArray = nil; |
|
327 self.nameLabel = nil; |
|
328 self.extraLabel = nil; |
|
329 self.captionLabel = nil; |
270 MSG_MEMCLEAN(); |
330 MSG_MEMCLEAN(); |
271 [super didReceiveMemoryWarning]; |
331 [super didReceiveMemoryWarning]; |
272 } |
332 } |
273 |
333 |
274 -(void) viewDidUnload { |
334 -(void) viewDidUnload { |
275 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
335 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
276 self.imagesArray = nil; |
336 self.imagesArray = nil; |
277 self.buttonsArray = nil; |
337 self.buttonsArray = nil; |
|
338 self.nameLabel = nil; |
|
339 self.extraLabel = nil; |
|
340 self.captionLabel = nil; |
278 free(delay); |
341 free(delay); |
279 delay = NULL; |
342 delay = NULL; |
280 free(shouldUpdateImage); |
343 free(shouldUpdateImage); |
281 shouldUpdateImage = NULL; |
344 shouldUpdateImage = NULL; |
282 MSG_DIDUNLOAD(); |
345 MSG_DIDUNLOAD(); |
283 [super viewDidUnload]; |
346 [super viewDidUnload]; |
284 } |
347 } |
285 |
348 |
286 -(void) dealloc { |
349 -(void) dealloc { |
|
350 [nameLabel release]; |
|
351 [extraLabel release]; |
|
352 [captionLabel release]; |
287 [imagesArray release]; |
353 [imagesArray release]; |
288 [buttonsArray release]; |
354 [buttonsArray release]; |
289 [super dealloc]; |
355 [super dealloc]; |
290 } |
356 } |
291 |
357 |