project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3639 b5cdbcc89b61
parent 3638 33ee433749ba
child 3646 a3271158d93b
equal deleted inserted replaced
3638:33ee433749ba 3639:b5cdbcc89b61
   338 
   338 
   339 #pragma mark -
   339 #pragma mark -
   340 #pragma mark Custom touch event handling
   340 #pragma mark Custom touch event handling
   341 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   341 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   342     NSSet *allTouches = [event allTouches];
   342     NSSet *allTouches = [event allTouches];
   343     UITouch *touch, *first, *second;
   343     UITouch *first, *second;
   344     
   344     
   345     if (isPopoverVisible) {
   345     if (isPopoverVisible) {
   346         [self dismissPopover];
   346         [self dismissPopover];
   347     }
   347     }
   348     /*
   348     /*
   351         [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   351         [dimTimer setFireDate:HIDING_TIME_DEFAULT];
   352     }
   352     }
   353     */
   353     */
   354     
   354     
   355     switch ([allTouches count]) {
   355     switch ([allTouches count]) {
   356         case 1:
   356         case 1:            
   357             touch = [[allTouches allObjects] objectAtIndex:0];
       
   358             CGPoint currentPosition = [touch locationInView:self.view];
       
   359             
       
   360             //DLog(@"X:%d Y:%d", HWX(currentPosition.x), HWY(currentPosition.y));
       
   361             // this is a single touch/tap
       
   362             isSingleClick = YES;
       
   363             // save were the click event will take place
       
   364             pointWhereToClick = currentPosition;
       
   365             
       
   366             removeConfirmationInput();
   357             removeConfirmationInput();
   367             if (2 == [touch tapCount])
   358             if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount])
   368                 HW_zoomReset();
   359                 HW_zoomReset();
   369             break;
   360             break;
   370         case 2:                
   361         case 2:                
   371             // pinching
   362             // pinching
   372             first = [[allTouches allObjects] objectAtIndex:0];
   363             first = [[allTouches allObjects] objectAtIndex:0];
   381     //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) {
   372     //if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) {
   382 
   373 
   383 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   374 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   384     CGRect screen = [[UIScreen mainScreen] bounds];
   375     CGRect screen = [[UIScreen mainScreen] bounds];
   385     NSSet *allTouches = [event allTouches];
   376     NSSet *allTouches = [event allTouches];
   386     UITouch *touch;
   377     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   387     
   378     
   388     switch ([allTouches count]) {
   379     switch ([allTouches count]) {
   389         case 1:
   380         case 1:
       
   381             // if we're in the menu we just click in the point
   390             if (HW_isAmmoOpen()) {
   382             if (HW_isAmmoOpen()) {
   391                 // if we're in the menu we just click in the point
   383                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   392                 HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y));
   384                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   393                 HW_click();
   385                 HW_click();
   394             } else 
   386             } else 
   395                 if (isSingleClick) {
   387                 // if weapon requires a further click, ask for tapping again
   396                     // if they tapped in the screen we trick the system so that camera doesn't move
   388                 if (HW_isWeaponRequiringClick()) {
   397                     HW_saveCursor(FALSE);
   389                     // here don't have to wrap thanks to isCursorVisible magic
   398                     HW_setCursor(HWX(pointWhereToClick.x), HWY(pointWhereToClick.y));
   390                     HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   399                     HW_click();
       
   400                     HW_saveCursor(TRUE);
       
   401                     
   391                     
   402                     // and remove the label (if any)
   392                     // draw the button at the last touched point (which is the current position)
   403                     removeConfirmationInput();
   393                     UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect];
   404                 } else {
   394                     tapAgain.frame = CGRectMake(currentPosition.x - 90, currentPosition.y + 15, 180, 30);
   405                     // if weapon requires a further click, ask for tapping again
   395                     tapAgain.tag = CONFIRMATION_TAG;
   406                     if (HW_isWeaponRequiringClick()) {
   396                     tapAgain.alpha = 0;
   407                         touch = [[allTouches allObjects] objectAtIndex:0];
   397                     [tapAgain addTarget:self action:@selector(sendHWClick) forControlEvents:UIControlEventTouchUpInside];
   408                         CGPoint currentPosition = [touch locationInView:self.view];
   398                     [tapAgain setTitle:NSLocalizedString(@"Tap again to confirm",@"from the overlay") forState:UIControlStateNormal];
   409                         UILabel *tapAgain = [[UILabel alloc] initWithFrame:CGRectMake(currentPosition.x-100, currentPosition.y + 10, 200, 25)];
   399                     [self.view addSubview:tapAgain];
   410                         tapAgain.text = NSLocalizedString(@"Tap again to confirm",@"from the overlay");
   400                     
   411                         tapAgain.backgroundColor = [UIColor clearColor];
   401                     // animation ftw!
   412                         tapAgain.tag = CONFIRMATION_TAG;
   402                     [UIView beginAnimations:@"inserting button" context:NULL]; 
   413                         tapAgain.textColor = [UIColor blueColor];
   403                     [UIView setAnimationDuration:ANIMATION_DURATION];
   414                         tapAgain.textAlignment = UITextAlignmentCenter;
   404                     [self.view viewWithTag:CONFIRMATION_TAG].alpha = 1;
   415                         tapAgain.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
   405                     [UIView commitAnimations];
   416                         [self.view addSubview:tapAgain];
       
   417                         [tapAgain release];
       
   418                     }
       
   419                 }
   406                 }
   420             break;
   407             break;
   421         case 2:
   408         case 2:
   422             HW_allKeysUp();
   409             HW_allKeysUp();
   423             break;
   410             break;
   424     }
   411         default:
   425     
   412             DLog(@"too many touches");
   426     pointWhereToClick = CGPointZero;
   413             break;
       
   414     }
       
   415     
   427     initialDistanceForPinching = 0;
   416     initialDistanceForPinching = 0;
   428     isSingleClick = NO;
   417 }
       
   418 
       
   419 -(void) sendHWClick {
       
   420     HW_click();
       
   421     removeConfirmationInput();
   429 }
   422 }
   430 
   423 
   431 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   424 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   432     [self touchesEnded:touches withEvent:event];
   425     [self touchesEnded:touches withEvent:event];
   433 }
   426 }
   440 
   433 
   441     switch ([allTouches count]) {
   434     switch ([allTouches count]) {
   442         case 1:
   435         case 1:
   443             touch = [[allTouches allObjects] objectAtIndex:0];
   436             touch = [[allTouches allObjects] objectAtIndex:0];
   444             CGPoint currentPosition = [touch locationInView:self.view];
   437             CGPoint currentPosition = [touch locationInView:self.view];
   445             isSingleClick = NO;
   438 
   446             if (HW_isAmmoOpen()) {
   439             if (HW_isAmmoOpen()) {
   447                 // saves the point on which to select the ammo
   440                 // moves the cursor around
   448                 pointWhereToClick = currentPosition;
       
   449                 // moves the cursor over
       
   450                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   441                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   451             } else {
   442             } else {
   452                 DLog(@"x: %f y: %f -> X:%d Y:%d", currentPosition.x, currentPosition.y, HWX(currentPosition.x), HWY(currentPosition.y));
   443                 DLog(@"x: %f y: %f -> X:%d Y:%d", currentPosition.x, currentPosition.y, HWX(currentPosition.x), HWY(currentPosition.y));
   453                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   444                 HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y));
   454             }
   445             }
   475         default:
   466         default:
   476             break;
   467             break;
   477     }
   468     }
   478 }
   469 }
   479 
   470 
       
   471 
   480 // called from AddProgress and FinishProgress (respectively)
   472 // called from AddProgress and FinishProgress (respectively)
   481 void startSpinning() {
   473 void startSpinning() {
   482     isGameRunning = NO;
   474     isGameRunning = NO;
   483     CGRect screen = [[UIScreen mainScreen] bounds];
   475     CGRect screen = [[UIScreen mainScreen] bounds];
   484     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   476     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   494     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] viewWithTag:987654];
   486     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] viewWithTag:987654];
   495     [indicator stopAnimating];
   487     [indicator stopAnimating];
   496     isGameRunning = YES;
   488     isGameRunning = YES;
   497 }
   489 }
   498 
   490 
       
   491 void clearView() {
       
   492     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
   493     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
       
   494     [UIView beginAnimations:@"remove button" context:NULL];
       
   495     [UIView setAnimationDuration:ANIMATION_DURATION];
       
   496     theButton.alpha = 0;
       
   497     [UIView commitAnimations];
       
   498     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3];
       
   499 }
       
   500 
   499 @end
   501 @end