21 |
21 |
22 #import "FortsViewController.h" |
22 #import "FortsViewController.h" |
23 #import "CommodityFunctions.h" |
23 #import "CommodityFunctions.h" |
24 #import "UIImageExtra.h" |
24 #import "UIImageExtra.h" |
25 |
25 |
|
26 #define IMGNUM_PER_FORT 4 |
|
27 |
26 @implementation FortsViewController |
28 @implementation FortsViewController |
27 @synthesize teamDictionary, fortArray, lastIndexPath; |
29 @synthesize teamDictionary, fortArray, lastIndexPath; |
28 |
30 |
29 |
31 |
30 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
32 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
39 |
41 |
40 NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FORTS_DIRECTORY() error:NULL]; |
42 NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FORTS_DIRECTORY() error:NULL]; |
41 NSMutableArray *filteredContents = [[NSMutableArray alloc] initWithCapacity:([directoryContents count] / 3)]; |
43 NSMutableArray *filteredContents = [[NSMutableArray alloc] initWithCapacity:([directoryContents count] / 3)]; |
42 // we need to remove the double entries and the L.png suffix |
44 // we need to remove the double entries and the L.png suffix |
43 for (int i = 0; i < [directoryContents count]; i++) { |
45 for (int i = 0; i < [directoryContents count]; i++) { |
44 if (i % 3 == 1) { |
46 if (i % IMGNUM_PER_FORT == 3) { |
45 NSString *currentName = [directoryContents objectAtIndex:i]; |
47 NSString *currentName = [directoryContents objectAtIndex:i]; |
46 NSString *correctName = [currentName substringToIndex:([currentName length] - 5)]; |
48 NSString *correctName = [currentName substringToIndex:([currentName length] - 5)]; |
47 [filteredContents addObject:correctName]; |
49 [filteredContents addObject:correctName]; |
48 } |
50 } |
49 } |
51 } |
50 self.fortArray = filteredContents; |
52 self.fortArray = filteredContents; |
51 [filteredContents release]; |
53 [filteredContents release]; |
52 |
54 |
53 // statically set row height instead of using delegate method for performance reasons |
55 // statically set row height instead of using delegate method for performance reasons |
54 self.tableView.rowHeight = 200; |
56 self.tableView.rowHeight = 128; |
55 |
57 |
56 self.title = NSLocalizedString(@"Choose team fort",@""); |
58 self.title = NSLocalizedString(@"Choose team fort",@""); |
57 } |
59 } |
58 |
60 |
59 |
61 |
60 - (void)viewWillAppear:(BOOL)animated { |
62 -(void) viewWillAppear:(BOOL)animated { |
61 [super viewWillAppear:animated]; |
63 [super viewWillAppear:animated]; |
62 [self.tableView reloadData]; |
64 [self.tableView reloadData]; |
63 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
65 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
64 } |
66 } |
65 |
67 |
77 // Customize the appearance of table view cells. |
79 // Customize the appearance of table view cells. |
78 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
80 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
79 static NSString *CellIdentifier = @"Cell"; |
81 static NSString *CellIdentifier = @"Cell"; |
80 |
82 |
81 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
83 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
82 if (cell == nil) { |
84 if (cell == nil) |
83 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
85 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
84 reuseIdentifier:CellIdentifier] autorelease]; |
86 reuseIdentifier:CellIdentifier] autorelease]; |
85 } |
|
86 |
87 |
87 NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
88 NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
88 cell.textLabel.text = fortName; |
89 cell.textLabel.text = fortName; |
89 |
90 |
90 NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@-preview.png", FORTS_DIRECTORY(), fortName]; |
91 NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@-preview.png", FORTS_DIRECTORY(), fortName]; |