30 #import "SDL_config_iphoneos.h" |
30 #import "SDL_config_iphoneos.h" |
31 #import "SDL_mouse.h" |
31 #import "SDL_mouse.h" |
32 |
32 |
33 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
33 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
34 #define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
34 #define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
35 #define doDim() [dimTimer setFireDate: ([[UIScreen screens] count] == 1) ? HIDING_TIME_DEFAULT : HIDING_TIME_NEVER] |
35 #define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT] |
36 #define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
36 #define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
37 |
37 |
38 #define CONFIRMATION_TAG 5959 |
38 #define CONFIRMATION_TAG 5959 |
39 #define GRENADE_TAG 9595 |
39 #define GRENADE_TAG 9595 |
40 #define REPLAYBLACKVIEW_TAG 9955 |
40 #define REPLAYBLACKVIEW_TAG 9955 |
58 [UIView beginAnimations:@"rotation" context:NULL]; |
58 [UIView beginAnimations:@"rotation" context:NULL]; |
59 [UIView setAnimationDuration:0.8f]; |
59 [UIView setAnimationDuration:0.8f]; |
60 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
60 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
61 switch (orientation) { |
61 switch (orientation) { |
62 case UIDeviceOrientationLandscapeLeft: |
62 case UIDeviceOrientationLandscapeLeft: |
63 if ([[UIScreen screens] count] == 1) |
63 if (IS_DUALHEAD() == NO) |
64 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
64 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
65 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
65 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
66 HW_setLandscape(YES); |
66 HW_setLandscape(YES); |
67 break; |
67 break; |
68 case UIDeviceOrientationLandscapeRight: |
68 case UIDeviceOrientationLandscapeRight: |
69 if ([[UIScreen screens] count] == 1) |
69 if (IS_DUALHEAD() == NO) |
70 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
70 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
71 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
71 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
72 HW_setLandscape(YES); |
72 HW_setLandscape(YES); |
73 break; |
73 break; |
74 /* |
74 /* |
109 // i called it a popover even on the iphone |
109 // i called it a popover even on the iphone |
110 isPopoverVisible = NO; |
110 isPopoverVisible = NO; |
111 self.view.alpha = 0; |
111 self.view.alpha = 0; |
112 self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
112 self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
113 |
113 |
|
114 initialScreenCount = [[UIScreen screens] count]; |
|
115 |
114 // set initial orientation wrt the controller orientation |
116 // set initial orientation wrt the controller orientation |
115 UIDeviceOrientation orientation = self.interfaceOrientation; |
117 UIDeviceOrientation orientation = self.interfaceOrientation; |
116 UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
118 UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
117 switch (orientation) { |
119 switch (orientation) { |
118 case UIDeviceOrientationLandscapeLeft: |
120 case UIDeviceOrientationLandscapeLeft: |
119 if ([[UIScreen screens] count] == 1) |
121 if (IS_DUALHEAD() == NO) |
120 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
122 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
121 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
123 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
122 break; |
124 break; |
123 case UIDeviceOrientationLandscapeRight: |
125 case UIDeviceOrientationLandscapeRight: |
124 if ([[UIScreen screens] count] == 1) |
126 if (IS_DUALHEAD() == NO) |
125 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
127 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
126 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
128 self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
127 break; |
129 break; |
128 default: |
130 default: |
129 DLog(@"unknown orientation"); |
131 DLog(@"unknown orientation"); |
130 break; |
132 break; |
131 } |
133 } |
132 CGRect screenRect = [[UIScreen mainScreen] bounds]; |
134 CGRect screenRect = [[UIScreen mainScreen] bounds]; |
133 self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); |
135 self.view.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height); |
134 |
136 |
135 dimTimer = [[NSTimer alloc] initWithFireDate:([[UIScreen screens] count] == 1) ? [NSDate dateWithTimeIntervalSinceNow:6] : HIDING_TIME_NEVER |
137 dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
136 interval:1000 |
138 interval:1000 |
137 target:self |
139 target:self |
138 selector:@selector(dimOverlay) |
140 selector:@selector(dimOverlay) |
139 userInfo:nil |
141 userInfo:nil |
140 repeats:YES]; |
142 repeats:YES]; |
156 [[NSNotificationCenter defaultCenter] addObserver:self |
158 [[NSNotificationCenter defaultCenter] addObserver:self |
157 selector:@selector(cleanup) |
159 selector:@selector(cleanup) |
158 name:@"remove overlay" |
160 name:@"remove overlay" |
159 object:nil]; |
161 object:nil]; |
160 |
162 |
|
163 [[NSNotificationCenter defaultCenter] addObserver:self |
|
164 selector:@selector(numberOfScreensIncreased) |
|
165 name:UIScreenDidConnectNotification |
|
166 object:nil]; |
|
167 |
|
168 [[NSNotificationCenter defaultCenter] addObserver:self |
|
169 selector:@selector(numberOfScreensDecreased) |
|
170 name:UIScreenDidDisconnectNotification |
|
171 object:nil]; |
|
172 |
161 [UIView beginAnimations:@"showing overlay" context:NULL]; |
173 [UIView beginAnimations:@"showing overlay" context:NULL]; |
162 [UIView setAnimationDuration:1]; |
174 [UIView setAnimationDuration:1]; |
163 self.view.alpha = 1; |
175 self.view.alpha = 1; |
164 [UIView commitAnimations]; |
176 [UIView commitAnimations]; |
165 } |
177 } |
|
178 |
|
179 -(void) numberOfScreensIncreased { |
|
180 if (initialScreenCount == 1) { |
|
181 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New display detected" |
|
182 message:NSLocalizedString(@"Hedgewars supports multi-monitor configurations, but the screen has to be connected before launching the game.",@"") |
|
183 delegate:nil |
|
184 cancelButtonTitle:@"Ok" |
|
185 otherButtonTitles:nil]; |
|
186 [alert show]; |
|
187 [alert release]; |
|
188 if (HW_isPaused() == NO) |
|
189 HW_pause(); |
|
190 } |
|
191 } |
|
192 |
|
193 -(void) numberOfScreensDecreased { |
|
194 if (initialScreenCount == 2) { |
|
195 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oh noes! Display disconnected" |
|
196 message:NSLocalizedString(@"A monitor has been disconnected while playing and this has ended the match! You need to restart the game if you wish to use the second display again.",@"") |
|
197 delegate:nil |
|
198 cancelButtonTitle:@"Ok" |
|
199 otherButtonTitles:nil]; |
|
200 [alert show]; |
|
201 [alert release]; |
|
202 [self cleanup]; |
|
203 } |
|
204 } |
|
205 |
166 |
206 |
167 -(void) showHelp:(id) sender { |
207 -(void) showHelp:(id) sender { |
168 if (self.helpPage == nil) |
208 if (self.helpPage == nil) |
169 self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil]; |
209 self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageInGameViewController" bundle:nil]; |
170 self.helpPage.view.alpha = 0; |
210 self.helpPage.view.alpha = 0; |
305 HW_backjump(); |
345 HW_backjump(); |
306 break; |
346 break; |
307 case 10: |
347 case 10: |
308 playSound(@"clickSound"); |
348 playSound(@"clickSound"); |
309 HW_pause(); |
349 HW_pause(); |
310 if (self.amvc.isVisible) { |
350 if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
311 doDim(); |
351 doDim(); |
312 [self.amvc disappear]; |
352 [self.amvc disappear]; |
313 } |
353 } |
314 removeConfirmationInput(); |
354 removeConfirmationInput(); |
315 [self showPopover]; |
355 [self showPopover]; |
316 break; |
356 break; |
317 case 11: |
357 case 11: |
318 playSound(@"clickSound"); |
358 playSound(@"clickSound"); |
319 removeConfirmationInput(); |
359 removeConfirmationInput(); |
320 |
360 |
321 if (self.useClassicMenu) |
361 if (IS_DUALHEAD() || self.useClassicMenu == NO) { |
322 HW_ammoMenu(); |
|
323 else { |
|
324 // TODO: removal and multimonitor experience |
|
325 if (self.amvc == nil) |
362 if (self.amvc == nil) |
326 self.amvc = [[AmmoMenuViewController alloc] init]; |
363 self.amvc = [[AmmoMenuViewController alloc] init]; |
327 |
364 |
328 if (self.amvc.isVisible) { |
365 if (self.amvc.isVisible) { |
329 doDim(); |
366 doDim(); |
330 [self.amvc disappear]; |
367 [self.amvc disappear]; |
331 } else { |
368 } else { |
332 doNotDim(); |
369 doNotDim(); |
333 [self.amvc appearInView:self.view]; |
370 [self.amvc appearInView:self.view]; |
334 } |
371 } |
|
372 } else { |
|
373 HW_ammoMenu(); |
335 } |
374 } |
336 break; |
375 break; |
337 default: |
376 default: |
338 DLog(@"Nope"); |
377 DLog(@"Nope"); |
339 break; |
378 break; |
619 int offset; |
658 int offset; |
620 if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) |
659 if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) |
621 offset = -120; |
660 offset = -120; |
622 else |
661 else |
623 offset = 120; |
662 offset = 120; |
624 if ([[UIScreen screens] count] > 1) |
663 if (IS_DUALHEAD()) |
625 indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + offset); |
664 indicator.center = CGPointMake(theWindow.frame.size.width/2, theWindow.frame.size.height/2 + offset); |
626 else |
665 else |
627 indicator.center = CGPointMake(theWindow.frame.size.width/2 + offset, theWindow.frame.size.height/2); |
666 indicator.center = CGPointMake(theWindow.frame.size.width/2 + offset, theWindow.frame.size.height/2); |
628 indicator.hidesWhenStopped = YES; |
667 indicator.hidesWhenStopped = YES; |
629 [indicator startAnimating]; |
668 [indicator startAnimating]; |
641 setGameRunning(YES); |
680 setGameRunning(YES); |
642 } |
681 } |
643 |
682 |
644 // called by CCHandlers from chNextTurn |
683 // called by CCHandlers from chNextTurn |
645 void clearView() { |
684 void clearView() { |
646 UIWindow *theWindow = ([[UIScreen screens] count] == 1) ? [[UIApplication sharedApplication] keyWindow] : [SDLUIKitDelegate sharedAppDelegate].uiwindow; |
685 UIWindow *theWindow = (IS_DUALHEAD()) ? [SDLUIKitDelegate sharedAppDelegate].uiwindow : [[UIApplication sharedApplication] keyWindow]; |
647 UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; |
686 UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; |
648 UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG]; |
687 UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG]; |
649 |
688 |
650 [UIView beginAnimations:@"remove button" context:NULL]; |
689 [UIView beginAnimations:@"remove button" context:NULL]; |
651 [UIView setAnimationDuration:ANIMATION_DURATION]; |
690 [UIView setAnimationDuration:ANIMATION_DURATION]; |