project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3904 22e4d74240e5
parent 3829 81db3c85784b
child 3906 c5da430cb3fd
equal deleted inserted replaced
3903:db01c37494af 3904:22e4d74240e5
    34 #define doDim()             [dimTimer setFireDate:HIDING_TIME_DEFAULT]
    34 #define doDim()             [dimTimer setFireDate:HIDING_TIME_DEFAULT]
    35 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    35 #define doNotDim()          [dimTimer setFireDate:HIDING_TIME_NEVER]
    36 
    36 
    37 #define CONFIRMATION_TAG 5959
    37 #define CONFIRMATION_TAG 5959
    38 #define GRENADE_TAG 9595
    38 #define GRENADE_TAG 9595
       
    39 #define BLACKVIEW_TAG 9955
    39 #define ANIMATION_DURATION 0.25
    40 #define ANIMATION_DURATION 0.25
    40 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
    41 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
    41 
    42 
    42 @implementation OverlayViewController
    43 @implementation OverlayViewController
    43 @synthesize popoverController, popupMenu, helpPage;
    44 @synthesize popoverController, popupMenu, helpPage;
    95 
    96 
    96 #pragma mark -
    97 #pragma mark -
    97 #pragma mark View Management
    98 #pragma mark View Management
    98 -(void) viewDidLoad {
    99 -(void) viewDidLoad {
    99     isGameRunning = NO;
   100     isGameRunning = NO;
       
   101     isReplay = NO;
   100     cachedGrenadeTime = 2;
   102     cachedGrenadeTime = 2;
   101     isAttacking = NO;
   103     isAttacking = NO;
   102     
   104     
   103     // i called it a popover even on the iphone
   105     // i called it a popover even on the iphone
   104     isPopoverVisible = NO;
   106     isPopoverVisible = NO;
   210     doNotDim();
   212     doNotDim();
   211 }
   213 }
   212 
   214 
   213 // dim the overlay when there's no more input for a certain amount of time
   215 // dim the overlay when there's no more input for a certain amount of time
   214 -(IBAction) buttonReleased:(id) sender {
   216 -(IBAction) buttonReleased:(id) sender {
   215     if (!isGameRunning)
   217     if (isGameRunning == NO)
   216         return;
   218         return;
   217 
   219 
   218     UIButton *theButton = (UIButton *)sender;
   220     UIButton *theButton = (UIButton *)sender;
   219 
   221 
   220     switch (theButton.tag) {
   222     switch (theButton.tag) {
   242 }
   244 }
   243 
   245 
   244 // issue certain action based on the tag of the button
   246 // issue certain action based on the tag of the button
   245 -(IBAction) buttonPressed:(id) sender {
   247 -(IBAction) buttonPressed:(id) sender {
   246     [self activateOverlay];
   248     [self activateOverlay];
   247     if (isPopoverVisible) {
   249     
       
   250     if (isGameRunning == NO)
       
   251         return;
       
   252     
       
   253     if (isPopoverVisible)
   248         [self dismissPopover];
   254         [self dismissPopover];
   249     }
       
   250 
       
   251     if (!isGameRunning)
       
   252         return;
       
   253 
       
   254     if (HW_isWaiting())
       
   255         HW_dismissReady();
       
   256     
   255     
   257     UIButton *theButton = (UIButton *)sender;
   256     UIButton *theButton = (UIButton *)sender;
   258     switch (theButton.tag) {
   257     switch (theButton.tag) {
   259         case 0:
   258         case 0:
   260             if (isAttacking == NO)
   259             if (isAttacking == NO)
   400 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   399 -(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
   401     CGRect screen = [[UIScreen mainScreen] bounds];
   400     CGRect screen = [[UIScreen mainScreen] bounds];
   402     NSSet *allTouches = [event allTouches];
   401     NSSet *allTouches = [event allTouches];
   403     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   402     CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view];
   404 
   403 
       
   404     if (isGameRunning == NO)
       
   405         return;
       
   406     
   405     switch ([allTouches count]) {
   407     switch ([allTouches count]) {
   406         case 1:
   408         case 1:
   407             // this dismisses the "get ready"
       
   408             if (HW_isWaiting())
       
   409                 HW_dismissReady();
       
   410 
       
   411             // if we're in the menu we just click in the point
   409             // if we're in the menu we just click in the point
   412             if (HW_isAmmoOpen()) {
   410             if (HW_isAmmoOpen()) {
   413                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   411                 HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y));
   414                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   412                 // this click doesn't need any wrapping because the ammoMenu already limits the cursor
   415                 HW_click();
   413                 HW_click();
   505 
   503 
   506 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   504 -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
   507     CGRect screen = [[UIScreen mainScreen] bounds];
   505     CGRect screen = [[UIScreen mainScreen] bounds];
   508     NSSet *allTouches = [event allTouches];
   506     NSSet *allTouches = [event allTouches];
   509     int x, y, dx, dy;
   507     int x, y, dx, dy;
   510 
       
   511     UITouch *touch, *first, *second;
   508     UITouch *touch, *first, *second;
   512 
   509 
       
   510     if (isGameRunning == NO)
       
   511         return;
       
   512     
   513     switch ([allTouches count]) {
   513     switch ([allTouches count]) {
   514         case 1:
   514         case 1:
   515             touch = [[allTouches allObjects] objectAtIndex:0];
   515             touch = [[allTouches allObjects] objectAtIndex:0];
   516             CGPoint currentPosition = [touch locationInView:self.view];
   516             CGPoint currentPosition = [touch locationInView:self.view];
   517 
   517 
   560     }
   560     }
   561 }
   561 }
   562 
   562 
   563 #pragma mark -
   563 #pragma mark -
   564 #pragma mark Functions called by pascal
   564 #pragma mark Functions called by pascal
   565 // called from AddProgress and FinishProgress (respectively)
   565 void setGameRunning(BOOL value) {
       
   566     isGameRunning = value;
       
   567 }
       
   568 
       
   569 // called by uStore from AddProgress
   566 void startSpinning() {
   570 void startSpinning() {
   567     isGameRunning = NO;
   571     setGameRunning(NO);
   568     CGRect screen = [[UIScreen mainScreen] bounds];
   572     CGRect screen = [[UIScreen mainScreen] bounds];
   569     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   573     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   570     indicator.tag = 987654;
   574     indicator.tag = 987654;
   571     indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2);
   575     indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2);
   572     indicator.hidesWhenStopped = YES;
   576     indicator.hidesWhenStopped = YES;
   573     [indicator startAnimating];
   577     [indicator startAnimating];
   574     [[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] addSubview:indicator];
   578     [[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] addSubview:indicator];
   575     [indicator release];
   579     [indicator release];
   576 }
   580 }
   577 
   581 
       
   582 // called by uStore from FinishProgress
   578 void stopSpinning() {
   583 void stopSpinning() {
   579     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654];
   584     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654];
   580     [indicator stopAnimating];
   585     [indicator stopAnimating];
   581     isGameRunning = YES;
       
   582     HW_zoomSet(1.7);
   586     HW_zoomSet(1.7);
   583 }
   587     if (isReplay == NO)
   584 
   588         setGameRunning(YES);
       
   589 }
       
   590 
       
   591 // called by CCHandlers from chNextTurn
   585 void clearView() {
   592 void clearView() {
   586     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   593     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   587     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   594     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   588     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
   595     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
   589 
   596 
   597     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3];
   604     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3];
   598 
   605 
   599     cachedGrenadeTime = 2;
   606     cachedGrenadeTime = 2;
   600 }
   607 }
   601 
   608 
       
   609 // called by hwengine
       
   610 void replayBegan() {
       
   611     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
   612     UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame];
       
   613     blackView.backgroundColor = [UIColor blackColor];
       
   614     blackView.alpha = 0.6;
       
   615     blackView.tag = BLACKVIEW_TAG;
       
   616     blackView.exclusiveTouch = NO;
       
   617     blackView.multipleTouchEnabled = NO;
       
   618     blackView.userInteractionEnabled = NO;
       
   619     [theWindow addSubview:blackView];
       
   620     [blackView release];
       
   621     isReplay = YES;
       
   622 }
       
   623 
       
   624 // called by uGame
       
   625 void replayFinished() {
       
   626     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
   627     UIView *blackView = (UIView *)[theWindow viewWithTag:BLACKVIEW_TAG];
       
   628     
       
   629     [UIView beginAnimations:@"removing black" context:NULL];
       
   630     [UIView setAnimationDuration:1];
       
   631     blackView.alpha = 0;
       
   632     [UIView commitAnimations];
       
   633     [theWindow performSelector:@selector(removeFromSuperview) withObject:blackView afterDelay:1];
       
   634     
       
   635     setGameRunning(YES);
       
   636     isReplay = NO;
       
   637 }
       
   638 
   602 @end
   639 @end