project_files/HedgewarsMobile/Classes/OverlayViewController.m
changeset 3977 9df7b4812da9
parent 3976 abaf741a4e21
child 3978 9660600e43cb
equal deleted inserted replaced
3976:abaf741a4e21 3977:9df7b4812da9
    46 @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu;
    46 @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu;
    47 
    47 
    48 #pragma mark -
    48 #pragma mark -
    49 #pragma mark rotation
    49 #pragma mark rotation
    50 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    50 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    51     if (IS_DUALHEAD())
    51     return rotationManager(interfaceOrientation);
    52         return YES;                         ////// TEST MEEEEE
       
    53     else
       
    54         return rotationManager(interfaceOrientation);
       
    55 }
    52 }
    56 
    53 
    57 // pause the game and remove objc menus so that animation is smoother
    54 // pause the game and remove objc menus so that animation is smoother
    58 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration{
    55 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration{
    59     [self dismissPopover];
    56     [self dismissPopover];
    80 
    77 
    81 // rotate the sdl view according to the orientation -- the uiview is autorotated
    78 // rotate the sdl view according to the orientation -- the uiview is autorotated
    82 -(void) didRotate:(NSNotification *)notification {
    79 -(void) didRotate:(NSNotification *)notification {
    83     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    80     UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
    84     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    81     UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG];
    85 
    82     CGRect screenRect = [[UIScreen mainScreen] bounds];
       
    83     
    86     [UIView beginAnimations:@"rotation" context:NULL];
    84     [UIView beginAnimations:@"rotation" context:NULL];
    87     [UIView setAnimationDuration:0.7];
    85     [UIView setAnimationDuration:0.7];
    88     switch (orientation) {
    86     switch (orientation) {
    89         case UIDeviceOrientationLandscapeLeft:
    87         case UIDeviceOrientationLandscapeLeft:
    90             if (IS_DUALHEAD() == NO)
    88             if (IS_DUALHEAD()) {
       
    89                 self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
       
    90                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
       
    91             } else
    91                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(a));
    92                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(a));
    92             //self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
       
    93             break;
    93             break;
    94         case UIDeviceOrientationLandscapeRight:
    94         case UIDeviceOrientationLandscapeRight:
    95             if (IS_DUALHEAD() == NO)
    95             if (IS_DUALHEAD()) {
       
    96                 self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
       
    97                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
       
    98             } else
    96                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(b));
    99                 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(b));
    97             //self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
       
    98             break;
       
    99         case UIDeviceOrientationPortrait:
       
   100             if (IS_DUALHEAD())
       
   101                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
       
   102             break;
       
   103         case UIDeviceOrientationPortraitUpsideDown:
       
   104             if (IS_DUALHEAD())
       
   105                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180));
       
   106             break;
   100             break;
   107         default:
   101         default:
   108             // a debug log would spam too much
   102             // a debug log would spam too much
   109             break;
   103             break;
   110     }
   104     }
   119 -(id) initWithCoder:(NSCoder *)aDecoder {
   113 -(id) initWithCoder:(NSCoder *)aDecoder {
   120     if ((self = [super initWithCoder:aDecoder])) {
   114     if ((self = [super initWithCoder:aDecoder])) {
   121         isGameRunning = NO;
   115         isGameRunning = NO;
   122         isReplay = NO;
   116         isReplay = NO;
   123         cachedGrenadeTime = 2;
   117         cachedGrenadeTime = 2;
       
   118 
   124         isAttacking = NO;
   119         isAttacking = NO;
   125         wasVisible = NO;
   120         wasVisible = NO;
   126         isPopoverVisible = NO;    // it is called "popover" even on the iphone
   121         isPopoverVisible = NO;    // it is called "popover" even on the iphone
       
   122         self.view.alpha = 0;
   127     }
   123     }
   128     return self;
   124     return self;
   129 }
   125 }
   130 
   126 
   131 -(void) viewDidLoad {
   127 -(void) viewDidLoad {
   132     CGRect screenRect = [[UIScreen mainScreen] bounds];
   128     CGRect screenRect = [[UIScreen mainScreen] bounds];
   133     self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
   129     self.view.frame = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width);
   134     self.view.alpha = 0;
       
   135     self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2);
   130     self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2);
   136 
   131 
   137     // get the number of screens to know the previous state whan a display is connected or detached
       
   138     initialScreenCount = [[UIScreen screens] count];
       
   139     
       
   140     // detrmine the quanitiy and direction of the rotation
   132     // detrmine the quanitiy and direction of the rotation
   141     if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
   133     if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
   142         a = 180;
   134         a = 180;
   143         b = 0;
   135         b = 0;
   144     } else {
   136     } else {
   145         a = 0;
   137         a = 0;
   146         b = 180;
   138         b = 180;
       
   139     }
       
   140 
       
   141     // get the number of screens to know the previous state whan a display is connected or detached
       
   142     initialScreenCount = [[UIScreen screens] count];
       
   143 
       
   144     // set initial orientation of the controller orientation
       
   145     if (IS_DUALHEAD()) {
       
   146         switch (self.interfaceOrientation) {
       
   147             case UIDeviceOrientationLandscapeLeft:
       
   148                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
       
   149                 break;
       
   150             case UIDeviceOrientationLandscapeRight:
       
   151                 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
       
   152                 break;
       
   153             default:
       
   154                 DLog(@"Nope");
       
   155                 break;
       
   156         }
   147     }
   157     }
   148 
   158 
   149     // the timer used to dim the overlay
   159     // the timer used to dim the overlay
   150     dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6]
   160     dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6]
   151                                         interval:1000
   161                                         interval:1000