33 #define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT] |
33 #define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT] |
34 #define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
34 #define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
35 |
35 |
36 |
36 |
37 @implementation OverlayViewController |
37 @implementation OverlayViewController |
38 @synthesize popoverController, popupMenu, helpPage, amvc, initialScreenCount, initialOrientation, |
38 @synthesize popoverController, popupMenu, helpPage, amvc, initialScreenCount, lowerIndicator, savesIndicator, |
39 lowerIndicator, savesIndicator, confirmButton, grenadeTimeSegment; |
39 confirmButton, grenadeTimeSegment; |
40 |
40 |
41 #pragma mark - |
41 #pragma mark - |
42 #pragma mark rotation |
42 #pragma mark rotation |
43 |
43 |
44 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
44 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
45 return rotationManager(interfaceOrientation); |
45 return rotationManager(interfaceOrientation); |
46 } |
|
47 |
|
48 // while in dual head the above rotation functions are not called |
|
49 -(void) handleRotationEvent:(NSNotification *)notification { |
|
50 if (isGameRunning() == NO) |
|
51 return; |
|
52 |
|
53 UIView *sdlView = nil; |
|
54 for (UIView *oneView in [[[UIApplication sharedApplication] keyWindow] subviews]) |
|
55 if ([oneView isMemberOfClass:[SDL_uikitopenglview class]]) { |
|
56 sdlView = (UIView *)oneView; |
|
57 break; |
|
58 } |
|
59 |
|
60 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
|
61 NSInteger angle_left = (self.initialOrientation == UIInterfaceOrientationLandscapeLeft) ? 180 : 0; |
|
62 NSInteger angle_right = (self.initialOrientation == UIInterfaceOrientationLandscapeLeft) ? 0 : 180; |
|
63 |
|
64 NSString *model = getModelType(); |
|
65 if (IS_VERY_POWERFUL(model)) { |
|
66 [UIView beginAnimations:@"overlay rotation" context:NULL]; |
|
67 [UIView setAnimationDuration:0.7]; |
|
68 } |
|
69 switch (orientation) { |
|
70 case UIDeviceOrientationLandscapeLeft: |
|
71 self.view.frame = [[UIScreen mainScreen] bounds]; |
|
72 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
73 if (IS_DUALHEAD() == NO) |
|
74 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(angle_left)); |
|
75 break; |
|
76 case UIDeviceOrientationLandscapeRight: |
|
77 self.view.frame = [[UIScreen mainScreen] bounds]; |
|
78 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
79 if (IS_DUALHEAD() == NO) |
|
80 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(angle_right)); |
|
81 break; |
|
82 default: |
|
83 // a debug log would spam too much |
|
84 break; |
|
85 } |
|
86 if (IS_VERY_POWERFUL(model)) |
|
87 [UIView commitAnimations]; |
|
88 } |
46 } |
89 |
47 |
90 #pragma mark - |
48 #pragma mark - |
91 #pragma mark View Management |
49 #pragma mark View Management |
92 -(id) initWithCoder:(NSCoder *)aDecoder { |
50 -(id) initWithCoder:(NSCoder *)aDecoder { |
93 if ((self = [super initWithCoder:aDecoder])) { |
51 if ((self = [super initWithCoder:aDecoder])) { |
94 isAttacking = NO; |
52 isAttacking = NO; |
95 isPopoverVisible = NO; |
53 isPopoverVisible = NO; |
96 initialScreenCount = (IS_DUALHEAD() ? 2 : 1); |
54 initialScreenCount = (IS_DUALHEAD() ? 2 : 1); |
97 initialOrientation = 0; |
|
98 lowerIndicator = nil; |
55 lowerIndicator = nil; |
99 savesIndicator = nil; |
56 savesIndicator = nil; |
100 } |
57 } |
101 return self; |
58 return self; |
102 } |
59 } |
103 |
60 |
104 -(void) viewDidLoad { |
61 -(void) viewDidLoad { |
105 CGRect screenRect = [[UIScreen mainScreen] bounds]; |
62 // fill all the screen available as sdlview disables autoresizing |
106 self.view.frame = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width); |
63 CGRect rect = [[UIScreen mainScreen] bounds]; |
107 self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2); |
64 self.view.frame = CGRectMake(0, 0, rect.size.height, rect.size.width); |
108 |
65 |
109 // set initial orientation of the controller orientation |
|
110 switch (self.interfaceOrientation) { |
|
111 case UIDeviceOrientationLandscapeLeft: |
|
112 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
113 break; |
|
114 case UIDeviceOrientationLandscapeRight: |
|
115 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
116 break; |
|
117 default: |
|
118 break; |
|
119 } |
|
120 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
121 [[NSNotificationCenter defaultCenter] addObserver:self |
|
122 selector:@selector(handleRotationEvent:) |
|
123 name:UIDeviceOrientationDidChangeNotification |
|
124 object:nil]; |
|
125 |
|
126 // the timer used to dim the overlay |
66 // the timer used to dim the overlay |
127 dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
67 dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
128 interval:1000 |
68 interval:1000 |
129 target:self |
69 target:self |
130 selector:@selector(dimOverlay) |
70 selector:@selector(dimOverlay) |