5 // Created by Vittorio on 02/04/10. |
5 // Created by Vittorio on 02/04/10. |
6 // Copyright 2010 __MyCompanyName__. All rights reserved. |
6 // Copyright 2010 __MyCompanyName__. All rights reserved. |
7 // |
7 // |
8 |
8 |
9 #import "HogHatViewController.h" |
9 #import "HogHatViewController.h" |
|
10 #import "CommodityFunctions.h" |
10 |
11 |
11 |
12 |
12 @implementation HogHatViewController |
13 @implementation HogHatViewController |
13 @synthesize teamDictionary, hatArray, hatSprites, lastIndexPath, selectedHog; |
14 @synthesize teamDictionary, hatArray, hatSprites, lastIndexPath, selectedHog; |
|
15 |
|
16 |
|
17 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
18 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
19 } |
14 |
20 |
15 #pragma mark - |
21 #pragma mark - |
16 #pragma mark View lifecycle |
22 #pragma mark View lifecycle |
17 - (void)viewDidLoad { |
23 - (void)viewDidLoad { |
18 [super viewDidLoad]; |
24 [super viewDidLoad]; |
19 |
25 |
20 // load all the hat file names and store them into hatArray |
26 // load all the hat file names and store them into hatArray |
21 NSString *hatPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"]; |
27 NSString *hatsDirectory = HATS_DIRECTORY(); |
22 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatPath error:NULL]; |
28 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatsDirectory error:NULL]; |
23 self.hatArray = array; |
29 self.hatArray = array; |
24 |
30 |
25 // load all the hat images from the previous array but save only the first sprite and store it in hatSprites |
31 // load all the hat images from the previous array but save only the first sprite and store it in hatSprites |
26 NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]]; |
32 NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[hatArray count]]; |
27 for (int i=0; i< [hatArray count]; i++) { |
33 for (int i=0; i < [hatArray count]; i++) { |
28 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/Data/Graphics/Hats/%@",[[NSBundle mainBundle] resourcePath],[hatArray objectAtIndex:i]]; |
34 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", hatsDirectory,[hatArray objectAtIndex:i]]; |
29 |
35 |
30 UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile]; |
36 UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile]; |
31 [hatFile release]; |
37 [hatFile release]; |
32 CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32); |
38 CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32); |
33 CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea); |
39 CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea); |
65 /* |
71 /* |
66 - (void)viewDidDisappear:(BOOL)animated { |
72 - (void)viewDidDisappear:(BOOL)animated { |
67 [super viewDidDisappear:animated]; |
73 [super viewDidDisappear:animated]; |
68 } |
74 } |
69 */ |
75 */ |
70 |
|
71 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
72 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
|
73 } |
|
74 |
76 |
75 |
77 |
76 #pragma mark - |
78 #pragma mark - |
77 #pragma mark Table view data source |
79 #pragma mark Table view data source |
78 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
80 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
96 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
98 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
97 if (cell == nil) { |
99 if (cell == nil) { |
98 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
100 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
99 } |
101 } |
100 |
102 |
101 NSDictionary *hog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
103 NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:selectedHog]; |
102 if (0 == [indexPath section]) { |
104 if (0 == [indexPath section]) { |
103 cell.textLabel.text = self.title; |
105 cell.textLabel.text = self.title; |
104 cell.imageView.image = nil; |
106 cell.imageView.image = nil; |
105 cell.accessoryType = UITableViewCellAccessoryNone; |
107 cell.accessoryType = UITableViewCellAccessoryNone; |
106 } else { |
108 } else { |
159 */ |
161 */ |
160 |
162 |
161 |
163 |
162 #pragma mark - |
164 #pragma mark - |
163 #pragma mark Table view delegate |
165 #pragma mark Table view delegate |
164 |
|
165 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
166 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
166 if (1 == [indexPath section]) { |
167 if (1 == [indexPath section]) { |
167 int newRow = [indexPath row]; |
168 int newRow = [indexPath row]; |
168 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
169 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
169 |
170 |