project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3650 ec90e573f47a
parent 3649 bc35f8fee587
child 3651 7058ca178f3b
equal deleted inserted replaced
3649:bc35f8fee587 3650:ec90e573f47a
    19 #define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
    19 #define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
    20 #define doDim()             [dimTimer setFireDate:HIDING_TIME_DEFAULT]
    20 #define doDim()             [dimTimer setFireDate:HIDING_TIME_DEFAULT]
    21 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    21 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    22 
    22 
    23 #define CONFIRMATION_TAG 5959
    23 #define CONFIRMATION_TAG 5959
       
    24 #define GRENADE_TAG 9595
    24 #define ANIMATION_DURATION 0.25
    25 #define ANIMATION_DURATION 0.25
    25 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; 
    26 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; 
    26 
    27 
    27 @implementation OverlayViewController
    28 @implementation OverlayViewController
    28 @synthesize popoverController, popupMenu;
    29 @synthesize popoverController, popupMenu;
    84     self.view.alpha = 0;
    85     self.view.alpha = 0;
    85     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
    86     self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0);
    86     
    87     
    87     // set initial orientation
    88     // set initial orientation
    88     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    89     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    89     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345];
    90     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    90     switch (orientation) {
    91     switch (orientation) {
    91         case UIDeviceOrientationLandscapeLeft:
    92         case UIDeviceOrientationLandscapeLeft:
    92             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
    93             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0));
    93             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
    94             self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90));
    94             break;
    95             break;
   308             [popupMenu dismiss];
   309             [popupMenu dismiss];
   309         }
   310         }
   310         [self buttonReleased:nil];
   311         [self buttonReleased:nil];
   311     }
   312     }
   312 }
   313 }
   313 
       
   314 -(void) textFieldDoneEditing:(id) sender{
       
   315     [sender resignFirstResponder];
       
   316 }
       
   317 
       
   318 
   314 
   319 #pragma mark -
   315 #pragma mark -
   320 #pragma mark Custom touch event handling
   316 #pragma mark Custom touch event handling
   321 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   317 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
   322     NSSet *allTouches = [event allTouches];
   318     NSSet *allTouches = [event allTouches];
   380                     [UIView setAnimationDuration:ANIMATION_DURATION];
   376                     [UIView setAnimationDuration:ANIMATION_DURATION];
   381                     [self.view viewWithTag:CONFIRMATION_TAG].alpha = 1;
   377                     [self.view viewWithTag:CONFIRMATION_TAG].alpha = 1;
   382                     [UIView commitAnimations];
   378                     [UIView commitAnimations];
   383                     
   379                     
   384                     // keep the overlay active, or the button will fade
   380                     // keep the overlay active, or the button will fade
       
   381                     [self activateOverlay];
   385                     doNotDim();
   382                     doNotDim();
   386                 }
   383                 } else
       
   384                     if (HW_isWeaponTimerable()) {
       
   385                         if (isSegmentVisible) {
       
   386                             UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG];
       
   387                             
       
   388                             [UIView beginAnimations:@"removing segmented control" context:NULL];
       
   389                             [UIView setAnimationDuration:ANIMATION_DURATION];
       
   390                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
       
   391                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
       
   392                             [UIView commitAnimations];
       
   393                             
       
   394                             [grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION];
       
   395                         } else {
       
   396                             NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil];
       
   397                             UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items];
       
   398                             [items release];
       
   399                             
       
   400                             [grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged];
       
   401                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50);
       
   402                             grenadeTime.selectedSegmentIndex = 2;
       
   403                             grenadeTime.tag = GRENADE_TAG;
       
   404                             [self.view addSubview:grenadeTime];
       
   405                             [grenadeTime release];
       
   406                             
       
   407                             [UIView beginAnimations:@"inserting segmented control" context:NULL];
       
   408                             [UIView setAnimationDuration:ANIMATION_DURATION];
       
   409                             [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
       
   410                             grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50);
       
   411                             [UIView commitAnimations];
       
   412                             
       
   413                             [self activateOverlay];
       
   414                             doNotDim();
       
   415                         }
       
   416                         isSegmentVisible = !isSegmentVisible;
       
   417                     }
       
   418 
   387             break;
   419             break;
   388         case 2:
   420         case 2:
   389             HW_allKeysUp();
   421             HW_allKeysUp();
   390             break;
   422             break;
   391         default:
   423         default:
   398 
   430 
   399 -(void) sendHWClick {
   431 -(void) sendHWClick {
   400     HW_click();
   432     HW_click();
   401     removeConfirmationInput();
   433     removeConfirmationInput();
   402     doDim();
   434     doDim();
       
   435 }
       
   436 
       
   437 -(void) setGrenadeTime:(id) sender {
       
   438     UISegmentedControl *theSegment = (UISegmentedControl *)sender;
       
   439     HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1);
   403 }
   440 }
   404 
   441 
   405 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   442 -(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
   406     [self touchesEnded:touches withEvent:event];
   443     [self touchesEnded:touches withEvent:event];
   407 }
   444 }
   447         default:
   484         default:
   448             break;
   485             break;
   449     }
   486     }
   450 }
   487 }
   451 
   488 
   452 
   489 #pragma mark -
       
   490 #pragma mark Functions called by pascal
   453 // called from AddProgress and FinishProgress (respectively)
   491 // called from AddProgress and FinishProgress (respectively)
   454 void startSpinning() {
   492 void startSpinning() {
   455     isGameRunning = NO;
   493     isGameRunning = NO;
   456     CGRect screen = [[UIScreen mainScreen] bounds];
   494     CGRect screen = [[UIScreen mainScreen] bounds];
   457     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   495     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   458     indicator.tag = 987654;
   496     indicator.tag = 987654;
   459     indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2);
   497     indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2);
   460     indicator.hidesWhenStopped = YES;
   498     indicator.hidesWhenStopped = YES;
   461     [indicator startAnimating];
   499     [indicator startAnimating];
   462     [[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] addSubview:indicator];
   500     [[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] addSubview:indicator];
   463     [indicator release];
   501     [indicator release];
   464 }
   502 }
   465 
   503 
   466 void stopSpinning() {
   504 void stopSpinning() {
   467     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] viewWithTag:987654];
   505     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654];
   468     [indicator stopAnimating];
   506     [indicator stopAnimating];
   469     isGameRunning = YES;
   507     isGameRunning = YES;
   470 }
   508 }
   471 
   509 
   472 void clearView() {
   510 void clearView() {
   473     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   511     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   474     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   512     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
       
   513     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
       
   514     
   475     [UIView beginAnimations:@"remove button" context:NULL];
   515     [UIView beginAnimations:@"remove button" context:NULL];
   476     [UIView setAnimationDuration:ANIMATION_DURATION];
   516     [UIView setAnimationDuration:ANIMATION_DURATION];
   477     theButton.alpha = 0;
   517     theButton.alpha = 0;
       
   518     theSegment.alpha = 0;
   478     [UIView commitAnimations];
   519     [UIView commitAnimations];
       
   520     
   479     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3];
   521     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3];
       
   522     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3];    
   480 }
   523 }
   481 
   524 
   482 @end
   525 @end