project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 6666 0e2f5b81cbf2
parent 6624 e049b5bb0ad1
child 6700 e04da46ee43c
equal deleted inserted replaced
6665:12e809cc5c3f 6666:0e2f5b81cbf2
   285 }
   285 }
   286 
   286 
   287 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   287 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize
   288 // on iphone instead just use the tableViewController directly (and implement manually all animations)
   288 // on iphone instead just use the tableViewController directly (and implement manually all animations)
   289 -(IBAction) showPopover{
   289 -(IBAction) showPopover{
   290     CGRect screen = [[UIScreen mainScreen] bounds];
   290     CGRect screen = [[UIScreen mainScreen] safeBounds];
   291     isPopoverVisible = YES;
   291     isPopoverVisible = YES;
   292 
   292 
   293     if (IS_IPAD()) {
   293     if (IS_IPAD()) {
   294         if (self.popupMenu == nil)
   294         if (self.popupMenu == nil)
   295             self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain];
   295             self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain];
   297             self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.popupMenu];
   297             self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.popupMenu];
   298             [self.popoverController setPopoverContentSize:CGSizeMake(220, 200) animated:YES];
   298             [self.popoverController setPopoverContentSize:CGSizeMake(220, 200) animated:YES];
   299             [self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
   299             [self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]];
   300         }
   300         }
   301 
   301 
   302         [self.popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1)
   302         [self.popoverController presentPopoverFromRect:CGRectMake(screen.size.width / 2, screen.size.height / 2, 1, 1)
   303                                            inView:self.view
   303                                            inView:self.view
   304                          permittedArrowDirections:UIPopoverArrowDirectionAny
   304                          permittedArrowDirections:UIPopoverArrowDirectionAny
   305                                          animated:YES];
   305                                          animated:YES];
   306     } else {
   306     } else {
   307         if (self.popupMenu == nil)
   307         if (self.popupMenu == nil)
   334     if ([HWUtils isGameRunning] == NO)
   334     if ([HWUtils isGameRunning] == NO)
   335         return YES;
   335         return YES;
   336 
   336 
   337     // ignore activity near the dpad and buttons
   337     // ignore activity near the dpad and buttons
   338     CGPoint touchPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   338     CGPoint touchPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   339     CGSize screen = [[UIScreen mainScreen] bounds].size;
   339     CGSize screen = [[UIScreen mainScreen] safeBounds].size;
   340 
   340 
   341     if ((touchPoint.x < 160 && touchPoint.y > screen.width - 155 ) || 
   341     if ((touchPoint.x < 160 && touchPoint.y > screen.height - 155 ) ||
   342         (touchPoint.x > screen.height - 135 && touchPoint.y > screen.width - 140))
   342         (touchPoint.x > screen.width - 135 && touchPoint.y > screen.height - 140))
   343         return YES;
   343         return YES;
   344     return NO;
   344     return NO;
   345 }
   345 }
   346 
   346 
   347 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   347 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   384 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   384 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   385     NSSet *allTouches = [event allTouches];
   385     NSSet *allTouches = [event allTouches];
   386     if ([self shouldIgnoreTouch:allTouches] == YES)
   386     if ([self shouldIgnoreTouch:allTouches] == YES)
   387         return;
   387         return;
   388 
   388 
   389     CGRect screen = [[UIScreen mainScreen] bounds];
   389     CGRect screen = [[UIScreen mainScreen] safeBounds];
   390     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   390     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   391 
   391 
   392     switch ([allTouches count]) {
   392     switch ([allTouches count]) {
   393         case 1:
   393         case 1:
   394             // if we're in the menu we just click in the point
   394             // if we're in the menu we just click in the point
   395             if (HW_isAmmoMenuOpen()) {
   395             if (HW_isAmmoMenuOpen()) {
   396                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   396                 HW_setCursor(HWXZ(currentPosition.x),HWYZ(currentPosition.y));
   397                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   397                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   398                 HW_click();
   398                 HW_click();
   399             } else
   399             } else
   400                 // if weapon requires a further click, ask for tapping again
   400                 // if weapon requires a further click, ask for tapping again
   401                 if (HW_isWeaponRequiringClick()) {
   401                 if (HW_isWeaponRequiringClick()) {
   477 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   477 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   478     NSSet *allTouches = [event allTouches];
   478     NSSet *allTouches = [event allTouches];
   479     if ([self shouldIgnoreTouch:allTouches] == YES)
   479     if ([self shouldIgnoreTouch:allTouches] == YES)
   480         return;
   480         return;
   481 
   481 
   482     CGRect screen = [[UIScreen mainScreen] bounds];
   482     CGRect screen = [[UIScreen mainScreen] safeBounds];
   483     int x, y, dx, dy;
   483     int x, y, dx, dy;
   484     UITouch *touch, *first, *second;
   484     UITouch *touch, *first, *second;
   485 
   485 
   486     switch ([allTouches count]) {
   486     switch ([allTouches count]) {
   487         case 1:
   487         case 1: