41 #define ACTIVITYINDICATOR_TAG 987654 |
41 #define ACTIVITYINDICATOR_TAG 987654 |
42 #define ANIMATION_DURATION 0.25 |
42 #define ANIMATION_DURATION 0.25 |
43 #define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
43 #define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
44 |
44 |
45 @implementation OverlayViewController |
45 @implementation OverlayViewController |
46 @synthesize popoverController, popupMenu, helpPage; |
46 @synthesize popoverController, popupMenu, helpPage, amvc; |
47 |
47 |
48 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
48 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
49 return rotationManager(interfaceOrientation); |
49 return rotationManager(interfaceOrientation); |
50 } |
50 } |
51 |
51 |
160 |
160 |
161 [UIView beginAnimations:@"showing overlay" context:NULL]; |
161 [UIView beginAnimations:@"showing overlay" context:NULL]; |
162 [UIView setAnimationDuration:1]; |
162 [UIView setAnimationDuration:1]; |
163 self.view.alpha = 1; |
163 self.view.alpha = 1; |
164 [UIView commitAnimations]; |
164 [UIView commitAnimations]; |
165 |
|
166 AmmoMenuViewController *amvc = [[AmmoMenuViewController alloc] init]; |
|
167 amvc.view.center = self.view.center; |
|
168 [self.view addSubview:amvc.view]; |
|
169 } |
165 } |
170 |
166 |
171 -(void) showHelp:(id) sender { |
167 -(void) showHelp:(id) sender { |
172 if (self.helpPage == nil) |
168 if (self.helpPage == nil) |
173 self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil]; |
169 self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil]; |
183 [super didReceiveMemoryWarning]; |
179 [super didReceiveMemoryWarning]; |
184 if (self.popupMenu.view.superview == nil) |
180 if (self.popupMenu.view.superview == nil) |
185 self.popupMenu = nil; |
181 self.popupMenu = nil; |
186 if (self.helpPage.view.superview == nil) |
182 if (self.helpPage.view.superview == nil) |
187 self.helpPage = nil; |
183 self.helpPage = nil; |
|
184 if (((UIPopoverController *)self.popoverController).contentViewController.view.superview == nil) |
|
185 self.popoverController = nil; |
|
186 if (self.amvc.view.superview == nil) |
|
187 self.amvc = nil; |
188 MSG_MEMCLEAN(); |
188 MSG_MEMCLEAN(); |
189 } |
189 } |
190 |
190 |
191 -(void) viewDidUnload { |
191 -(void) viewDidUnload { |
192 // only objects initialized in viewDidLoad should be here |
192 // only objects initialized in viewDidLoad should be here |
193 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
193 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
194 dimTimer = nil; |
194 dimTimer = nil; |
|
195 self.helpPage = nil; |
|
196 [self dismissPopover]; |
|
197 self.popoverController = nil; |
|
198 self.amvc = nil; |
195 MSG_DIDUNLOAD(); |
199 MSG_DIDUNLOAD(); |
196 [super viewDidUnload]; |
200 [super viewDidUnload]; |
197 } |
201 } |
198 |
202 |
199 -(void) dealloc { |
203 -(void) dealloc { |
200 [popupMenu release]; |
204 [popupMenu release]; |
201 [helpPage release]; |
205 [helpPage release]; |
202 [popoverController release]; |
206 [popoverController release]; |
|
207 [amvc release]; |
203 // dimTimer is autoreleased |
208 // dimTimer is autoreleased |
204 [super dealloc]; |
209 [super dealloc]; |
205 } |
210 } |
206 |
211 |
207 -(void) cleanup { |
212 -(void) cleanup { |
300 HW_backjump(); |
305 HW_backjump(); |
301 break; |
306 break; |
302 case 10: |
307 case 10: |
303 playSound(@"clickSound"); |
308 playSound(@"clickSound"); |
304 HW_pause(); |
309 HW_pause(); |
|
310 if (amvc.isVisible) { |
|
311 doDim(); |
|
312 [amvc disappear]; |
|
313 } |
305 removeConfirmationInput(); |
314 removeConfirmationInput(); |
306 [self showPopover]; |
315 [self showPopover]; |
307 break; |
316 break; |
308 case 11: |
317 case 11: |
309 playSound(@"clickSound"); |
318 playSound(@"clickSound"); |
310 removeConfirmationInput(); |
319 removeConfirmationInput(); |
311 HW_ammoMenu(); |
320 HW_ammoMenu(); |
|
321 |
|
322 // TODO: removal and multimonitor experience |
|
323 if (self.amvc == nil) |
|
324 self.amvc = [[AmmoMenuViewController alloc] init]; |
|
325 |
|
326 if (self.amvc.isVisible) { |
|
327 doDim(); |
|
328 [self.amvc disappear]; |
|
329 } else { |
|
330 doNotDim(); |
|
331 [self.amvc appearInView:self.view]; |
|
332 } |
|
333 |
312 break; |
334 break; |
313 default: |
335 default: |
314 DLog(@"Nope"); |
336 DLog(@"Nope"); |
315 break; |
337 break; |
316 } |
338 } |
333 -(IBAction) showPopover{ |
355 -(IBAction) showPopover{ |
334 CGRect screen = [[UIScreen mainScreen] bounds]; |
356 CGRect screen = [[UIScreen mainScreen] bounds]; |
335 isPopoverVisible = YES; |
357 isPopoverVisible = YES; |
336 |
358 |
337 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
359 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
338 if (popupMenu == nil) |
360 if (self.popupMenu == nil) |
339 popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
361 self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
340 if (popoverController == nil) { |
362 if (self.popoverController == nil) { |
341 popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
363 self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.popupMenu]; |
342 [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
364 [self.popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
343 [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
365 [self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
344 } |
366 } |
345 |
367 |
346 [popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
368 [self.popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
347 inView:self.view |
369 inView:self.view |
348 permittedArrowDirections:UIPopoverArrowDirectionAny |
370 permittedArrowDirections:UIPopoverArrowDirectionAny |
349 animated:YES]; |
371 animated:YES]; |
350 } else { |
372 } else { |
351 if (popupMenu == nil) |
373 if (self.popupMenu == nil) |
352 popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
374 self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
353 |
375 |
354 [self.view addSubview:popupMenu.view]; |
376 [self.view addSubview:popupMenu.view]; |
355 [popupMenu present]; |
377 [self.popupMenu present]; |
356 } |
378 } |
357 popupMenu.tableView.scrollEnabled = NO; |
379 self.popupMenu.tableView.scrollEnabled = NO; |
358 } |
380 } |
359 |
381 |
360 // on ipad just dismiss it, on iphone transtion to the right |
382 // on ipad just dismiss it, on iphone transtion to the right |
361 -(void) dismissPopover { |
383 -(void) dismissPopover { |
362 if (YES == isPopoverVisible) { |
384 if (YES == isPopoverVisible) { |
363 isPopoverVisible = NO; |
385 isPopoverVisible = NO; |
364 if (HW_isPaused()) |
386 if (HW_isPaused()) |
365 HW_pause(); |
387 HW_pause(); |
366 |
388 |
367 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
389 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
368 [(InGameMenuViewController *)popoverController.contentViewController removeChat]; |
390 [(InGameMenuViewController *)[[self popoverController] contentViewController] removeChat]; |
369 [popoverController dismissPopoverAnimated:YES]; |
391 [self.popoverController dismissPopoverAnimated:YES]; |
370 } else { |
392 } else { |
371 [popupMenu dismiss]; |
393 [self.popupMenu dismiss]; |
372 } |
394 } |
373 [self buttonReleased:nil]; |
395 [self buttonReleased:nil]; |
374 } |
396 } |
375 } |
397 } |
376 |
398 |