148 } |
148 } |
149 |
149 |
150 // this set details for a static map (called by didSelectRowAtIndexPath) |
150 // this set details for a static map (called by didSelectRowAtIndexPath) |
151 -(void) setDetailsForStaticMap:(NSInteger) index { |
151 -(void) setDetailsForStaticMap:(NSInteger) index { |
152 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
152 NSArray *source = [self.dataSourceArray objectAtIndex:scIndex]; |
153 |
153 |
154 NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", |
154 NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", |
155 (scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:index]]; |
155 (scIndex == 1) ? MAPS_DIRECTORY() : MISSIONS_DIRECTORY(),[source objectAtIndex:index]]; |
156 NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
156 NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL]; |
157 [fileCfg release]; |
157 [fileCfg release]; |
158 NSArray *split = [contents componentsSeparatedByString:@"\n"]; |
158 NSArray *split = [contents componentsSeparatedByString:@"\n"]; |
159 [contents release]; |
159 [contents release]; |
164 if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0) |
164 if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0) |
165 max = [split objectAtIndex:1]; |
165 max = [split objectAtIndex:1]; |
166 else |
166 else |
167 max = @"18"; |
167 max = @"18"; |
168 [self setMaxLabelText:max]; |
168 [self setMaxLabelText:max]; |
169 |
169 |
170 self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]]; |
170 self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]]; |
171 self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [source objectAtIndex:index]]; |
171 self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [source objectAtIndex:index]]; |
172 |
172 |
173 if (scIndex != 3) |
173 if (scIndex != 3) |
174 self.missionCommand = @""; |
174 self.missionCommand = @""; |
355 #pragma mark - |
355 #pragma mark - |
356 #pragma mark view management |
356 #pragma mark view management |
357 -(NSArray *) dataSourceArray { |
357 -(NSArray *) dataSourceArray { |
358 if (dataSourceArray == nil) { |
358 if (dataSourceArray == nil) { |
359 NSString *model = [HWUtils modelType]; |
359 NSString *model = [HWUtils modelType]; |
360 |
360 |
361 // only folders containing icon.png are a valid theme |
361 // only folders containing icon.png are a valid theme |
362 NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL]; |
362 NSArray *themeArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:THEMES_DIRECTORY() error:NULL]; |
363 NSMutableArray *themeArray = [[NSMutableArray alloc] init]; |
363 NSMutableArray *themeArray = [[NSMutableArray alloc] init]; |
364 for (NSString *themeName in themeArrayFull) { |
364 for (NSString *themeName in themeArrayFull) { |
365 NSString *checkPath = [[NSString alloc] initWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]; |
365 NSString *checkPath = [[NSString alloc] initWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]; |
366 if ([[NSFileManager defaultManager] fileExistsAtPath:checkPath]) |
366 if ([[NSFileManager defaultManager] fileExistsAtPath:checkPath]) |
367 [themeArray addObject:themeName]; |
367 [themeArray addObject:themeName]; |
368 [checkPath release]; |
368 [checkPath release]; |
369 } |
369 } |
370 |
370 |
371 // remove images that are too big for certain devices without loading the whole image |
371 // remove images that are too big for certain devices without loading the whole image |
372 NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
372 NSArray *mapArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL]; |
373 NSMutableArray *mapArray = [[NSMutableArray alloc] init]; |
373 NSMutableArray *mapArray = [[NSMutableArray alloc] init]; |
374 for (NSString *str in mapArrayFull) { |
374 for (NSString *str in mapArrayFull) { |
375 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
375 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MAPS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
377 continue; |
377 continue; |
378 if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
378 if (IS_NOT_VERY_POWERFUL(model) && imgSize.height > 1280.0f) |
379 continue; |
379 continue; |
380 [mapArray addObject:str]; |
380 [mapArray addObject:str]; |
381 } |
381 } |
382 |
382 |
383 NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; |
383 NSArray *missionArrayFull = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MISSIONS_DIRECTORY() error:NULL]; |
384 NSMutableArray *missionArray = [[NSMutableArray alloc] init]; |
384 NSMutableArray *missionArray = [[NSMutableArray alloc] init]; |
385 for (NSString *str in missionArrayFull) { |
385 for (NSString *str in missionArrayFull) { |
386 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
386 CGSize imgSize = [UIImage imageSizeFromMetadataOf:[MISSIONS_DIRECTORY() stringByAppendingFormat:@"%@/map.png",str]]; |
387 if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
387 if (IS_NOT_POWERFUL(model) && imgSize.height > 1024.0f) |
392 } |
392 } |
393 NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil]; |
393 NSArray *array = [[NSArray alloc] initWithObjects:themeArray,mapArray,themeArray,missionArray,nil]; |
394 [missionArray release]; |
394 [missionArray release]; |
395 [themeArray release]; |
395 [themeArray release]; |
396 [mapArray release]; |
396 [mapArray release]; |
397 |
397 |
398 self.dataSourceArray = array; |
398 self.dataSourceArray = array; |
399 [array release]; |
399 [array release]; |
400 } |
400 } |
401 return dataSourceArray; |
401 return dataSourceArray; |
402 } |
402 } |
403 |
403 |
404 -(void) viewDidLoad { |
404 -(void) viewDidLoad { |
405 [super viewDidLoad]; |
405 [super viewDidLoad]; |
406 srandom(time(NULL)); |
406 srandom(time(NULL)); |
407 |
407 |
408 // initialize some "default" values |
408 // initialize some "default" values |
409 self.slider.value = 0.05f; |
409 self.slider.value = 0.05f; |
410 self.slider.enabled = NO; |
410 self.slider.enabled = NO; |
411 self.oldValue = 5; |
411 self.oldValue = 5; |
412 self.busy = NO; |
412 self.busy = NO; |