10 #import "SDL_uikitappdelegate.h" |
10 #import "SDL_uikitappdelegate.h" |
11 #import "PascalImports.h" |
11 #import "PascalImports.h" |
12 #import "CGPointUtils.h" |
12 #import "CGPointUtils.h" |
13 #import "SDL_mouse.h" |
13 #import "SDL_mouse.h" |
14 #import "SDL_config_iphoneos.h" |
14 #import "SDL_config_iphoneos.h" |
15 #import "PopoverMenuViewController.h" |
15 #import "InGameMenuViewController.h" |
16 #import "CommodityFunctions.h" |
16 #import "CommodityFunctions.h" |
17 |
17 |
18 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
18 #define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
19 #define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
19 #define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
20 #define doDim() [dimTimer setFireDate:HIDING_TIME_DEFAULT] |
20 #define doDim() [dimTimer setFireDate:HIDING_TIME_DEFAULT] |
42 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
42 [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
43 switch (orientation) { |
43 switch (orientation) { |
44 case UIDeviceOrientationLandscapeLeft: |
44 case UIDeviceOrientationLandscapeLeft: |
45 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
45 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
46 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
46 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
47 [self chatDisappear]; |
|
48 HW_setLandscape(YES); |
47 HW_setLandscape(YES); |
49 break; |
48 break; |
50 case UIDeviceOrientationLandscapeRight: |
49 case UIDeviceOrientationLandscapeRight: |
51 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
50 sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
52 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
51 self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
53 [self chatDisappear]; |
|
54 HW_setLandscape(YES); |
52 HW_setLandscape(YES); |
55 break; |
53 break; |
56 /* |
54 /* |
57 case UIDeviceOrientationPortrait: |
55 case UIDeviceOrientationPortrait: |
58 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
56 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
77 self.view.frame = usefulRect; |
75 self.view.frame = usefulRect; |
78 //sdlView.frame = usefulRect; |
76 //sdlView.frame = usefulRect; |
79 [UIView commitAnimations]; |
77 [UIView commitAnimations]; |
80 } |
78 } |
81 |
79 |
82 -(void) chatAppear { |
|
83 /* |
|
84 if (writeChatTextField == nil) { |
|
85 writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)]; |
|
86 writeChatTextField.textColor = [UIColor whiteColor]; |
|
87 writeChatTextField.backgroundColor = [UIColor blueColor]; |
|
88 writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; |
|
89 writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo; |
|
90 writeChatTextField.enablesReturnKeyAutomatically = NO; |
|
91 writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault; |
|
92 writeChatTextField.keyboardType = UIKeyboardTypeDefault; |
|
93 writeChatTextField.returnKeyType = UIReturnKeyDefault; |
|
94 writeChatTextField.secureTextEntry = NO; |
|
95 [self.view addSubview:writeChatTextField]; |
|
96 } |
|
97 writeChatTextField.alpha = 1; |
|
98 [self activateOverlay]; |
|
99 [dimTimer setFireDate:HIDING_TIME_NEVER]; |
|
100 */ |
|
101 } |
|
102 |
|
103 -(void) chatDisappear { |
|
104 /* |
|
105 writeChatTextField.alpha = 0; |
|
106 [writeChatTextField resignFirstResponder]; |
|
107 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
108 */ |
|
109 } |
|
110 |
|
111 #pragma mark - |
80 #pragma mark - |
112 #pragma mark View Management |
81 #pragma mark View Management |
113 -(void) viewDidLoad { |
82 -(void) viewDidLoad { |
114 isPopoverVisible = NO; |
83 isPopoverVisible = NO; |
115 self.view.alpha = 0; |
84 self.view.alpha = 0; |
149 |
118 |
150 [UIView beginAnimations:@"showing overlay" context:NULL]; |
119 [UIView beginAnimations:@"showing overlay" context:NULL]; |
151 [UIView setAnimationDuration:1]; |
120 [UIView setAnimationDuration:1]; |
152 self.view.alpha = 1; |
121 self.view.alpha = 1; |
153 [UIView commitAnimations]; |
122 [UIView commitAnimations]; |
|
123 |
|
124 // find the sdl window we're on |
|
125 SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
|
126 SDL_VideoDisplay *display = &_this->displays[0]; |
|
127 sdlwindow = display->windows; |
154 } |
128 } |
155 |
129 |
156 /* these are causing problems at reloading so let's remove 'em |
130 /* these are causing problems at reloading so let's remove 'em |
157 -(void) viewDidUnload { |
131 -(void) viewDidUnload { |
158 [dimTimer invalidate]; |
132 [dimTimer invalidate]; |
288 -(IBAction) showPopover{ |
262 -(IBAction) showPopover{ |
289 isPopoverVisible = YES; |
263 isPopoverVisible = YES; |
290 |
264 |
291 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
265 if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
292 if (popupMenu == nil) |
266 if (popupMenu == nil) |
293 popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
267 popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
294 if (popoverController == nil) { |
268 if (popoverController == nil) { |
295 popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
269 popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
296 [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
270 [popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
297 [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
271 [popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
298 } |
272 } |
301 inView:self.view |
275 inView:self.view |
302 permittedArrowDirections:UIPopoverArrowDirectionUp |
276 permittedArrowDirections:UIPopoverArrowDirectionUp |
303 animated:YES]; |
277 animated:YES]; |
304 } else { |
278 } else { |
305 if (popupMenu == nil) { |
279 if (popupMenu == nil) { |
306 popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
280 popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
307 popupMenu.view.backgroundColor = [UIColor clearColor]; |
281 popupMenu.view.backgroundColor = [UIColor clearColor]; |
308 popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
282 popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
309 } |
283 } |
310 [self.view addSubview:popupMenu.view]; |
284 [self.view addSubview:popupMenu.view]; |
311 |
285 |
345 #pragma mark Custom touch event handling |
319 #pragma mark Custom touch event handling |
346 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
320 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
347 NSSet *allTouches = [event allTouches]; |
321 NSSet *allTouches = [event allTouches]; |
348 UITouch *first, *second; |
322 UITouch *first, *second; |
349 |
323 |
350 if (isPopoverVisible) { |
324 // hide in-game menu |
|
325 if (isPopoverVisible) |
351 [self dismissPopover]; |
326 [self dismissPopover]; |
352 } |
327 |
353 /* |
328 // remove keyboard from the view |
354 if (writeChatTextField) { |
329 if (SDL_iPhoneKeyboardIsShown(sdlwindow)) |
355 [self.writeChatTextField resignFirstResponder]; |
330 SDL_iPhoneKeyboardHide(sdlwindow); |
356 [dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
357 } |
|
358 */ |
|
359 |
331 |
360 // reset default dimming |
332 // reset default dimming |
361 doDim(); |
333 doDim(); |
362 |
334 |
363 switch ([allTouches count]) { |
335 switch ([allTouches count]) { |