53 CFRelease(uuid); |
53 CFRelease(uuid); |
54 NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed]; |
54 NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed]; |
55 self.seedCommand = seedCmd; |
55 self.seedCommand = seedCmd; |
56 [seedCmd release]; |
56 [seedCmd release]; |
57 |
57 |
58 if (self.dataSourceArray == nil) |
|
59 [self loadDataSourceArray]; |
|
60 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
58 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
61 NSIndexPath *theIndex; |
59 NSIndexPath *theIndex; |
62 if (isRandomness()) { |
60 if (isRandomness()) { |
63 // prevent other events and add an activity while the preview is beign generated |
61 // prevent other events and add an activity while the preview is beign generated |
64 [self turnOffWidgets]; |
62 [self turnOffWidgets]; |
126 |
122 |
127 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
123 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
128 if (cell == nil) |
124 if (cell == nil) |
129 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
125 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
130 |
126 |
131 if (self.dataSourceArray == nil) |
|
132 [self loadDataSourceArray]; |
|
133 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
127 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
134 |
128 |
135 NSString *labelString = [source objectAtIndex:row]; |
129 NSString *labelString = [source objectAtIndex:row]; |
136 cell.textLabel.text = labelString; |
130 cell.textLabel.text = labelString; |
137 cell.textLabel.adjustsFontSizeToFitWidth = YES; |
131 cell.textLabel.adjustsFontSizeToFitWidth = YES; |
157 return cell; |
151 return cell; |
158 } |
152 } |
159 |
153 |
160 // this set details for a static map (called by didSelectRowAtIndexPath) |
154 // this set details for a static map (called by didSelectRowAtIndexPath) |
161 -(void) setDetailsForStaticMap:(NSInteger) index { |
155 -(void) setDetailsForStaticMap:(NSInteger) index { |
162 if (self.dataSourceArray == nil) |
|
163 [self loadDataSourceArray]; |
|
164 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
156 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
165 |
157 |
166 NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", |
158 NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", |
167 (scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:index]]; |
159 (scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:index]]; |
168 NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
160 NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
194 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
186 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
195 int newRow = [indexPath row]; |
187 int newRow = [indexPath row]; |
196 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
188 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
197 |
189 |
198 if (newRow != oldRow) { |
190 if (newRow != oldRow) { |
199 if (self.dataSourceArray == nil) |
|
200 [self loadDataSourceArray]; |
|
201 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
191 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
202 if (isRandomness()) { |
192 if (isRandomness()) { |
203 // just change the theme, don't update preview |
193 // just change the theme, don't update preview |
204 self.themeCommand = [NSString stringWithFormat:@"etheme %@", [source objectAtIndex:newRow]]; |
194 self.themeCommand = [NSString stringWithFormat:@"etheme %@", [source objectAtIndex:newRow]]; |
205 } else { |
195 } else { |
373 [self.parentController buttonPressed:sender]; |
363 [self.parentController buttonPressed:sender]; |
374 } |
364 } |
375 |
365 |
376 #pragma mark - |
366 #pragma mark - |
377 #pragma mark view management |
367 #pragma mark view management |
378 -(void) loadDataSourceArray { |
368 -(NSArray *) dataSourceArray { |
379 NSString *model = [HWUtils modelType]; |
369 if (dataSourceArray == nil) { |
380 |
370 NSString *model = [HWUtils modelType]; |
381 // only folders containing icon.png are a valid theme |
371 |
382 NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL]; |
372 // only folders containing icon.png are a valid theme |
383 NSMutableArray *themeArray = [[NSMutableArray alloc] init]; |
373 NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL]; |
384 for (NSString *themeName in themeArrayFull) { |
374 NSMutableArray *themeArray = [[NSMutableArray alloc] init]; |
385 NSString *checkPath = [[NSString alloc] initWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]; |
375 for (NSString *themeName in themeArrayFull) { |
386 if ([[NSFileManager defaultManager] fileExistsAtPath:checkPath]) |
376 NSString *checkPath = [[NSString alloc] initWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]; |
387 [themeArray addObject:themeName]; |
377 if ([[NSFileManager defaultManager] fileExistsAtPath:checkPath]) |
388 [checkPath release]; |
378 [themeArray addObject:themeName]; |
389 } |
379 [checkPath release]; |
390 |
380 } |
391 // remove images that are too big for certain devices without loading the whole image |
381 |
392 NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
382 // remove images that are too big for certain devices without loading the whole image |
393 NSMutableArray *mapArray = [[NSMutableArray alloc] init]; |
383 NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
394 for (NSString *str in mapArrayFull) { |
384 NSMutableArray *mapArray = [[NSMutableArray alloc] init]; |
395 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
385 for (NSString *str in mapArrayFull) { |
396 if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
386 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
397 continue; |
387 if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
398 if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
388 continue; |
399 continue; |
389 if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
400 [mapArray addObject:str]; |
390 continue; |
401 } |
391 [mapArray addObject:str]; |
402 |
392 } |
403 NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; |
393 |
404 NSMutableArray *missionArray = [[NSMutableArray alloc] init]; |
394 NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; |
405 for (NSString *str in missionArrayFull) { |
395 NSMutableArray *missionArray = [[NSMutableArray alloc] init]; |
406 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
396 for (NSString *str in missionArrayFull) { |
407 if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
397 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
408 continue; |
398 if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
409 if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
399 continue; |
410 continue; |
400 if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
411 [missionArray addObject:str]; |
401 continue; |
412 } |
402 [missionArray addObject:str]; |
413 NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil]; |
403 } |
414 [missionArray release]; |
404 NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil]; |
415 [themeArray release]; |
405 [missionArray release]; |
416 [mapArray release]; |
406 [themeArray release]; |
417 |
407 [mapArray release]; |
418 self.dataSourceArray = array; |
408 |
419 [array release]; |
409 self.dataSourceArray = array; |
|
410 [array release]; |
|
411 } |
|
412 return dataSourceArray; |
420 } |
413 } |
421 |
414 |
422 -(void) viewDidLoad { |
415 -(void) viewDidLoad { |
423 [super viewDidLoad]; |
416 [super viewDidLoad]; |
424 |
417 |