75 break; |
82 break; |
76 } |
83 } |
77 } |
84 } |
78 |
85 |
79 -(IBAction) segmentPressed:(id) sender { |
86 -(IBAction) segmentPressed:(id) sender { |
|
87 |
80 UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
88 UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
81 |
89 |
82 [AudioManagerController playSelectSound]; |
90 [AudioManagerController playSelectSound]; |
83 switch (theSegment.selectedSegmentIndex) { |
91 switch (theSegment.selectedSegmentIndex) { |
84 case 0: |
92 case 0: |
85 // this init here is just aestetic as this controller was already set up in viewDidLoad |
|
86 if (mapConfigViewController == nil) { |
|
87 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
|
88 [self.view addSubview:mapConfigViewController.view]; |
|
89 } |
|
90 // this message is compulsory otherwise the table won't be loaded at all |
93 // this message is compulsory otherwise the table won't be loaded at all |
91 [mapConfigViewController viewWillAppear:NO]; |
94 [self.mapConfigViewController viewWillAppear:NO]; |
92 [self.view bringSubviewToFront:mapConfigViewController.view]; |
95 [self.view bringSubviewToFront:self.mapConfigViewController.view]; |
93 break; |
96 break; |
94 case 1: |
97 case 1: |
95 if (teamConfigViewController == nil) { |
|
96 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
97 [self.view addSubview:teamConfigViewController.view]; |
|
98 } |
|
99 // this message is compulsory otherwise the table won't be loaded at all |
98 // this message is compulsory otherwise the table won't be loaded at all |
100 [teamConfigViewController viewWillAppear:NO]; |
99 [self.teamConfigViewController viewWillAppear:NO]; |
101 [self.view bringSubviewToFront:teamConfigViewController.view]; |
100 [self.view bringSubviewToFront:self.teamConfigViewController.view]; |
102 break; |
101 break; |
103 case 2: |
102 case 2: |
104 if (schemeWeaponConfigViewController == nil) { |
|
105 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
106 [self.view addSubview:schemeWeaponConfigViewController.view]; |
|
107 } |
|
108 // this message is compulsory otherwise the table won't be loaded at all |
103 // this message is compulsory otherwise the table won't be loaded at all |
109 [schemeWeaponConfigViewController viewWillAppear:NO]; |
104 [schemeWeaponConfigViewController viewWillAppear:NO]; |
110 [self.view bringSubviewToFront:schemeWeaponConfigViewController.view]; |
105 [self.view bringSubviewToFront:schemeWeaponConfigViewController.view]; |
111 break; |
106 break; |
112 case 3: |
107 case 3: |
228 self.schemeWeaponConfigViewController.selectedScheme,@"scheme", |
221 self.schemeWeaponConfigViewController.selectedScheme,@"scheme", |
229 self.schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
222 self.schemeWeaponConfigViewController.selectedWeapon,@"weapon", |
230 script,@"mission_command", |
223 script,@"mission_command", |
231 nil]; |
224 nil]; |
232 |
225 |
233 if (self.interfaceBridge == nil) { |
226 GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self]; |
234 GameInterfaceBridge *bridge = [[GameInterfaceBridge alloc] initWithController:self]; |
227 [bridge startLocalGame:gameDictionary]; |
235 self.interfaceBridge = bridge; |
228 [bridge release]; |
236 [bridge release]; |
|
237 } |
|
238 [self.interfaceBridge startLocalGame:gameDictionary]; |
|
239 } |
229 } |
240 |
230 |
241 -(void) loadNiceHogs { |
231 -(void) loadNiceHogs { |
242 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
232 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
243 NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; |
233 srand(time(NULL)); |
244 UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)]; |
234 NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()]; |
245 |
235 UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath]; |
|
236 [filePath release]; |
|
237 |
246 NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL]; |
238 NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL]; |
247 int numberOfHats = [hatArray count]; |
239 int numberOfHats = [hatArray count]; |
|
240 int animationFrames = IS_VERY_POWERFUL([HWUtils modelType]) ? 18 : 1; |
248 |
241 |
249 if (self.imgContainer != nil) |
242 if (self.imgContainer != nil) |
250 [self.imgContainer removeFromSuperview]; |
243 [self.imgContainer removeFromSuperview]; |
251 |
244 |
252 self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; |
245 self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; |
253 for (int i = 0; i < 1 + random()%20; i++) { |
246 for (int i = 0; i < 1 + random()%20; i++) { |
254 NSString *hat = [hatArray objectAtIndex:random()%numberOfHats]; |
247 NSString *hat = [hatArray objectAtIndex:random()%numberOfHats]; |
255 |
248 |
256 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat]; |
249 NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat]; |
257 UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)]; |
250 UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile]; |
|
251 NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames]; |
|
252 for (int j = 0; j < animationFrames; j++) { |
|
253 int x = ((j*32)/(int)hatSprite.size.height)*32; |
|
254 int y = (j*32)%(int)hatSprite.size.height; |
|
255 UIImage *hatSpriteFrame = [hatSprite cutAt:CGRectMake(x, y, 32, 32)]; |
|
256 UIImage *hogSpriteFrame = [hogSprite cutAt:CGRectMake(x, y, 32, 32)]; |
|
257 UIImage *hogWithHat = [hogSpriteFrame mergeWith:hatSpriteFrame atPoint:CGPointMake(0, 5)]; |
|
258 [animation addObject:hogWithHat]; |
|
259 } |
|
260 [hatSprite release]; |
258 [hatFile release]; |
261 [hatFile release]; |
259 UIImage *hogWithHat = [sprite mergeWith:hatSprite atPoint:CGPointMake(0, 5)]; |
262 |
260 [hatSprite release]; |
263 UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]]; |
261 |
264 hog.animationImages = animation; |
262 UIImageView *hog = [[UIImageView alloc] initWithImage:hogWithHat]; |
265 hog.animationDuration = 3; |
263 int x = 15*(i+1)+random()%40; |
266 [animation release]; |
264 if (x + 32 > 300) |
267 |
265 x = i*10; |
268 int x = 20*i+random()%128; |
266 hog.frame = CGRectMake(x, 30, 32, 32); |
269 if (x > 320 - 32) |
|
270 x = i*random()%32; |
|
271 hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height); |
267 [self.imgContainer addSubview:hog]; |
272 [self.imgContainer addSubview:hog]; |
|
273 [hog startAnimating]; |
268 [hog release]; |
274 [hog release]; |
269 } |
275 } |
|
276 |
270 [self.view addSubview:self.imgContainer]; |
277 [self.view addSubview:self.imgContainer]; |
271 [sprite release]; |
278 [hogSprite release]; |
272 [pool drain]; |
279 [pool drain]; |
273 } |
280 } |
274 |
281 |
275 -(void) viewDidLoad { |
282 -(void) viewDidLoad { |
276 self.view.backgroundColor = [UIColor blackColor]; |
283 self.view.backgroundColor = [UIColor blackColor]; |
277 |
284 |
278 CGRect screen = [[UIScreen mainScreen] bounds]; |
285 CGRect screen = [[UIScreen mainScreen] bounds]; |
279 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
286 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
280 |
287 |
281 if (IS_IPAD()) { |
288 if (IS_IPAD()) { |
282 // load other controllers |
289 // the label for the filter slider |
283 if (self.mapConfigViewController == nil) |
290 UILabel *filterLabel = [[UILabel alloc] initWithFrame:CGRectMake(116, 714, 310, 40) |
284 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
291 andTitle:nil |
285 |
292 withBorderWidth:2.0f]; |
286 UILabel *leftBackground = createLabelWithParams(nil, CGRectMake(0, 60, 320, 620), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
293 [self.view insertSubview:filterLabel belowSubview:self.mapConfigViewController.slider]; |
287 [self.mapConfigViewController.view addSubview:leftBackground]; |
294 [filterLabel release]; |
288 [leftBackground release]; |
295 |
289 UILabel *middleBackground = createLabelWithParams(nil, CGRectMake(337, 187, 350, 505), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
296 // the label for max hogs |
290 [self.mapConfigViewController.view addSubview:middleBackground]; |
297 UILabel *maxLabel = [[UILabel alloc] initWithFrame:CGRectMake(598, 714, 310, 40) |
291 [middleBackground release]; |
298 andTitle:NSLocalizedString(@"Loading...",@"") |
292 UILabel *rightBackground = createLabelWithParams(nil, CGRectMake(704, 214, 320, 464), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
299 withBorderWidth:2.0f]; |
293 [self.mapConfigViewController.view addSubview:rightBackground]; |
300 maxLabel.font = [UIFont italicSystemFontOfSize:[UIFont labelFontSize]]; |
294 [rightBackground release]; |
301 maxLabel.textColor = [UIColor whiteColor]; |
295 UILabel *topBackground = createLabelWithParams(nil, CGRectMake(714, 14, 300, 190), 2.3f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
302 maxLabel.textAlignment = UITextAlignmentCenter; |
296 [self.mapConfigViewController.view addSubview:topBackground]; |
303 [self.view addSubview:maxLabel]; |
297 [topBackground release]; |
304 self.mapConfigViewController.maxLabel = maxLabel; |
298 UILabel *bottomLeftBackground = createLabelWithParams(nil, CGRectMake(106, 714, 320, 40), 2.0f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
305 [maxLabel release]; |
299 [self.mapConfigViewController.view addSubview:bottomLeftBackground]; |
306 |
300 [bottomLeftBackground release]; |
307 // as this is loaded from a NIB we need to set its size and position |
301 UILabel *bottomRightBackground = createLabelWithParams(NSLocalizedString(@"Max Hogs: ",@""), CGRectMake(594, 714, 320, 40), 2.0f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
308 self.mapConfigViewController.view.frame = CGRectMake(704, 0, 320, 680); |
302 bottomRightBackground.font = [UIFont italicSystemFontOfSize:[UIFont labelFontSize]]; |
|
303 [self.mapConfigViewController.view addSubview:bottomRightBackground]; |
|
304 [bottomRightBackground release]; |
|
305 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.maxLabel]; |
|
306 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.sizeLabel]; |
|
307 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.segmentedControl]; |
|
308 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.previewButton]; |
|
309 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.slider]; |
|
310 [self.mapConfigViewController.view bringSubviewToFront:self.mapConfigViewController.tableView]; |
|
311 |
|
312 if (self.teamConfigViewController == nil) |
|
313 self.teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
314 [self.mapConfigViewController.view addSubview:self.teamConfigViewController.view]; |
|
315 if (self.schemeWeaponConfigViewController == nil) |
|
316 self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
317 [self.mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
|
318 self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
|
319 self.teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480); |
|
320 self.schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600); |
|
321 |
|
322 self.mapConfigViewController.parentController = self; |
|
323 } else { |
309 } else { |
324 // this is the visible controller |
310 self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width-44); |
325 if (self.mapConfigViewController == nil) |
|
326 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
|
327 // this must be loaded & added in order to auto set default scheme and ammo |
|
328 self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
329 [self.view addSubview:self.schemeWeaponConfigViewController.view]; |
|
330 } |
311 } |
331 [self.view addSubview:self.mapConfigViewController.view]; |
312 [self.view addSubview:self.mapConfigViewController.view]; |
332 self.mapConfigViewController.externalController = schemeWeaponConfigViewController; |
|
333 |
313 |
334 [super viewDidLoad]; |
314 [super viewDidLoad]; |
335 } |
315 } |
336 |
316 |
337 -(void) viewWillAppear:(BOOL)animated { |
317 -(void) viewWillAppear:(BOOL)animated { |
366 [self.schemeWeaponConfigViewController viewDidDisappear:animated]; |
346 [self.schemeWeaponConfigViewController viewDidDisappear:animated]; |
367 [super viewDidDisappear:animated]; |
347 [super viewDidDisappear:animated]; |
368 } |
348 } |
369 |
349 |
370 -(void) didReceiveMemoryWarning { |
350 -(void) didReceiveMemoryWarning { |
|
351 self.imgContainer = nil; |
|
352 |
|
353 if (self.mapConfigViewController.view.superview == nil) |
|
354 self.mapConfigViewController = nil; |
371 if (self.teamConfigViewController.view.superview == nil) |
355 if (self.teamConfigViewController.view.superview == nil) |
372 self.teamConfigViewController = nil; |
356 self.teamConfigViewController = nil; |
373 if (self.schemeWeaponConfigViewController.view.superview == nil) |
357 if (self.schemeWeaponConfigViewController.view.superview == nil) |
374 self.schemeWeaponConfigViewController = nil; |
358 self.schemeWeaponConfigViewController = nil; |
375 if (self.helpPage.view.superview == nil) |
359 if (self.helpPage.view.superview == nil) |
376 self.helpPage = nil; |
360 self.helpPage = nil; |
377 if (self.mapConfigViewController.view.superview == nil) |
|
378 self.mapConfigViewController = nil; |
|
379 |
|
380 self.imgContainer = nil; |
|
381 // don't nil this one or it won't be able to send messages |
|
382 //self.interfaceBridge = nil; |
|
383 MSG_MEMCLEAN(); |
361 MSG_MEMCLEAN(); |
384 [super didReceiveMemoryWarning]; |
362 [super didReceiveMemoryWarning]; |
385 } |
363 } |
386 |
364 |
387 -(void) viewDidUnload { |
365 -(void) viewDidUnload { |
388 self.imgContainer = nil; |
366 self.imgContainer = nil; |
389 self.interfaceBridge = nil; |
367 self.schemeWeaponConfigViewController = nil; |
|
368 self.teamConfigViewController = nil; |
390 self.mapConfigViewController = nil; |
369 self.mapConfigViewController = nil; |
391 self.teamConfigViewController = nil; |
|
392 self.schemeWeaponConfigViewController = nil; |
|
393 self.helpPage = nil; |
370 self.helpPage = nil; |
394 MSG_DIDUNLOAD(); |
371 MSG_DIDUNLOAD(); |
395 [super viewDidUnload]; |
372 [super viewDidUnload]; |
396 } |
373 } |
397 |
374 |
398 -(void) dealloc { |
375 -(void) dealloc { |
399 releaseAndNil(imgContainer); |
376 releaseAndNil(imgContainer); |
400 releaseAndNil(interfaceBridge); |
377 releaseAndNil(schemeWeaponConfigViewController); |
|
378 releaseAndNil(teamConfigViewController); |
401 releaseAndNil(mapConfigViewController); |
379 releaseAndNil(mapConfigViewController); |
402 releaseAndNil(teamConfigViewController); |
|
403 releaseAndNil(schemeWeaponConfigViewController); |
|
404 releaseAndNil(helpPage); |
380 releaseAndNil(helpPage); |
405 [super dealloc]; |
381 [super dealloc]; |
406 } |
382 } |
407 |
383 |
408 @end |
384 @end |