9 #import "overlayViewController.h" |
9 #import "overlayViewController.h" |
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 "SettingsViewController.h" |
|
15 #import "popupMenuViewController.h" |
14 #import "popupMenuViewController.h" |
16 |
15 |
17 @implementation overlayViewController |
16 @implementation overlayViewController |
18 @synthesize dimTimer; |
17 @synthesize dimTimer, menuPopover; |
19 |
18 |
20 |
19 |
21 -(void) didReceiveMemoryWarning { |
20 -(void) didReceiveMemoryWarning { |
22 // Releases the view if it doesn't have a superview. |
21 // Releases the view if it doesn't have a superview. |
23 [super didReceiveMemoryWarning]; |
22 [super didReceiveMemoryWarning]; |
37 target:self |
36 target:self |
38 selector:@selector(dimOverlay) |
37 selector:@selector(dimOverlay) |
39 userInfo:nil |
38 userInfo:nil |
40 repeats:YES]; |
39 repeats:YES]; |
41 |
40 |
|
41 // add timer too runloop, otherwise it doesn't work |
42 [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
42 [[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
43 |
43 // listen for dismissal of the popover (see below)x |
|
44 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dismissPopover) name:@"dismissPopover" object:nil]; |
|
45 // present the overlay after 2 seconds |
44 [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO]; |
46 [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(showMenuAfterwards) userInfo:nil repeats:NO]; |
45 } |
47 } |
46 |
48 |
47 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
49 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
48 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
50 return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); |
139 NSLog(@"Nope"); |
142 NSLog(@"Nope"); |
140 break; |
143 break; |
141 } |
144 } |
142 } |
145 } |
143 |
146 |
|
147 // present a further check before closing game |
144 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
148 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
145 if ([actionSheet cancelButtonIndex] != buttonIndex) |
149 if ([actionSheet cancelButtonIndex] != buttonIndex) |
146 HW_terminate(NO); |
150 HW_terminate(NO); |
147 else |
151 else |
148 HW_pause(); |
152 HW_pause(); |
149 } |
153 } |
150 |
154 |
|
155 // show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
151 -(IBAction) showPopover{ |
156 -(IBAction) showPopover{ |
152 popupMenuViewController *popupMenu = [[popupMenuViewController alloc] initWithNibName:@"popupMenuViewController" bundle:nil]; |
157 popupMenuViewController *popupMenu = [[popupMenuViewController alloc] initWithNibName:@"popupMenuViewController" bundle:nil]; |
153 UIPopoverController* aPopover = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
158 |
154 [aPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
159 menuPopover = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
|
160 [menuPopover setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
155 |
161 |
156 /*UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
162 /*UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
157 button.frame= CGRectMake(960, 0, 64, 64); |
163 button.frame= CGRectMake(960, 0, 64, 64); |
158 button.titleLabel.text=@"UUUUUUUF"; |
164 button.titleLabel.text=@"UUUUUUUF"; |
159 [self.view addSubview:button];*/ |
165 [self.view addSubview:button];*/ |
160 |
166 |
161 [aPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; |
167 [menuPopover presentPopoverFromRect:CGRectMake(960, 0, 220, 32) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; |
162 //UIBarButtonItem *sender = [[useless items] objectAtIndex:1]; |
168 //UIBarButtonItem *sender = [[useless items] objectAtIndex:1]; |
163 //[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; |
169 //[self.popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; |
164 } |
170 } |
165 |
171 |
|
172 // because of the actionSheet, the popOver might not get dismissed, so we do it manually (through a NSNotification system, see above) |
|
173 -(void) dismissPopover { |
|
174 if (menuPopover.popoverVisible) |
|
175 [menuPopover dismissPopoverAnimated:YES]; |
|
176 } |
166 |
177 |
167 #pragma mark - |
178 #pragma mark - |
168 #pragma mark Custom SDL_UIView input handling |
|
169 #define kMinimumPinchDelta 50 |
179 #define kMinimumPinchDelta 50 |
170 #define kMinimumGestureLength 10 |
180 #define kMinimumGestureLength 10 |
171 #define kMaximumVariance 3 |
181 #define kMaximumVariance 3 |
172 |
182 |
173 // we override default touch input to implement our own gestures |
|
174 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
183 -(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
175 NSArray *twoTouches; |
184 NSArray *twoTouches; |
176 UITouch *touch = [touches anyObject]; |
185 UITouch *touch = [touches anyObject]; |
177 |
186 |
178 switch ([touches count]) { |
187 switch ([touches count]) { |