project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3922 44804043b691
parent 3906 c5da430cb3fd
child 3924 2a9ace189288
equal deleted inserted replaced
3921:022dfe1431b7 3922:44804043b691
    29 #import "SDL_config_iphoneos.h"
    29 #import "SDL_config_iphoneos.h"
    30 #import "SDL_mouse.h"
    30 #import "SDL_mouse.h"
    31 
    31 
    32 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
    32 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7]
    33 #define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
    33 #define HIDING_TIME_NEVER   [NSDate dateWithTimeIntervalSinceNow:10000]
    34 #define doDim()             [dimTimer setFireDate:HIDING_TIME_DEFAULT]
    34 #define doDim()             [dimTimer setFireDate: ([[UIScreen screens] count] == 1) ? HIDING_TIME_DEFAULT : HIDING_TIME_NEVER]
    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 REPLAYBLACKVIEW_TAG 9955
       
    40 #define ACTIVITYINDICATOR_TAG 987654
    40 #define ANIMATION_DURATION 0.25
    41 #define ANIMATION_DURATION 0.25
    41 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
    42 #define removeConfirmationInput()   [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview];
    42 
    43 
    43 @implementation OverlayViewController
    44 @implementation OverlayViewController
    44 @synthesize popoverController, popupMenu, helpPage;
    45 @synthesize popoverController, popupMenu, helpPage;
    56     [UIView beginAnimations:@"rotation" context:NULL];
    57     [UIView beginAnimations:@"rotation" context:NULL];
    57     [UIView setAnimationDuration:0.8f];
    58     [UIView setAnimationDuration:0.8f];
    58     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    59     [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    59     switch (orientation) {
    60     switch (orientation) {
    60         case UIDeviceOrientationLandscapeLeft:
    61         case UIDeviceOrientationLandscapeLeft:
    61             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
    62             if ([[UIScreen screens] count] == 1)
       
    63                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
    62             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
    64             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
    63             HW_setLandscape(YES);
    65             HW_setLandscape(YES);
    64             break;
    66             break;
    65         case UIDeviceOrientationLandscapeRight:
    67         case UIDeviceOrientationLandscapeRight:
    66             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
    68             if ([[UIScreen screens] count] == 1)
       
    69                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
    67             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
    70             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
    68             HW_setLandscape(YES);
    71             HW_setLandscape(YES);
    69             break;
    72             break;
    70         /*
    73         /*
    71         case UIDeviceOrientationPortrait:
    74         case UIDeviceOrientationPortrait:
   110     // set initial orientation wrt the controller orientation
   113     // set initial orientation wrt the controller orientation
   111     UIDeviceOrientation orientation = self.interfaceOrientation;
   114     UIDeviceOrientation orientation = self.interfaceOrientation;
   112     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
   115     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
   113     switch (orientation) {
   116     switch (orientation) {
   114         case UIDeviceOrientationLandscapeLeft:
   117         case UIDeviceOrientationLandscapeLeft:
   115             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
   118             if ([[UIScreen screens] count] == 1)
       
   119                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
   116             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   120             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
   117             break;
   121             break;
   118         case UIDeviceOrientationLandscapeRight:
   122         case UIDeviceOrientationLandscapeRight:
   119             sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
   123             if ([[UIScreen screens] count] == 1)
       
   124                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
   120             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
   125             self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
   121             break;
   126             break;
   122         default:
   127         default:
   123             DLog(@"unknown orientation");
   128             DLog(@"unknown orientation");
   124             break;
   129             break;
   125     }
   130     }
   126     CGRect rect = [[UIScreen mainScreen] bounds];
   131     CGRect screenRect = [[UIScreen mainScreen] bounds];
   127     self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
   132     self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
   128 
   133 
   129     dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6]
   134     dimTimer = [[NSTimer alloc] initWithFireDate:([[UIScreen screens] count] == 1) ? [NSDate dateWithTimeIntervalSinceNow:6] : HIDING_TIME_NEVER
   130                                         interval:1000
   135                                         interval:1000
   131                                           target:self
   136                                           target:self
   132                                         selector:@selector(dimOverlay)
   137                                         selector:@selector(dimOverlay)
   133                                         userInfo:nil
   138                                         userInfo:nil
   134                                          repeats:YES];
   139                                          repeats:YES];
   145     [[NSNotificationCenter defaultCenter] addObserver:self
   150     [[NSNotificationCenter defaultCenter] addObserver:self
   146                                              selector:@selector(showHelp:)
   151                                              selector:@selector(showHelp:)
   147                                                  name:@"show help ingame"
   152                                                  name:@"show help ingame"
   148                                                object:nil];
   153                                                object:nil];
   149 
   154 
       
   155     [[NSNotificationCenter defaultCenter] addObserver:self
       
   156                                              selector:@selector(cleanup)
       
   157                                                  name:@"remove overlay"
       
   158                                                object:nil];
       
   159     
   150     [UIView beginAnimations:@"showing overlay" context:NULL];
   160     [UIView beginAnimations:@"showing overlay" context:NULL];
   151     [UIView setAnimationDuration:1];
   161     [UIView setAnimationDuration:1];
   152     self.view.alpha = 1;
   162     self.view.alpha = 1;
   153     [UIView commitAnimations];
   163     [UIView commitAnimations];
   154 
       
   155     // find the sdl window we're on
       
   156     SDL_VideoDevice *_this = SDL_GetVideoDevice();
       
   157     SDL_VideoDisplay *display = &_this->displays[0];
       
   158     sdlwindow = display->windows;
       
   159 }
   164 }
   160 
   165 
   161 -(void) showHelp:(id) sender {
   166 -(void) showHelp:(id) sender {
   162     if (self.helpPage == nil)
   167     if (self.helpPage == nil)
   163         self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil];
   168         self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil];
   190     [popupMenu release];
   195     [popupMenu release];
   191     [helpPage release];
   196     [helpPage release];
   192     [popoverController release];
   197     [popoverController release];
   193     // dimTimer is autoreleased
   198     // dimTimer is autoreleased
   194     [super dealloc];
   199     [super dealloc];
       
   200 }
       
   201 
       
   202 -(void) cleanup {
       
   203     [self dismissPopover];
       
   204     [self.view removeFromSuperview];
   195 }
   205 }
   196 
   206 
   197 #pragma mark -
   207 #pragma mark -
   198 #pragma mark Overlay actions and members
   208 #pragma mark Overlay actions and members
   199 // nice transition for dimming, should be called only by the timer himself
   209 // nice transition for dimming, should be called only by the timer himself
   567 }
   577 }
   568 
   578 
   569 // called by uStore from AddProgress
   579 // called by uStore from AddProgress
   570 void startSpinning() {
   580 void startSpinning() {
   571     setGameRunning(NO);
   581     setGameRunning(NO);
   572     CGRect screen = [[UIScreen mainScreen] bounds];
   582     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   573     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   583     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   574     indicator.tag = 987654;
   584     indicator.tag = ACTIVITYINDICATOR_TAG;
   575     indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2);
   585     if ([[UIScreen screens] count] > 1)
       
   586         indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + 118);
       
   587     else
       
   588         indicator.center = CGPointMake(theWindow.frame.size.width/2 + 118, theWindow.frame.size.height/2);
   576     indicator.hidesWhenStopped = YES;
   589     indicator.hidesWhenStopped = YES;
   577     [indicator startAnimating];
   590     [indicator startAnimating];
   578     [[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] addSubview:indicator];
   591     [theWindow addSubview:indicator];
   579     [indicator release];
   592     [indicator release];
   580 }
   593 }
   581 
   594 
   582 // called by uStore from FinishProgress and by OverlayViewController by replayBegan
   595 // called by uStore from FinishProgress and by OverlayViewController by replayBegan
   583 void stopSpinning() {
   596 void stopSpinning() {
   584     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654];
   597     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
       
   598     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[theWindow viewWithTag:ACTIVITYINDICATOR_TAG];
   585     [indicator stopAnimating];
   599     [indicator stopAnimating];
   586     HW_zoomSet(1.7);
   600     HW_zoomSet(1.7);
   587     if (isReplay == NO)
   601     if (isReplay == NO)
   588         setGameRunning(YES);
   602         setGameRunning(YES);
   589 }
   603 }
   590 
   604 
   591 // called by CCHandlers from chNextTurn
   605 // called by CCHandlers from chNextTurn
   592 void clearView() {
   606 void clearView() {
   593     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   607     UIWindow *theWindow = ([[UIScreen screens] count] == 1) ? [[UIApplication sharedApplication] keyWindow] : [SDLUIKitDelegate sharedAppDelegate].uiwindow;
   594     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   608     UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG];
   595     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
   609     UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG];
   596 
   610 
   597     [UIView beginAnimations:@"remove button" context:NULL];
   611     [UIView beginAnimations:@"remove button" context:NULL];
   598     [UIView setAnimationDuration:ANIMATION_DURATION];
   612     [UIView setAnimationDuration:ANIMATION_DURATION];
   599     theButton.alpha = 0;
   613     theButton.alpha = 0;
   600     theSegment.alpha = 0;
   614     theSegment.alpha = 0;
   601     [UIView commitAnimations];
   615     [UIView commitAnimations];
   602 
   616 
   603     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3];
   617     [theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:ANIMATION_DURATION];
   604     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3];
   618     [theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:ANIMATION_DURATION];
   605 
   619 
   606     cachedGrenadeTime = 2;
   620     cachedGrenadeTime = 2;
   607 }
   621 }
   608 
   622 
   609 // called by hwengine
   623 // called by hwengine
   610 void replayBegan() {
   624 void replayBegan() {
   611     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   625     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   612     UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame];
   626     UIView *blackView = [[UIView alloc] initWithFrame:theWindow.frame];
   613     blackView.backgroundColor = [UIColor blackColor];
   627     blackView.backgroundColor = [UIColor blackColor];
   614     blackView.alpha = 0.6;
   628     blackView.alpha = 0.6;
   615     blackView.tag = BLACKVIEW_TAG;
   629     blackView.tag = REPLAYBLACKVIEW_TAG;
   616     blackView.exclusiveTouch = NO;
   630     blackView.exclusiveTouch = NO;
   617     blackView.multipleTouchEnabled = NO;
   631     blackView.multipleTouchEnabled = NO;
   618     blackView.userInteractionEnabled = NO;
   632     blackView.userInteractionEnabled = NO;
   619     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   633     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
   620     indicator.center = theWindow.center;
   634     indicator.center = theWindow.center;
   628 }
   642 }
   629 
   643 
   630 // called by uGame
   644 // called by uGame
   631 void replayFinished() {
   645 void replayFinished() {
   632     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   646     UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow];
   633     UIView *blackView = (UIView *)[theWindow viewWithTag:BLACKVIEW_TAG];
   647     UIView *blackView = (UIView *)[theWindow viewWithTag:REPLAYBLACKVIEW_TAG];
   634     
   648     
   635     [UIView beginAnimations:@"removing black" context:NULL];
   649     [UIView beginAnimations:@"removing black" context:NULL];
   636     [UIView setAnimationDuration:1];
   650     [UIView setAnimationDuration:1];
   637     blackView.alpha = 0;
   651     blackView.alpha = 0;
   638     [UIView commitAnimations];
   652     [UIView commitAnimations];