22 #import "GameInterfaceBridge.h" |
22 #import "GameInterfaceBridge.h" |
23 |
23 |
24 |
24 |
25 @implementation MissionTrainingViewController |
25 @implementation MissionTrainingViewController |
26 |
26 |
27 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
27 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
28 return rotationManager(interfaceOrientation); |
28 return rotationManager(interfaceOrientation); |
29 } |
29 } |
30 |
30 |
31 #pragma mark - |
31 #pragma mark - |
32 #pragma mark View management |
32 #pragma mark View management |
33 -(void) viewDidLoad |
33 - (void)viewDidLoad |
34 { |
34 { |
35 [super viewDidLoad]; |
35 [super viewDidLoad]; |
36 |
36 |
37 self.previewImage.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
37 self.previewImage.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
38 self.previewImage.layer.borderWidth = 3.8f; |
38 self.previewImage.layer.borderWidth = 3.8f; |
52 self.tableView.separatorColor = [UIColor whiteColor]; |
52 self.tableView.separatorColor = [UIColor whiteColor]; |
53 |
53 |
54 self.descriptionLabel.textColor = [UIColor lightYellowColor]; |
54 self.descriptionLabel.textColor = [UIColor lightYellowColor]; |
55 } |
55 } |
56 |
56 |
57 -(void) viewWillAppear:(BOOL)animated { |
57 - (void)viewWillAppear:(BOOL)animated { |
58 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:arc4random_uniform((int)[self.listOfMissionIDs count]) inSection:0]; |
58 NSIndexPath *indexPath = [NSIndexPath indexPathForRow:arc4random_uniform((int)[self.listOfMissionIDs count]) inSection:0]; |
59 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; |
59 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle]; |
60 [self tableView:self.tableView didSelectRowAtIndexPath:indexPath]; |
60 [self tableView:self.tableView didSelectRowAtIndexPath:indexPath]; |
61 [super viewWillAppear:animated]; |
61 [super viewWillAppear:animated]; |
62 } |
62 } |
63 |
63 |
64 -(IBAction) buttonPressed:(id) sender { |
64 - (IBAction)buttonPressed:(id)sender { |
65 UIButton *button = (UIButton *)sender; |
65 UIButton *button = (UIButton *)sender; |
66 |
66 |
67 if (button.tag == 0) { |
67 if (button.tag == 0) { |
68 [[AudioManagerController mainManager] playBackSound]; |
68 [[AudioManagerController mainManager] playBackSound]; |
69 [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; |
69 [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; |
85 if (![languageID isEqualToString:@"en"] && [[NSFileManager defaultManager] fileExistsAtPath:localizedMissionsDescLocation]) |
85 if (![languageID isEqualToString:@"en"] && [[NSFileManager defaultManager] fileExistsAtPath:localizedMissionsDescLocation]) |
86 { |
86 { |
87 NSDictionary *missionsDict = [self newMissionsDictionaryFromMissionsFile:missionsDescLocation]; |
87 NSDictionary *missionsDict = [self newMissionsDictionaryFromMissionsFile:missionsDescLocation]; |
88 NSDictionary *localizedMissionsDict = [self newMissionsDictionaryFromMissionsFile:localizedMissionsDescLocation]; |
88 NSDictionary *localizedMissionsDict = [self newMissionsDictionaryFromMissionsFile:localizedMissionsDescLocation]; |
89 |
89 |
90 [missionsDescLocation release]; |
|
91 [localizedMissionsDescLocation release]; |
|
92 |
90 |
93 NSMutableDictionary *tempMissionsDict = [[NSMutableDictionary alloc] init]; |
91 NSMutableDictionary *tempMissionsDict = [[NSMutableDictionary alloc] init]; |
94 |
92 |
95 for (NSString *key in [missionsDict allKeys]) |
93 for (NSString *key in [missionsDict allKeys]) |
96 { |
94 { |
198 return _dictOfMissions; |
190 return _dictOfMissions; |
199 } |
191 } |
200 |
192 |
201 #pragma mark - |
193 #pragma mark - |
202 #pragma mark Table view data source |
194 #pragma mark Table view data source |
203 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
195 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
204 return 1; |
196 return 1; |
205 } |
197 } |
206 |
198 |
207 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
199 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
208 return [self.listOfMissionIDs count]; |
200 return [self.listOfMissionIDs count]; |
209 } |
201 } |
210 |
202 |
211 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |
203 -(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { |
212 return (IS_IPAD()) ? self.tableView.rowHeight : 80; |
204 return (IS_IPAD()) ? self.tableView.rowHeight : 80; |
216 static NSString *CellIdentifier = @"CellTr"; |
208 static NSString *CellIdentifier = @"CellTr"; |
217 NSInteger row = [indexPath row]; |
209 NSInteger row = [indexPath row]; |
218 |
210 |
219 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
211 UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
220 if (cell == nil) |
212 if (cell == nil) |
221 cell = [[[UITableViewCell alloc] initWithStyle:(IS_IPAD()) ? UITableViewCellStyleDefault : UITableViewCellStyleSubtitle |
213 cell = [[UITableViewCell alloc] initWithStyle:(IS_IPAD()) ? UITableViewCellStyleDefault : UITableViewCellStyleSubtitle |
222 reuseIdentifier:CellIdentifier] autorelease]; |
214 reuseIdentifier:CellIdentifier]; |
223 |
215 |
224 NSString *missionID = [self.listOfMissionIDs objectAtIndex:row]; |
216 NSString *missionID = [self.listOfMissionIDs objectAtIndex:row]; |
225 cell.textLabel.text = self.dictOfMissions[missionID][@"name"]; |
217 cell.textLabel.text = self.dictOfMissions[missionID][@"name"]; |
226 |
218 |
227 cell.textLabel.textColor = [UIColor lightYellowColor]; |
219 cell.textLabel.textColor = [UIColor lightYellowColor]; |
238 |
230 |
239 UIView *bgColorView = [[UIView alloc] init]; |
231 UIView *bgColorView = [[UIView alloc] init]; |
240 bgColorView.backgroundColor = [UIColor colorWithRed:(85.0/255.0) green:(15.0/255.0) blue:(106.0/255.0) alpha:1.0]; |
232 bgColorView.backgroundColor = [UIColor colorWithRed:(85.0/255.0) green:(15.0/255.0) blue:(106.0/255.0) alpha:1.0]; |
241 bgColorView.layer.masksToBounds = YES; |
233 bgColorView.layer.masksToBounds = YES; |
242 cell.selectedBackgroundView = bgColorView; |
234 cell.selectedBackgroundView = bgColorView; |
243 [bgColorView release]; |
|
244 |
235 |
245 cell.backgroundColor = [UIColor blackColorTransparent]; |
236 cell.backgroundColor = [UIColor blackColorTransparent]; |
246 return cell; |
237 return cell; |
247 } |
238 } |
248 |
239 |
249 #pragma mark - |
240 #pragma mark - |
250 #pragma mark Table view delegate |
241 #pragma mark Table view delegate |
251 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
242 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
252 NSInteger row = [indexPath row]; |
243 NSInteger row = [indexPath row]; |
253 |
244 |
254 self.missionName = [self.listOfMissionIDs objectAtIndex:row]; |
245 self.missionName = [self.listOfMissionIDs objectAtIndex:row]; |
255 NSString *size = IS_IPAD() ? @"@2x" : @""; |
246 NSString *size = IS_IPAD() ? @"@2x" : @""; |
256 NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Missions/Training/%@%@.png",GRAPHICS_DIRECTORY(),self.missionName,size]; |
247 NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Missions/Training/%@%@.png",GRAPHICS_DIRECTORY(),self.missionName,size]; |
257 UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath]; |
248 UIImage *img = [[UIImage alloc] initWithContentsOfFile:filePath]; |
258 [filePath release]; |
|
259 [self.previewImage setImage:img]; |
249 [self.previewImage setImage:img]; |
260 [img release]; |
|
261 |
250 |
262 self.descriptionLabel.text = self.dictOfMissions[self.missionName][@"desc"]; |
251 self.descriptionLabel.text = self.dictOfMissions[self.missionName][@"desc"]; |
263 } |
252 } |
264 |
253 |
265 #pragma mark - |
254 #pragma mark - |
266 #pragma mark Memory management |
255 #pragma mark Memory management |
267 |
256 |
268 -(void) didReceiveMemoryWarning |
257 - (void)didReceiveMemoryWarning |
269 { |
258 { |
270 self.missionName = nil; |
259 self.missionName = nil; |
271 self.listOfMissionIDs = nil; |
260 self.listOfMissionIDs = nil; |
272 self.dictOfMissions = nil; |
261 self.dictOfMissions = nil; |
273 // if you nil this one it won't get updated anymore |
262 // if you nil this one it won't get updated anymore |
274 //self.previewImage = nil; |
263 //self.previewImage = nil; |
275 [super didReceiveMemoryWarning]; |
264 [super didReceiveMemoryWarning]; |
276 } |
265 } |
277 |
266 |
278 -(void) viewDidUnload |
|
279 { |
|
280 self.listOfMissionIDs = nil; |
|
281 self.dictOfMissions = nil; |
|
282 self.previewImage = nil; |
|
283 self.tableView = nil; |
|
284 self.descriptionLabel = nil; |
|
285 self.missionName = nil; |
|
286 MSG_DIDUNLOAD(); |
|
287 [super viewDidUnload]; |
|
288 } |
|
289 |
|
290 |
|
291 -(void) dealloc |
|
292 { |
|
293 releaseAndNil(_listOfMissionIDs); |
|
294 releaseAndNil(_dictOfMissions); |
|
295 releaseAndNil(_previewImage); |
|
296 releaseAndNil(_tableView); |
|
297 releaseAndNil(_descriptionLabel); |
|
298 releaseAndNil(_missionName); |
|
299 [super dealloc]; |
|
300 } |
|
301 |
|
302 |
|
303 @end |
267 @end |