36 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
36 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
37 return rotationManager(interfaceOrientation); |
37 return rotationManager(interfaceOrientation); |
38 } |
38 } |
39 |
39 |
40 -(IBAction) buttonPressed:(id) sender { |
40 -(IBAction) buttonPressed:(id) sender { |
41 // works even if it's not actually a button |
41 UIButton *theButton = (UIButton *)sender; |
42 UIButton *theButton; |
|
43 if (IS_IPAD()) |
|
44 theButton = [[(NSNotification *)sender userInfo] objectForKey:@"sender"]; |
|
45 else |
|
46 theButton = (UIButton *)sender; |
|
47 |
42 |
48 switch (theButton.tag) { |
43 switch (theButton.tag) { |
49 case 0: |
44 case 0: |
50 playSound(@"backSound"); |
45 playSound(@"backSound"); |
51 if ([self.mapConfigViewController busy]) { |
46 if ([self.mapConfigViewController busy]) { |
169 } |
164 } |
170 |
165 |
171 // play if there aren't too many teams |
166 // play if there aren't too many teams |
172 if ([self.teamConfigViewController.listOfSelectedTeams count] > HW_getMaxNumberOfTeams()) { |
167 if ([self.teamConfigViewController.listOfSelectedTeams count] > HW_getMaxNumberOfTeams()) { |
173 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many teams",@"") |
168 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many teams",@"") |
174 message:NSLocalizedString(@"Max six teams are allowed in the same game",@"") |
169 message:NSLocalizedString(@"You exceeded the maximum number of tems allowed in a game",@"") |
175 delegate:nil |
170 delegate:nil |
176 cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
171 cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
177 otherButtonTitles:nil]; |
172 otherButtonTitles:nil]; |
178 [alert show]; |
173 [alert show]; |
179 [alert release]; |
174 [alert release]; |
232 nil]; |
227 nil]; |
233 |
228 |
234 // finally launch game and remove this controller |
229 // finally launch game and remove this controller |
235 DLog(@"sending config %@", gameDictionary); |
230 DLog(@"sending config %@", gameDictionary); |
236 |
231 |
237 if ([[gameDictionary allKeys] count] == 11) { |
232 NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:gameDictionary,@"game_dictionary", @"",@"savefile", |
238 NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:gameDictionary,@"game_dictionary", @"",@"savefile", |
233 [NSNumber numberWithBool:NO],@"netgame", nil]; |
239 [NSNumber numberWithBool:NO],@"netgame", nil]; |
234 if (IS_IPAD()) |
240 // let's hide all the views while the game is on |
235 [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; |
|
236 else { |
|
237 // this causes a sporadic crash on the ipad but without this rotation doesn't work on iphone |
241 UIViewController *dummy = [[UIViewController alloc] init]; |
238 UIViewController *dummy = [[UIViewController alloc] init]; |
242 [self presentModalViewController:dummy animated:NO]; |
239 [self presentModalViewController:dummy animated:NO]; |
243 [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; |
240 [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary]; |
244 [self dismissModalViewControllerAnimated:NO]; |
241 [self dismissModalViewControllerAnimated:NO]; |
245 [dummy release]; |
242 [dummy release]; |
246 } else { |
|
247 DLog(@"gameconfig data not complete!!"); |
|
248 [self.parentViewController dismissModalViewControllerAnimated:YES]; |
|
249 |
|
250 // present an alert to the user, with an image on the ipad (too big for the iphone) |
|
251 NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@""); |
|
252 if (IS_IPAD()) |
|
253 msg = [msg stringByAppendingString:@"\n\n\n\n\n\n\n\n"]; // this makes space for the image |
|
254 |
|
255 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops" |
|
256 message:msg |
|
257 delegate:nil |
|
258 cancelButtonTitle:@"Ok" |
|
259 otherButtonTitles:nil]; |
|
260 |
|
261 if (IS_IPAD()) { |
|
262 UIImageView *deniedImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"denied.png"]]; |
|
263 deniedImg.frame = CGRectMake(25, 80, 240, 160); |
|
264 [alert addSubview:deniedImg]; |
|
265 [deniedImg release]; |
|
266 } |
|
267 [alert show]; |
|
268 [alert release]; |
|
269 } |
243 } |
270 |
244 |
271 } |
245 } |
272 |
246 |
273 -(void) loadNiceHogs { |
247 -(void) loadNiceHogs { |
309 |
283 |
310 CGRect screen = [[UIScreen mainScreen] bounds]; |
284 CGRect screen = [[UIScreen mainScreen] bounds]; |
311 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
285 self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
312 |
286 |
313 if (IS_IPAD()) { |
287 if (IS_IPAD()) { |
314 [[NSNotificationCenter defaultCenter] addObserver:self |
|
315 selector:@selector(buttonPressed:) |
|
316 name:@"buttonPressed" |
|
317 object:nil]; |
|
318 srandom(time(NULL)); |
|
319 |
|
320 // load other controllers |
288 // load other controllers |
321 if (self.mapConfigViewController == nil) |
289 if (self.mapConfigViewController == nil) |
322 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
290 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil]; |
323 |
291 |
324 UILabel *leftBackground = createLabelWithParams(nil, CGRectMake(0, 60, 320, 620), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
292 UILabel *leftBackground = createLabelWithParams(nil, CGRectMake(0, 60, 320, 620), 2.7f, UICOLOR_HW_YELLOW_BODER, UICOLOR_HW_ALPHABLUE); |
355 [self.mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
323 [self.mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view]; |
356 self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
324 self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width); |
357 self.teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480); |
325 self.teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480); |
358 self.schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600); |
326 self.schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600); |
359 |
327 |
|
328 self.mapConfigViewController.parentController = self; |
360 } else { |
329 } else { |
361 // this is the visible controller |
330 // this is the visible controller |
362 if (self.mapConfigViewController == nil) |
331 if (self.mapConfigViewController == nil) |
363 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
332 self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil]; |
364 // this must be loaded & added in order to auto set default scheme and ammo |
333 // this must be loaded & added in order to auto set default scheme and ammo |
418 MSG_MEMCLEAN(); |
387 MSG_MEMCLEAN(); |
419 [super didReceiveMemoryWarning]; |
388 [super didReceiveMemoryWarning]; |
420 } |
389 } |
421 |
390 |
422 -(void) viewDidUnload { |
391 -(void) viewDidUnload { |
423 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
|
424 self.imgContainer = nil; |
392 self.imgContainer = nil; |
425 self.mapConfigViewController = nil; |
393 self.mapConfigViewController = nil; |
426 self.teamConfigViewController = nil; |
394 self.teamConfigViewController = nil; |
427 self.schemeWeaponConfigViewController = nil; |
395 self.schemeWeaponConfigViewController = nil; |
428 self.helpPage = nil; |
396 self.helpPage = nil; |