author | koda |
Thu, 15 Jul 2010 01:18:51 +0200 | |
changeset 3642 | fb39fecca350 |
parent 3639 | b5cdbcc89b61 |
child 3646 | a3271158d93b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// overlayViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 16/03/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "OverlayViewController.h" |
|
10 |
#import "SDL_uikitappdelegate.h" |
|
11 |
#import "PascalImports.h" |
|
12 |
#import "CGPointUtils.h" |
|
13 |
#import "SDL_mouse.h" |
|
14 |
#import "SDL_config_iphoneos.h" |
|
15 |
#import "PopoverMenuViewController.h" |
|
16 |
#import "CommodityFunctions.h" |
|
17 |
||
18 |
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
|
19 |
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
|
20 |
||
21 |
||
22 |
@implementation OverlayViewController |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
23 |
@synthesize popoverController, popupMenu; |
3547 | 24 |
|
25 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
26 |
return rotationManager(interfaceOrientation); |
|
27 |
} |
|
28 |
||
29 |
-(void) didRotate:(NSNotification *)notification { |
|
30 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
|
31 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
|
32 |
CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); |
|
33 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345]; |
|
34 |
||
35 |
[UIView beginAnimations:@"rotation" context:NULL]; |
|
36 |
[UIView setAnimationDuration:0.8f]; |
|
37 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
|
38 |
switch (orientation) { |
|
39 |
case UIDeviceOrientationLandscapeLeft: |
|
40 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
|
41 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
|
42 |
[self chatDisappear]; |
|
43 |
HW_setLandscape(YES); |
|
44 |
break; |
|
45 |
case UIDeviceOrientationLandscapeRight: |
|
46 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
|
47 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
|
48 |
[self chatDisappear]; |
|
49 |
HW_setLandscape(YES); |
|
50 |
break; |
|
3551 | 51 |
/* |
3547 | 52 |
case UIDeviceOrientationPortrait: |
53 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
54 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
|
55 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
|
56 |
[self chatAppear]; |
|
57 |
HW_setLandscape(NO); |
|
58 |
} |
|
59 |
break; |
|
60 |
case UIDeviceOrientationPortraitUpsideDown: |
|
61 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
62 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
|
63 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
|
64 |
[self chatAppear]; |
|
65 |
HW_setLandscape(NO); |
|
66 |
} |
|
67 |
break; |
|
3551 | 68 |
*/ |
3547 | 69 |
default: |
70 |
break; |
|
71 |
} |
|
72 |
self.view.frame = usefulRect; |
|
73 |
//sdlView.frame = usefulRect; |
|
74 |
[UIView commitAnimations]; |
|
75 |
} |
|
76 |
||
77 |
-(void) chatAppear { |
|
3617 | 78 |
/* |
3547 | 79 |
if (writeChatTextField == nil) { |
80 |
writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)]; |
|
81 |
writeChatTextField.textColor = [UIColor whiteColor]; |
|
82 |
writeChatTextField.backgroundColor = [UIColor blueColor]; |
|
83 |
writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; |
|
84 |
writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo; |
|
85 |
writeChatTextField.enablesReturnKeyAutomatically = NO; |
|
86 |
writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault; |
|
87 |
writeChatTextField.keyboardType = UIKeyboardTypeDefault; |
|
88 |
writeChatTextField.returnKeyType = UIReturnKeyDefault; |
|
89 |
writeChatTextField.secureTextEntry = NO; |
|
90 |
[self.view addSubview:writeChatTextField]; |
|
91 |
} |
|
92 |
writeChatTextField.alpha = 1; |
|
93 |
[self activateOverlay]; |
|
94 |
[dimTimer setFireDate:HIDING_TIME_NEVER]; |
|
3617 | 95 |
*/ |
3547 | 96 |
} |
97 |
||
98 |
-(void) chatDisappear { |
|
3617 | 99 |
/* |
3547 | 100 |
writeChatTextField.alpha = 0; |
101 |
[writeChatTextField resignFirstResponder]; |
|
102 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
3617 | 103 |
*/ |
3547 | 104 |
} |
105 |
||
106 |
#pragma mark - |
|
107 |
#pragma mark View Management |
|
108 |
-(void) viewDidLoad { |
|
109 |
isPopoverVisible = NO; |
|
110 |
self.view.alpha = 0; |
|
111 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
|
112 |
||
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
113 |
// set initial orientation |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
114 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
115 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345]; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
116 |
switch (orientation) { |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
117 |
case UIDeviceOrientationLandscapeLeft: |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
118 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
119 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
120 |
break; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
121 |
case UIDeviceOrientationLandscapeRight: |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
122 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
123 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
124 |
break; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
125 |
} |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
126 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
127 |
self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); |
3547 | 128 |
|
129 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
|
130 |
interval:1000 |
|
131 |
target:self |
|
132 |
selector:@selector(dimOverlay) |
|
133 |
userInfo:nil |
|
134 |
repeats:YES]; |
|
135 |
||
136 |
// add timer too runloop, otherwise it doesn't work |
|
137 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
|
138 |
||
139 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
140 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
141 |
selector:@selector(didRotate:) |
|
3598 | 142 |
name:UIDeviceOrientationDidChangeNotification |
3547 | 143 |
object:nil]; |
144 |
||
145 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
|
146 |
[UIView setAnimationDuration:1]; |
|
147 |
self.view.alpha = 1; |
|
148 |
[UIView commitAnimations]; |
|
149 |
} |
|
150 |
||
3626 | 151 |
/* these are causing problems at reloading so let's remove 'em |
3547 | 152 |
-(void) viewDidUnload { |
3617 | 153 |
[dimTimer invalidate]; |
3547 | 154 |
self.popoverController = nil; |
155 |
self.popupMenu = nil; |
|
156 |
[super viewDidUnload]; |
|
157 |
MSG_DIDUNLOAD(); |
|
158 |
} |
|
159 |
||
3626 | 160 |
-(void) didReceiveMemoryWarning { |
161 |
// Releases the view if it doesn't have a superview. |
|
162 |
[super didReceiveMemoryWarning]; |
|
163 |
// Release any cached data, images, etc that aren't in use. |
|
164 |
if (popupMenu.view.superview == nil) |
|
165 |
popupMenu = nil; |
|
166 |
MSG_MEMCLEAN(); |
|
167 |
} |
|
168 |
*/ |
|
169 |
||
3547 | 170 |
-(void) dealloc { |
171 |
[popupMenu release]; |
|
172 |
[popoverController release]; |
|
173 |
// dimTimer is autoreleased |
|
174 |
[super dealloc]; |
|
175 |
} |
|
176 |
||
177 |
#pragma mark - |
|
178 |
#pragma mark Overlay actions and members |
|
179 |
// nice transition for dimming, should be called only by the timer himself |
|
180 |
-(void) dimOverlay { |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
181 |
if (isGameRunning) { |
3547 | 182 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
183 |
[UIView setAnimationDuration:0.6]; |
|
184 |
self.view.alpha = 0.2; |
|
185 |
[UIView commitAnimations]; |
|
186 |
} |
|
187 |
} |
|
188 |
||
189 |
// set the overlay visible and put off the timer for enough time |
|
190 |
-(void) activateOverlay { |
|
191 |
self.view.alpha = 1; |
|
192 |
[dimTimer setFireDate:HIDING_TIME_NEVER]; |
|
193 |
} |
|
194 |
||
3626 | 195 |
// dim the overlay when there's no more input for a certain amount of time |
196 |
-(IBAction) buttonReleased:(id) sender { |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
197 |
if (!isGameRunning) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
198 |
return; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
199 |
|
3626 | 200 |
UIButton *theButton = (UIButton *)sender; |
201 |
||
202 |
switch (theButton.tag) { |
|
203 |
case 0: |
|
204 |
case 1: |
|
205 |
case 2: |
|
206 |
case 3: |
|
207 |
HW_walkingKeysUp(); |
|
208 |
break; |
|
209 |
case 4: |
|
210 |
case 5: |
|
211 |
case 6: |
|
212 |
HW_otherKeysUp(); |
|
213 |
break; |
|
214 |
default: |
|
215 |
NSLog(@"Nope"); |
|
216 |
break; |
|
217 |
} |
|
218 |
||
219 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
220 |
} |
|
221 |
||
3547 | 222 |
// issue certain action based on the tag of the button |
223 |
-(IBAction) buttonPressed:(id) sender { |
|
224 |
[self activateOverlay]; |
|
225 |
if (isPopoverVisible) { |
|
226 |
[self dismissPopover]; |
|
227 |
} |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
228 |
|
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
229 |
if (!isGameRunning) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
230 |
return; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
231 |
|
3547 | 232 |
UIButton *theButton = (UIButton *)sender; |
233 |
||
234 |
switch (theButton.tag) { |
|
235 |
case 0: |
|
236 |
HW_walkLeft(); |
|
237 |
break; |
|
238 |
case 1: |
|
239 |
HW_walkRight(); |
|
240 |
break; |
|
241 |
case 2: |
|
242 |
HW_aimUp(); |
|
243 |
break; |
|
244 |
case 3: |
|
245 |
HW_aimDown(); |
|
246 |
break; |
|
247 |
case 4: |
|
248 |
HW_shoot(); |
|
249 |
break; |
|
250 |
case 5: |
|
251 |
HW_jump(); |
|
252 |
break; |
|
253 |
case 6: |
|
254 |
HW_backjump(); |
|
255 |
break; |
|
256 |
case 7: |
|
257 |
HW_tab(); |
|
258 |
break; |
|
259 |
case 10: |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
260 |
removeConfirmationInput(); |
3547 | 261 |
[self showPopover]; |
262 |
break; |
|
3624 | 263 |
case 11: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
264 |
removeConfirmationInput(); |
3624 | 265 |
HW_ammoMenu(); |
266 |
break; |
|
3547 | 267 |
default: |
3626 | 268 |
DLog(@"Nope"); |
3547 | 269 |
break; |
270 |
} |
|
271 |
} |
|
272 |
||
273 |
// present a further check before closing game |
|
274 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
275 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
276 |
HW_terminate(NO); |
|
277 |
else |
|
278 |
HW_pause(); |
|
279 |
} |
|
280 |
||
281 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
282 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
|
283 |
-(IBAction) showPopover{ |
|
284 |
isPopoverVisible = YES; |
|
285 |
||
286 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
287 |
if (popupMenu == nil) |
|
288 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
|
289 |
if (popoverController == nil) { |
|
290 |
popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
|
291 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
292 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
|
293 |
} |
|
3551 | 294 |
|
295 |
[popoverController presentPopoverFromRect:CGRectMake(1000, 0, 220, 32) |
|
3547 | 296 |
inView:self.view |
297 |
permittedArrowDirections:UIPopoverArrowDirectionUp |
|
298 |
animated:YES]; |
|
299 |
} else { |
|
300 |
if (popupMenu == nil) { |
|
301 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
302 |
popupMenu.view.backgroundColor = [UIColor clearColor]; |
|
303 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
304 |
} |
|
305 |
[self.view addSubview:popupMenu.view]; |
|
306 |
||
307 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
|
308 |
[UIView setAnimationDuration:0.35]; |
|
309 |
popupMenu.view.frame = CGRectMake(280, 0, 200, 170); |
|
310 |
[UIView commitAnimations]; |
|
311 |
} |
|
312 |
popupMenu.tableView.scrollEnabled = NO; |
|
313 |
} |
|
314 |
||
315 |
// on ipad just dismiss it, on iphone transtion to the right |
|
316 |
-(void) dismissPopover { |
|
317 |
if (YES == isPopoverVisible) { |
|
318 |
isPopoverVisible = NO; |
|
319 |
||
320 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
321 |
[popoverController dismissPopoverAnimated:YES]; |
|
322 |
} else { |
|
323 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
324 |
[UIView setAnimationDuration:0.35]; |
|
325 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
326 |
[UIView commitAnimations]; |
|
327 |
||
328 |
[popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
329 |
} |
|
330 |
[self buttonReleased:nil]; |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
-(void) textFieldDoneEditing:(id) sender{ |
|
335 |
[sender resignFirstResponder]; |
|
336 |
} |
|
337 |
||
338 |
||
339 |
#pragma mark - |
|
340 |
#pragma mark Custom touch event handling |
|
341 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
342 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
343 |
UITouch *first, *second; |
3547 | 344 |
|
345 |
if (isPopoverVisible) { |
|
346 |
[self dismissPopover]; |
|
347 |
} |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
348 |
/* |
3547 | 349 |
if (writeChatTextField) { |
350 |
[self.writeChatTextField resignFirstResponder]; |
|
351 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
352 |
} |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
353 |
*/ |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
354 |
|
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
355 |
switch ([allTouches count]) { |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
356 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
357 |
removeConfirmationInput(); |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
358 |
if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
359 |
HW_zoomReset(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
360 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
361 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
362 |
// pinching |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
363 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
364 |
second = [[allTouches allObjects] objectAtIndex:1]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
365 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
366 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
367 |
default: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
368 |
break; |
3547 | 369 |
} |
370 |
} |
|
371 |
||
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
372 |
//if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
373 |
|
3547 | 374 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
3635
38d3e31556d3
improvements to touch interface (tap to select weap, don't move camera for spourious taps, ask for confirmation when using click-weapons)
koda
parents:
3629
diff
changeset
|
375 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
376 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
377 |
CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
378 |
|
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
379 |
switch ([allTouches count]) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
380 |
case 1: |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
381 |
// if we're in the menu we just click in the point |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
382 |
if (HW_isAmmoOpen()) { |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
383 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
384 |
// this click doesn't need any wrapping because the ammoMenu already limits the cursor |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
385 |
HW_click(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
386 |
} else |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
387 |
// if weapon requires a further click, ask for tapping again |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
388 |
if (HW_isWeaponRequiringClick()) { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
389 |
// here don't have to wrap thanks to isCursorVisible magic |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
390 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
391 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
392 |
// draw the button at the last touched point (which is the current position) |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
393 |
UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
394 |
tapAgain.frame = CGRectMake(currentPosition.x - 90, currentPosition.y + 15, 180, 30); |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
395 |
tapAgain.tag = CONFIRMATION_TAG; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
396 |
tapAgain.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
397 |
[tapAgain addTarget:self action:@selector(sendHWClick) forControlEvents:UIControlEventTouchUpInside]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
398 |
[tapAgain setTitle:NSLocalizedString(@"Tap again to confirm",@"from the overlay") forState:UIControlStateNormal]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
399 |
[self.view addSubview:tapAgain]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
400 |
|
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
401 |
// animation ftw! |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
402 |
[UIView beginAnimations:@"inserting button" context:NULL]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
403 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
404 |
[self.view viewWithTag:CONFIRMATION_TAG].alpha = 1; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
405 |
[UIView commitAnimations]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
406 |
} |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
407 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
408 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
409 |
HW_allKeysUp(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
410 |
break; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
411 |
default: |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
412 |
DLog(@"too many touches"); |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
413 |
break; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
414 |
} |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
415 |
|
3635
38d3e31556d3
improvements to touch interface (tap to select weap, don't move camera for spourious taps, ask for confirmation when using click-weapons)
koda
parents:
3629
diff
changeset
|
416 |
initialDistanceForPinching = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
417 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
418 |
|
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
419 |
-(void) sendHWClick { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
420 |
HW_click(); |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
421 |
removeConfirmationInput(); |
3547 | 422 |
} |
423 |
||
424 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
|
425 |
[self touchesEnded:touches withEvent:event]; |
|
426 |
} |
|
427 |
||
428 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3551 | 429 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
430 |
NSSet *allTouches = [event allTouches]; |
3547 | 431 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
432 |
UITouch *touch, *first, *second; |
3547 | 433 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
434 |
switch ([allTouches count]) { |
3551 | 435 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
436 |
touch = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
437 |
CGPoint currentPosition = [touch locationInView:self.view]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
438 |
|
3551 | 439 |
if (HW_isAmmoOpen()) { |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
440 |
// moves the cursor around |
3551 | 441 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3635
38d3e31556d3
improvements to touch interface (tap to select weap, don't move camera for spourious taps, ask for confirmation when using click-weapons)
koda
parents:
3629
diff
changeset
|
442 |
} else { |
38d3e31556d3
improvements to touch interface (tap to select weap, don't move camera for spourious taps, ask for confirmation when using click-weapons)
koda
parents:
3629
diff
changeset
|
443 |
DLog(@"x: %f y: %f -> X:%d Y:%d", currentPosition.x, currentPosition.y, HWX(currentPosition.x), HWY(currentPosition.y)); |
38d3e31556d3
improvements to touch interface (tap to select weap, don't move camera for spourious taps, ask for confirmation when using click-weapons)
koda
parents:
3629
diff
changeset
|
444 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3547 | 445 |
} |
3551 | 446 |
break; |
3547 | 447 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
448 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
449 |
second = [[allTouches allObjects] objectAtIndex:1]; |
3547 | 450 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
451 |
const int pinchDelta = 40; |
|
452 |
||
453 |
if (0 != initialDistanceForPinching) { |
|
454 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
455 |
HW_zoomIn(); |
|
456 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
457 |
} |
|
458 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
459 |
HW_zoomOut(); |
|
460 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
461 |
} |
|
462 |
} else |
|
463 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
464 |
||
465 |
break; |
|
466 |
default: |
|
467 |
break; |
|
468 |
} |
|
469 |
} |
|
470 |
||
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
471 |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
472 |
// called from AddProgress and FinishProgress (respectively) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
473 |
void startSpinning() { |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
474 |
isGameRunning = NO; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
475 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
476 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
477 |
indicator.tag = 987654; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
478 |
indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2); |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
479 |
indicator.hidesWhenStopped = YES; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
480 |
[indicator startAnimating]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
481 |
[[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] addSubview:indicator]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
482 |
[indicator release]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
483 |
} |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
484 |
|
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
485 |
void stopSpinning() { |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
486 |
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:12345] viewWithTag:987654]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
487 |
[indicator stopAnimating]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
488 |
isGameRunning = YES; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
489 |
} |
3547 | 490 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
491 |
void clearView() { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
492 |
UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
493 |
UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
494 |
[UIView beginAnimations:@"remove button" context:NULL]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
495 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
496 |
theButton.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
497 |
[UIView commitAnimations]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
498 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
499 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
500 |
|
3547 | 501 |
@end |