30 for (int i = 0; i < [directoryContents count]; i++) { |
30 for (int i = 0; i < [directoryContents count]; i++) { |
31 if (i % 2) { |
31 if (i % 2) { |
32 NSString *currentName = [directoryContents objectAtIndex:i]; |
32 NSString *currentName = [directoryContents objectAtIndex:i]; |
33 NSString *correctName = [currentName substringToIndex:([currentName length] - 5)]; |
33 NSString *correctName = [currentName substringToIndex:([currentName length] - 5)]; |
34 [filteredContents addObject:correctName]; |
34 [filteredContents addObject:correctName]; |
35 } |
35 } |
36 } |
36 } |
37 self.fortArray = filteredContents; |
37 self.fortArray = filteredContents; |
38 [filteredContents release]; |
38 [filteredContents release]; |
39 |
39 |
40 /* |
40 /* |
41 // this creates a scaled down version of the image |
41 // this creates a scaled down version of the image |
42 NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[fortArray count]]; |
42 NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[fortArray count]]; |
43 for (NSString *fortName in fortArray) { |
43 for (NSString *fortName in fortArray) { |
44 NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@L.png", fortsDirectory, fortName]; |
44 NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@L.png", fortsDirectory, fortName]; |
76 } |
76 } |
77 |
77 |
78 // Customize the appearance of table view cells. |
78 // Customize the appearance of table view cells. |
79 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
79 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
80 static NSString *CellIdentifier = @"Cell"; |
80 static NSString *CellIdentifier = @"Cell"; |
81 |
81 |
82 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
82 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
83 if (cell == nil) { |
83 if (cell == nil) { |
84 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
84 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
85 reuseIdentifier:CellIdentifier] autorelease]; |
85 reuseIdentifier:CellIdentifier] autorelease]; |
86 } |
86 } |
87 |
87 |
88 NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
88 NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
89 cell.textLabel.text = fortName; |
89 cell.textLabel.text = fortName; |
90 |
90 |
91 // this creates a scaled down version of the image |
91 // this creates a scaled down version of the image |
92 // TODO: create preview files, scaling is way too slow! |
92 // TODO: create preview files, scaling is way too slow! |
93 NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@L.png", FORTS_DIRECTORY(), fortName]; |
93 NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@L.png", FORTS_DIRECTORY(), fortName]; |
94 UIImage *fortSprite = [[UIImage alloc] initWithContentsOfFile:fortFile]; |
94 UIImage *fortSprite = [[UIImage alloc] initWithContentsOfFile:fortFile]; |
95 [fortFile release]; |
95 [fortFile release]; |
96 cell.imageView.image = [fortSprite scaleToSize:CGSizeMake(196,196)]; |
96 cell.imageView.image = [fortSprite scaleToSize:CGSizeMake(196,196)]; |
97 [fortSprite release]; |
97 [fortSprite release]; |
98 |
98 |
99 cell.detailTextLabel.text = @"Insert funny description here"; |
99 cell.detailTextLabel.text = @"Insert funny description here"; |
100 if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"fort"]]) { |
100 if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"fort"]]) { |
101 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
101 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
102 self.lastIndexPath = indexPath; |
102 self.lastIndexPath = indexPath; |
103 } else { |
103 } else { |
104 cell.accessoryType = UITableViewCellAccessoryNone; |
104 cell.accessoryType = UITableViewCellAccessoryNone; |
105 } |
105 } |
106 |
106 |
107 return cell; |
107 return cell; |
108 } |
108 } |
109 |
109 |
110 |
110 |
111 #pragma mark - |
111 #pragma mark - |
112 #pragma mark Table view delegate |
112 #pragma mark Table view delegate |
113 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
113 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
114 int newRow = [indexPath row]; |
114 int newRow = [indexPath row]; |
115 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
115 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
116 |
116 |
117 if (newRow != oldRow) { |
117 if (newRow != oldRow) { |
118 // if the two selected rows differ update data on the hog dictionary and reload table content |
118 // if the two selected rows differ update data on the hog dictionary and reload table content |
119 [self.teamDictionary setValue:[fortArray objectAtIndex:newRow] forKey:@"fort"]; |
119 [self.teamDictionary setValue:[fortArray objectAtIndex:newRow] forKey:@"fort"]; |
120 |
120 |
121 // tell our boss to write this new stuff on disk |
121 // tell our boss to write this new stuff on disk |
122 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
122 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
123 |
123 |
124 UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
124 UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
125 newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
125 newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
126 UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
126 UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
127 oldCell.accessoryType = UITableViewCellAccessoryNone; |
127 oldCell.accessoryType = UITableViewCellAccessoryNone; |
128 self.lastIndexPath = indexPath; |
128 self.lastIndexPath = indexPath; |