26 #import "HelpPageViewController.h" |
26 #import "HelpPageViewController.h" |
27 #import "GameInterfaceBridge.h" |
27 #import "GameInterfaceBridge.h" |
28 |
28 |
29 |
29 |
30 @implementation GameConfigViewController |
30 @implementation GameConfigViewController |
31 @synthesize imgContainer, helpPage, mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController, interfaceBridge; |
31 @synthesize imgContainer, helpPage, mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController; |
32 |
32 |
33 |
33 |
34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
35 return rotationManager(interfaceOrientation); |
35 return rotationManager(interfaceOrientation); |
36 } |
36 } |
|
37 |
|
38 /* |
|
39 -(MapConfigViewController *)mapConfigViewController { |
|
40 if (mapConfigViewController == nil) { |
|
41 NSString *xib = IS_IPAD() ? @"MapConfigViewController-iPad" : @"MapConfigViewController-iPhone"; |
|
42 MapConfigViewController *mcvc = [[MapConfigViewController alloc] initWithNibName:xib bundle:nil]; |
|
43 [self.view addSubview:mcvc.view]; |
|
44 self.mapConfigViewController = mcvc; |
|
45 [mcvc release]; |
|
46 } |
|
47 return mapConfigViewController; |
|
48 } |
|
49 */ |
37 |
50 |
38 -(IBAction) buttonPressed:(id) sender { |
51 -(IBAction) buttonPressed:(id) sender { |
39 UIButton *theButton = (UIButton *)sender; |
52 UIButton *theButton = (UIButton *)sender; |
40 |
53 |
41 switch (theButton.tag) { |
54 switch (theButton.tag) { |
82 break; |
95 break; |
83 } |
96 } |
84 } |
97 } |
85 |
98 |
86 -(IBAction) segmentPressed:(id) sender { |
99 -(IBAction) segmentPressed:(id) sender { |
|
100 /* |
87 UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
101 UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
88 |
102 |
89 [AudioManagerController playSelectSound]; |
103 [AudioManagerController playSelectSound]; |
90 switch (theSegment.selectedSegmentIndex) { |
104 switch (theSegment.selectedSegmentIndex) { |
91 case 0: |
105 case 0: |
92 // this init here is just aestetic as this controller was already set up in viewDidLoad |
|
93 if (mapConfigViewController == nil) { |
|
94 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
|
95 [self.view addSubview:mapConfigViewController.view]; |
|
96 } |
|
97 // this message is compulsory otherwise the table won't be loaded at all |
106 // this message is compulsory otherwise the table won't be loaded at all |
98 [mapConfigViewController viewWillAppear:NO]; |
107 [self.mapConfigViewController viewWillAppear:NO]; |
99 [self.view bringSubviewToFront:mapConfigViewController.view]; |
108 [self.view bringSubviewToFront:self.mapConfigViewController.view]; |
100 break; |
109 break; |
101 case 1: |
110 case 1: |
102 if (teamConfigViewController == nil) { |
|
103 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
104 [self.view addSubview:teamConfigViewController.view]; |
|
105 } |
|
106 // this message is compulsory otherwise the table won't be loaded at all |
111 // this message is compulsory otherwise the table won't be loaded at all |
107 [teamConfigViewController viewWillAppear:NO]; |
112 [self.teamConfigViewController viewWillAppear:NO]; |
108 [self.view bringSubviewToFront:teamConfigViewController.view]; |
113 [self.view bringSubviewToFront:self.teamConfigViewController.view]; |
109 break; |
114 break; |
110 case 2: |
115 case 2: |
111 if (schemeWeaponConfigViewController == nil) { |
116 if (schemeWeaponConfigViewController == nil) { |
112 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
117 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
113 [self.view addSubview:schemeWeaponConfigViewController.view]; |
118 [self.view addSubview:schemeWeaponConfigViewController.view]; |
232 self.schemeWeaponConfigViewController.selectedScheme,@"scheme", |
238 self.schemeWeaponConfigViewController.selectedScheme,@"scheme", |
233 self.schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
239 self.schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
234 script,@"mission_command", |
240 script,@"mission_command", |
235 nil]; |
241 nil]; |
236 |
242 |
237 if (self.interfaceBridge == nil) { |
243 GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self]; |
238 GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self]; |
244 [bridge startLocalGame:gameDictionary]; |
239 self.interfaceBridge = bridge; |
245 [bridge release]; |
240 [bridge release]; |
|
241 } |
|
242 [self.interfaceBridge startLocalGame:gameDictionary]; |
|
243 } |
246 } |
244 |
247 |
245 -(void) loadNiceHogs { |
248 -(void) loadNiceHogs { |
246 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
249 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
247 srand(time(NULL)); |
250 srand(time(NULL)); |
298 |
301 |
299 CGRect screen = [[UIScreen mainScreen] bounds]; |
302 CGRect screen = [[UIScreen mainScreen] bounds]; |
300 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
303 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
301 |
304 |
302 if (IS_IPAD()) { |
305 if (IS_IPAD()) { |
303 // load other controllers and the background |
306 // the label for the filter slider |
304 if (self.mapConfigViewController == nil) |
307 UILabel *filterLabel = [[UILabel alloc] initWithFrame:CGRectMake(116, 714, 310, 40) |
305 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
308 andTitle:nil |
306 |
309 withBorderWidth:2.0f]; |
307 UILabel *theLabel; |
310 [self.view insertSubview:filterLabel belowSubview:self.mapConfigViewController.slider]; |
308 // top right column (map) |
311 [filterLabel release]; |
309 theLabel = [[UILabel alloc] initWithFrame:CGRectMake(714, 14, 300, 190) andTitle:nil withBorderWidth:2.3f]; |
312 |
310 [self.mapConfigViewController.view addSubview:theLabel]; |
313 // the label for max hogs |
311 releaseAndNil(theLabel); |
314 UILabel *maxLabel = [[UILabel alloc] initWithFrame:CGRectMake(598, 714, 310, 40) |
312 // bottom left |
315 andTitle:NSLocalizedString(@"Loading...",@"") |
313 theLabel = [[UILabel alloc] initWithFrame:CGRectMake(116, 714, 310, 40) andTitle:nil withBorderWidth:2.0f]; |
316 withBorderWidth:2.0f]; |
314 [self.mapConfigViewController.view addSubview:theLabel]; |
317 maxLabel.font = [UIFont italicSystemFontOfSize:[UIFont labelFontSize]]; |
315 releaseAndNil(theLabel); |
318 maxLabel.textColor = [UIColor whiteColor]; |
316 // bottom right |
319 maxLabel.textAlignment = UITextAlignmentCenter; |
317 theLabel = [[UILabel alloc] initWithFrame:CGRectMake(598, 714, 310, 40) |
320 [self.view addSubview:maxLabel]; |
318 andTitle:NSLocalizedString(@" Max Hogs:",@"") |
321 self.mapConfigViewController.maxLabel = maxLabel; |
319 withBorderWidth:2.0f]; |
322 [maxLabel release]; |
320 theLabel.font = [UIFont italicSystemFontOfSize:[UIFont labelFontSize]]; |
323 |
321 theLabel.textColor = [UIColor whiteColor]; |
324 // as this is loaded from a NIB we need to set its size and position |
322 theLabel.textAlignment = UITextAlignmentLeft; |
325 self.mapConfigViewController.view.frame = CGRectMake(704, 0, 320, 680); |
323 [self.mapConfigViewController.view addSubview:theLabel]; |
|
324 releaseAndNil(theLabel); |
|
325 |
|
326 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.maxLabel]; |
|
327 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.sizeLabel]; |
|
328 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.segmentedControl]; |
|
329 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.previewButton]; |
|
330 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.slider]; |
|
331 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.tableView]; |
|
332 |
|
333 if (self.teamConfigViewController == nil) |
|
334 self.teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
335 [self.mapConfigViewController.view addSubview:self.teamConfigViewController.view]; |
|
336 if (self.schemeWeaponConfigViewController == nil) |
|
337 self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
338 [self.mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
|
339 |
|
340 self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
|
341 self.schemeWeaponConfigViewController.view.frame = CGRectMake(0, 60, 320, 620); |
|
342 self.teamConfigViewController.view.frame = CGRectMake(337, 187, 350, 505); |
|
343 |
|
344 self.mapConfigViewController.parentController = self; |
|
345 } else { |
326 } else { |
346 // this is the visible controller |
327 // this is the visible controller |
347 if (self.mapConfigViewController == nil) |
328 if (self.mapConfigViewController == nil) |
348 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
329 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
349 // this must be loaded & added in order to auto set default scheme and ammo |
330 // this must be loaded & added in order to auto set default scheme and ammo |
350 self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
331 self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
351 [self.view addSubview:self.schemeWeaponConfigViewController.view]; |
332 [self.view addSubview:self.schemeWeaponConfigViewController.view]; |
352 } |
333 } |
353 [self.view addSubview:self.mapConfigViewController.view]; |
334 [self.view addSubview:self.mapConfigViewController.view]; |
354 self.mapConfigViewController.externalController = schemeWeaponConfigViewController; |
|
355 |
335 |
356 [super viewDidLoad]; |
336 [super viewDidLoad]; |
357 } |
337 } |
358 |
338 |
359 -(void) viewWillAppear:(BOOL)animated { |
339 -(void) viewWillAppear:(BOOL)animated { |
388 [self.schemeWeaponConfigViewController viewDidDisappear:animated]; |
368 [self.schemeWeaponConfigViewController viewDidDisappear:animated]; |
389 [super viewDidDisappear:animated]; |
369 [super viewDidDisappear:animated]; |
390 } |
370 } |
391 |
371 |
392 -(void) didReceiveMemoryWarning { |
372 -(void) didReceiveMemoryWarning { |
|
373 self.imgContainer = nil; |
|
374 |
|
375 if (self.mapConfigViewController.view.superview == nil) |
|
376 self.mapConfigViewController = nil; |
393 if (self.teamConfigViewController.view.superview == nil) |
377 if (self.teamConfigViewController.view.superview == nil) |
394 self.teamConfigViewController = nil; |
378 self.teamConfigViewController = nil; |
395 if (self.schemeWeaponConfigViewController.view.superview == nil) |
379 if (self.schemeWeaponConfigViewController.view.superview == nil) |
396 self.schemeWeaponConfigViewController = nil; |
380 self.schemeWeaponConfigViewController = nil; |
397 if (self.helpPage.view.superview == nil) |
381 if (self.helpPage.view.superview == nil) |
398 self.helpPage = nil; |
382 self.helpPage = nil; |
399 if (self.mapConfigViewController.view.superview == nil) |
|
400 self.mapConfigViewController = nil; |
|
401 |
|
402 self.imgContainer = nil; |
|
403 // don't nil this one or it won't be able to send messages |
|
404 //self.interfaceBridge = nil; |
|
405 MSG_MEMCLEAN(); |
383 MSG_MEMCLEAN(); |
406 [super didReceiveMemoryWarning]; |
384 [super didReceiveMemoryWarning]; |
407 } |
385 } |
408 |
386 |
409 -(void) viewDidUnload { |
387 -(void) viewDidUnload { |
410 self.imgContainer = nil; |
388 self.imgContainer = nil; |
411 self.interfaceBridge = nil; |
389 self.schemeWeaponConfigViewController = nil; |
|
390 self.teamConfigViewController = nil; |
412 self.mapConfigViewController = nil; |
391 self.mapConfigViewController = nil; |
413 self.teamConfigViewController = nil; |
|
414 self.schemeWeaponConfigViewController = nil; |
|
415 self.helpPage = nil; |
392 self.helpPage = nil; |
416 MSG_DIDUNLOAD(); |
393 MSG_DIDUNLOAD(); |
417 [super viewDidUnload]; |
394 [super viewDidUnload]; |
418 } |
395 } |
419 |
396 |
420 -(void) dealloc { |
397 -(void) dealloc { |
421 releaseAndNil(imgContainer); |
398 releaseAndNil(imgContainer); |
422 releaseAndNil(interfaceBridge); |
399 releaseAndNil(schemeWeaponConfigViewController); |
|
400 releaseAndNil(teamConfigViewController); |
423 releaseAndNil(mapConfigViewController); |
401 releaseAndNil(mapConfigViewController); |
424 releaseAndNil(teamConfigViewController); |
|
425 releaseAndNil(schemeWeaponConfigViewController); |
|
426 releaseAndNil(helpPage); |
402 releaseAndNil(helpPage); |
427 [super dealloc]; |
403 [super dealloc]; |
428 } |
404 } |
429 |
405 |
430 @end |
406 @end |