43 #define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
43 #define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
44 |
44 |
45 @implementation OverlayViewController |
45 @implementation OverlayViewController |
46 @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu; |
46 @synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu; |
47 |
47 |
|
48 #pragma mark - |
|
49 #pragma mark rotation |
48 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
50 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
49 return rotationManager(interfaceOrientation); |
51 if (IS_DUALHEAD()) |
50 } |
52 return YES; ////// TEST MEEEEE |
51 |
53 else |
|
54 return rotationManager(interfaceOrientation); |
|
55 } |
|
56 |
|
57 // pause the game and remove objc menus so that animation is smoother |
|
58 -(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration{ |
|
59 [self dismissPopover]; |
|
60 if (HW_isPaused() == NO) |
|
61 HW_pause(); |
|
62 if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
|
63 [self.amvc disappear]; |
|
64 wasVisible = YES; |
|
65 } else |
|
66 wasVisible = NO; |
|
67 |
|
68 [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; |
|
69 } |
|
70 |
|
71 // now restore previous state |
|
72 -(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation { |
|
73 if (wasVisible || IS_DUALHEAD()) |
|
74 [self.amvc appearInView:self.view]; |
|
75 if (HW_isPaused() == YES) |
|
76 HW_pause(); |
|
77 |
|
78 [super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; |
|
79 } |
|
80 |
|
81 // rotate the sdl view according to the orientation -- the uiview is autorotated |
52 -(void) didRotate:(NSNotification *)notification { |
82 -(void) didRotate:(NSNotification *)notification { |
53 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
83 UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
54 CGRect rect = [[UIScreen mainScreen] bounds]; |
|
55 CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); |
|
56 UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
84 UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
57 |
85 |
58 [UIView beginAnimations:@"rotation" context:NULL]; |
86 [UIView beginAnimations:@"rotation" context:NULL]; |
59 [UIView setAnimationDuration:0.8f]; |
87 [UIView setAnimationDuration:0.7]; |
60 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
|
61 switch (orientation) { |
88 switch (orientation) { |
62 case UIDeviceOrientationLandscapeLeft: |
89 case UIDeviceOrientationLandscapeLeft: |
63 if (IS_DUALHEAD() == NO) |
90 if (IS_DUALHEAD() == NO) |
64 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
91 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(a)); |
65 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
92 //self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
66 break; |
93 break; |
67 case UIDeviceOrientationLandscapeRight: |
94 case UIDeviceOrientationLandscapeRight: |
68 if (IS_DUALHEAD() == NO) |
95 if (IS_DUALHEAD() == NO) |
69 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
96 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(b)); |
70 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
97 //self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
71 break; |
98 break; |
72 case UIDeviceOrientationPortrait: |
99 case UIDeviceOrientationPortrait: |
73 if (IS_DUALHEAD()) |
100 if (IS_DUALHEAD()) |
74 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
101 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
75 break; |
102 break; |
79 break; |
106 break; |
80 default: |
107 default: |
81 // a debug log would spam too much |
108 // a debug log would spam too much |
82 break; |
109 break; |
83 } |
110 } |
84 if (self.amvc.isVisible) |
|
85 [self.amvc appearInView:self.view]; |
|
86 self.view.frame = usefulRect; |
|
87 [UIView commitAnimations]; |
111 [UIView commitAnimations]; |
88 |
112 |
89 // for single screens only landscape mode is supported |
113 // for single screens only landscape mode is supported |
90 // for dual screen mode the sdlview is not modified, but you can rotate the pad in any direction |
114 // for dual screen mode the sdlview is not modified, but you can rotate the pad in any direction |
91 } |
115 } |
92 |
116 |
93 #pragma mark - |
117 #pragma mark - |
94 #pragma mark View Management |
118 #pragma mark View Management |
|
119 -(id) initWithCoder:(NSCoder *)aDecoder { |
|
120 if ((self = [super initWithCoder:aDecoder])) { |
|
121 isGameRunning = NO; |
|
122 isReplay = NO; |
|
123 cachedGrenadeTime = 2; |
|
124 isAttacking = NO; |
|
125 wasVisible = NO; |
|
126 isPopoverVisible = NO; // it is called "popover" even on the iphone |
|
127 } |
|
128 return self; |
|
129 } |
|
130 |
95 -(void) viewDidLoad { |
131 -(void) viewDidLoad { |
96 isGameRunning = NO; |
|
97 isReplay = NO; |
|
98 cachedGrenadeTime = 2; |
|
99 isAttacking = NO; |
|
100 |
|
101 // i called it a popover even on the iphone |
|
102 isPopoverVisible = NO; |
|
103 self.view.alpha = 0; |
|
104 self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
|
105 |
|
106 initialScreenCount = [[UIScreen screens] count]; |
|
107 |
|
108 if (IS_DUALHEAD()) { |
|
109 // set initial orientation wrt 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 case UIDeviceOrientationPortrait: |
|
118 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
|
119 break; |
|
120 case UIDeviceOrientationPortraitUpsideDown: |
|
121 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
|
122 break; |
|
123 default: |
|
124 DLog(@"Nope"); |
|
125 break; |
|
126 } |
|
127 } |
|
128 CGRect screenRect = [[UIScreen mainScreen] bounds]; |
132 CGRect screenRect = [[UIScreen mainScreen] bounds]; |
129 self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); |
133 self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); |
130 |
134 self.view.alpha = 0; |
|
135 self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2); |
|
136 |
|
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 |
|
141 if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { |
|
142 a = 180; |
|
143 b = 0; |
|
144 } else { |
|
145 a = 0; |
|
146 b = 180; |
|
147 } |
|
148 |
|
149 // the timer used to dim the overlay |
131 dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
150 dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
132 interval:1000 |
151 interval:1000 |
133 target:self |
152 target:self |
134 selector:@selector(dimOverlay) |
153 selector:@selector(dimOverlay) |
135 userInfo:nil |
154 userInfo:nil |
136 repeats:YES]; |
155 repeats:YES]; |
137 |
|
138 // add timer to runloop, otherwise it doesn't work |
156 // add timer to runloop, otherwise it doesn't work |
139 [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
157 [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
140 |
158 |
|
159 // become listener of some notifications |
141 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
160 [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
142 [[NSNotificationCenter defaultCenter] addObserver:self |
161 [[NSNotificationCenter defaultCenter] addObserver:self |
143 selector:@selector(didRotate:) |
162 selector:@selector(didRotate:) |
144 name:UIDeviceOrientationDidChangeNotification |
163 name:UIDeviceOrientationDidChangeNotification |
145 object:nil]; |
164 object:nil]; |
379 |
399 |
380 -(void) unsetPreciseStatus { |
400 -(void) unsetPreciseStatus { |
381 HW_preciseSet(NO); |
401 HW_preciseSet(NO); |
382 } |
402 } |
383 |
403 |
|
404 -(void) sendHWClick { |
|
405 HW_click(); |
|
406 removeConfirmationInput(); |
|
407 doDim(); |
|
408 } |
|
409 |
|
410 -(void) setGrenadeTime:(id) sender { |
|
411 UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
412 if (cachedGrenadeTime != theSegment.selectedSegmentIndex) { |
|
413 HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); |
|
414 cachedGrenadeTime = theSegment.selectedSegmentIndex; |
|
415 } |
|
416 } |
|
417 |
|
418 #pragma mark - |
|
419 #pragma mark other menu |
384 // present a further check before closing game |
420 // present a further check before closing game |
385 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
421 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
386 if ([actionSheet cancelButtonIndex] != buttonIndex) |
422 if ([actionSheet cancelButtonIndex] != buttonIndex) |
387 [self cleanup]; |
423 [self cleanup]; |
388 else |
424 else |