12 #import "VoicesViewController.h" |
12 #import "VoicesViewController.h" |
13 #import "FortsViewController.h" |
13 #import "FortsViewController.h" |
14 #import "FlagsViewController.h" |
14 #import "FlagsViewController.h" |
15 #import "LevelViewController.h" |
15 #import "LevelViewController.h" |
16 #import "CommodityFunctions.h" |
16 #import "CommodityFunctions.h" |
|
17 #import "UIImageExtra.h" |
17 |
18 |
18 #define TEAMNAME_TAG 1234 |
19 #define TEAMNAME_TAG 1234 |
19 |
20 |
20 @implementation SingleTeamViewController |
21 @implementation SingleTeamViewController |
21 @synthesize teamDictionary, hatArray, secondaryItems, textFieldBeingEdited, teamName; |
22 @synthesize teamDictionary, hatArray, secondaryItems, textFieldBeingEdited, teamName; |
130 |
131 |
131 self.teamName = self.title; |
132 self.teamName = self.title; |
132 |
133 |
133 // load the images of the hat for aach hog |
134 // load the images of the hat for aach hog |
134 NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; |
135 NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; |
135 UIImage *normalHogImage = [[UIImage alloc] initWithContentsOfFile:normalHogFile]; |
136 UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)]; |
136 [normalHogFile release]; |
137 [normalHogFile release]; |
137 CGRect hogSpriteArea = CGRectMake(96, 0, 32, 32); |
|
138 CGImageRef cgImg = CGImageCreateWithImageInRect([normalHogImage CGImage], hogSpriteArea); |
|
139 [normalHogImage release]; |
|
140 UIImage *normalHogSprite = [[UIImage alloc] initWithCGImage:cgImg]; |
|
141 CGImageRelease(cgImg); |
|
142 |
138 |
143 NSArray *hogArray = [self.teamDictionary objectForKey:@"hedgehogs"]; |
139 NSArray *hogArray = [self.teamDictionary objectForKey:@"hedgehogs"]; |
144 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[hogArray count]]; |
140 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[hogArray count]]; |
145 for (NSDictionary *hog in hogArray) { |
141 for (NSDictionary *hog in hogArray) { |
146 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png",HATS_DIRECTORY(),[hog objectForKey:@"hat"]]; |
142 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png",HATS_DIRECTORY(),[hog objectForKey:@"hat"]]; |
147 |
143 |
148 UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile]; |
144 UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile andCutAt:CGRectMake(0, 0, 32, 32)]; |
149 [hatFile release]; |
145 [hatFile release]; |
150 CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32); |
|
151 CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea); |
|
152 [image release]; |
|
153 |
146 |
154 UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage]; |
147 [array addObject:[normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, -5)]]; |
155 CGImageRelease(cgImgage); |
|
156 |
|
157 [array addObject:mergeHogHatSprites(normalHogSprite, hatSprite)]; |
|
158 [hatSprite release]; |
148 [hatSprite release]; |
159 } |
149 } |
160 [normalHogSprite release]; |
150 [normalHogSprite release]; |
161 self.hatArray = array; |
151 self.hatArray = array; |
162 [array release]; |
152 [array release]; |
311 } |
302 } |
312 |
303 |
313 cell.textLabel.text = [self.secondaryItems objectAtIndex:row]; |
304 cell.textLabel.text = [self.secondaryItems objectAtIndex:row]; |
314 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
305 cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; |
315 switch (row) { |
306 switch (row) { |
|
307 case 0: // grave |
|
308 accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png", |
|
309 GRAVES_DIRECTORY(),[teamDictionary objectForKey:@"grave"]] |
|
310 andCutAt:CGRectMake(0,0,32,32)]; |
|
311 cell.imageView.image = accessoryImage; |
|
312 [accessoryImage release]; |
|
313 break; |
|
314 case 2: // fort |
|
315 accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@L.png", |
|
316 FORTS_DIRECTORY(),[teamDictionary objectForKey:@"fort"]]]; |
|
317 cell.imageView.image = [accessoryImage scaleToSize:CGSizeMake(42, 42)]; |
|
318 [accessoryImage release]; |
|
319 break; |
|
320 |
316 case 3: // flags |
321 case 3: // flags |
317 cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png", |
322 accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png", |
318 FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]]; |
323 FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]]; |
|
324 cell.imageView.image = accessoryImage; |
|
325 [accessoryImage release]; |
|
326 break; |
|
327 case 4: // level |
|
328 accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%d.png", |
|
329 BOTLEVELS_DIRECTORY(),[[[[teamDictionary objectForKey:@"hedgehogs"] |
|
330 objectAtIndex:0] objectForKey:@"level"] |
|
331 intValue]]]; |
|
332 cell.imageView.image = accessoryImage; |
|
333 [accessoryImage release]; |
319 break; |
334 break; |
320 default: |
335 default: |
321 cell.imageView.image = nil; |
336 cell.imageView.image = nil; |
322 break; |
337 break; |
323 } |
338 } |
334 NSInteger row = [indexPath row]; |
349 NSInteger row = [indexPath row]; |
335 NSInteger section = [indexPath section]; |
350 NSInteger section = [indexPath section]; |
336 UITableViewController *nextController; |
351 UITableViewController *nextController; |
337 UITableViewCell *cell; |
352 UITableViewCell *cell; |
338 |
353 |
339 switch (section) { |
354 if (2 == section) { |
340 case 2: //secondary items |
355 switch (row) { |
341 switch (row) { |
356 case 0: // grave |
342 case 0: // grave |
357 if (nil == gravesViewController) |
343 if (nil == gravesViewController) |
358 gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
344 gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
359 |
345 |
360 nextController = gravesViewController; |
346 nextController = gravesViewController; |
361 break; |
347 break; |
362 case 1: // voice |
348 case 1: // voice |
363 if (nil == voicesViewController) |
349 if (nil == voicesViewController) |
364 voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
350 voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
365 |
351 |
366 nextController = voicesViewController; |
352 nextController = voicesViewController; |
367 break; |
353 break; |
368 case 2: // fort |
354 case 2: // fort |
369 if (nil == fortsViewController) |
355 if (nil == fortsViewController) |
370 fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
356 fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
371 |
357 |
372 nextController = fortsViewController; |
358 nextController = fortsViewController; |
373 break; |
359 break; |
374 case 3: // flag |
360 case 3: // flag |
375 if (nil == flagsViewController) |
361 if (nil == flagsViewController) |
376 flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
362 flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
377 |
363 |
378 nextController = flagsViewController; |
364 nextController = flagsViewController; |
379 break; |
365 break; |
380 case 4: // level |
366 case 4: // level |
381 if (nil == levelViewController) |
367 if (nil == levelViewController) |
382 levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
368 levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
383 |
369 |
384 nextController = levelViewController; |
370 nextController = levelViewController; |
385 break; |
371 break; |
386 } |
372 } |
387 |
373 |
388 nextController.title = [secondaryItems objectAtIndex:row]; |
374 nextController.title = [secondaryItems objectAtIndex:row]; |
389 [nextController setTeamDictionary:teamDictionary]; |
375 [nextController setTeamDictionary:teamDictionary]; |
390 [self.navigationController pushViewController:nextController animated:YES]; |
376 [self.navigationController pushViewController:nextController animated:YES]; |
391 } else { |
377 break; |
392 cell = [aTableView cellForRowAtIndexPath:indexPath]; |
378 default: |
393 for (UIView *oneView in cell.contentView.subviews) { |
379 cell = [aTableView cellForRowAtIndexPath:indexPath]; |
394 if ([oneView isMemberOfClass:[UITextField class]]) { |
380 for (UIView *oneView in cell.contentView.subviews) { |
395 textFieldBeingEdited = (UITextField *)oneView; |
381 if ([oneView isMemberOfClass:[UITextField class]]) { |
396 [textFieldBeingEdited becomeFirstResponder]; |
382 textFieldBeingEdited = (UITextField *)oneView; |
397 } |
383 [textFieldBeingEdited becomeFirstResponder]; |
398 } |
384 } |
399 [aTableView deselectRowAtIndexPath:indexPath animated:NO]; |
385 } |
|
386 [aTableView deselectRowAtIndexPath:indexPath animated:NO]; |
|
387 break; |
|
388 } |
400 } |
389 |
401 |
390 } |
402 } |
391 |
403 |
392 // action to perform when you want to change a hog hat |
404 // action to perform when you want to change a hog hat |
419 self.secondaryItems = nil; |
431 self.secondaryItems = nil; |
420 hogHatViewController = nil; |
432 hogHatViewController = nil; |
421 flagsViewController = nil; |
433 flagsViewController = nil; |
422 fortsViewController = nil; |
434 fortsViewController = nil; |
423 gravesViewController = nil; |
435 gravesViewController = nil; |
|
436 levelViewController = nil; |
424 [super viewDidUnload]; |
437 [super viewDidUnload]; |
425 } |
438 } |
426 |
439 |
427 -(void) dealloc { |
440 -(void) dealloc { |
428 [teamDictionary release]; |
441 [teamDictionary release]; |