author | koda |
Sun, 01 Aug 2010 17:58:09 +0200 | |
changeset 3701 | 8c449776ebe6 |
parent 3697 | d5b30d6373fc |
child 3737 | 2ba6ac8a114b |
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" |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
14 |
#import "InGameMenuViewController.h" |
3547 | 15 |
#import "CommodityFunctions.h" |
3648 | 16 |
#import "SDL_config_iphoneos.h" |
3547 | 17 |
|
18 |
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
|
19 |
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
20 |
#define doDim() [dimTimer setFireDate:HIDING_TIME_DEFAULT] |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
21 |
#define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
3547 | 22 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
23 |
#define CONFIRMATION_TAG 5959 |
3650 | 24 |
#define GRENADE_TAG 9595 |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
25 |
#define ANIMATION_DURATION 0.25 |
3697 | 26 |
#define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
3547 | 27 |
|
28 |
@implementation OverlayViewController |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
29 |
@synthesize popoverController, popupMenu; |
3547 | 30 |
|
31 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
32 |
return rotationManager(interfaceOrientation); |
|
33 |
} |
|
34 |
||
3697 | 35 |
-(void) didRotate:(NSNotification *)notification { |
3547 | 36 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
37 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
|
38 |
CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); |
|
3648 | 39 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
3697 | 40 |
|
3547 | 41 |
[UIView beginAnimations:@"rotation" context:NULL]; |
42 |
[UIView setAnimationDuration:0.8f]; |
|
43 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
|
44 |
switch (orientation) { |
|
45 |
case UIDeviceOrientationLandscapeLeft: |
|
3680 | 46 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
47 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
3547 | 48 |
HW_setLandscape(YES); |
49 |
break; |
|
50 |
case UIDeviceOrientationLandscapeRight: |
|
3680 | 51 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
52 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
3547 | 53 |
HW_setLandscape(YES); |
54 |
break; |
|
3551 | 55 |
/* |
3547 | 56 |
case UIDeviceOrientationPortrait: |
57 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
58 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
|
59 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
|
60 |
[self chatAppear]; |
|
61 |
HW_setLandscape(NO); |
|
62 |
} |
|
63 |
break; |
|
64 |
case UIDeviceOrientationPortraitUpsideDown: |
|
65 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
66 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
|
67 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
|
68 |
[self chatAppear]; |
|
69 |
HW_setLandscape(NO); |
|
70 |
} |
|
71 |
break; |
|
3551 | 72 |
*/ |
3547 | 73 |
default: |
74 |
break; |
|
75 |
} |
|
76 |
self.view.frame = usefulRect; |
|
77 |
//sdlView.frame = usefulRect; |
|
78 |
[UIView commitAnimations]; |
|
79 |
} |
|
80 |
||
81 |
#pragma mark - |
|
82 |
#pragma mark View Management |
|
83 |
-(void) viewDidLoad { |
|
84 |
isPopoverVisible = NO; |
|
85 |
self.view.alpha = 0; |
|
86 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
|
3697 | 87 |
|
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
88 |
// set initial orientation |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
89 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
3650 | 90 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
91 |
switch (orientation) { |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
92 |
case UIDeviceOrientationLandscapeLeft: |
3680 | 93 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
94 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
95 |
break; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
96 |
case UIDeviceOrientationLandscapeRight: |
3680 | 97 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
98 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
99 |
break; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
100 |
default: |
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
101 |
break; |
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
102 |
} |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
103 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
104 |
self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); |
3697 | 105 |
|
3547 | 106 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
107 |
interval:1000 |
|
108 |
target:self |
|
109 |
selector:@selector(dimOverlay) |
|
110 |
userInfo:nil |
|
111 |
repeats:YES]; |
|
3697 | 112 |
|
3547 | 113 |
// add timer too runloop, otherwise it doesn't work |
114 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
|
3697 | 115 |
|
116 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
3547 | 117 |
[[NSNotificationCenter defaultCenter] addObserver:self |
118 |
selector:@selector(didRotate:) |
|
3598 | 119 |
name:UIDeviceOrientationDidChangeNotification |
3547 | 120 |
object:nil]; |
121 |
||
122 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
|
123 |
[UIView setAnimationDuration:1]; |
|
124 |
self.view.alpha = 1; |
|
125 |
[UIView commitAnimations]; |
|
3697 | 126 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
127 |
// find the sdl window we're on |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
128 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
129 |
SDL_VideoDisplay *display = &_this->displays[0]; |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
130 |
sdlwindow = display->windows; |
3701 | 131 |
|
132 |
doDim(); |
|
3547 | 133 |
} |
134 |
||
135 |
-(void) viewDidUnload { |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3661
diff
changeset
|
136 |
// only object initialized in viewDidLoad should be here |
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3661
diff
changeset
|
137 |
dimTimer = nil; |
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3661
diff
changeset
|
138 |
MSG_DIDUNLOAD(); |
3547 | 139 |
[super viewDidUnload]; |
140 |
} |
|
141 |
||
3626 | 142 |
-(void) didReceiveMemoryWarning { |
143 |
// Releases the view if it doesn't have a superview. |
|
144 |
[super didReceiveMemoryWarning]; |
|
145 |
// Release any cached data, images, etc that aren't in use. |
|
3697 | 146 |
if (popupMenu.view.superview == nil) |
3626 | 147 |
popupMenu = nil; |
148 |
MSG_MEMCLEAN(); |
|
149 |
} |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3661
diff
changeset
|
150 |
|
3626 | 151 |
|
3547 | 152 |
-(void) dealloc { |
153 |
[popupMenu release]; |
|
154 |
[popoverController release]; |
|
155 |
// dimTimer is autoreleased |
|
156 |
[super dealloc]; |
|
157 |
} |
|
158 |
||
159 |
#pragma mark - |
|
160 |
#pragma mark Overlay actions and members |
|
161 |
// nice transition for dimming, should be called only by the timer himself |
|
162 |
-(void) dimOverlay { |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
163 |
if (isGameRunning) { |
3547 | 164 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
165 |
[UIView setAnimationDuration:0.6]; |
|
166 |
self.view.alpha = 0.2; |
|
167 |
[UIView commitAnimations]; |
|
168 |
} |
|
169 |
} |
|
170 |
||
171 |
// set the overlay visible and put off the timer for enough time |
|
172 |
-(void) activateOverlay { |
|
173 |
self.view.alpha = 1; |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
174 |
doNotDim(); |
3547 | 175 |
} |
176 |
||
3626 | 177 |
// dim the overlay when there's no more input for a certain amount of time |
178 |
-(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
|
179 |
if (!isGameRunning) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
180 |
return; |
3697 | 181 |
|
3626 | 182 |
UIButton *theButton = (UIButton *)sender; |
3697 | 183 |
|
3626 | 184 |
switch (theButton.tag) { |
185 |
case 0: |
|
186 |
case 1: |
|
187 |
case 2: |
|
188 |
case 3: |
|
3649 | 189 |
[NSObject cancelPreviousPerformRequestsWithTarget:self |
190 |
selector:@selector(unsetPreciseStatus) |
|
191 |
object:nil]; |
|
3626 | 192 |
HW_walkingKeysUp(); |
193 |
break; |
|
194 |
case 4: |
|
195 |
case 5: |
|
196 |
case 6: |
|
197 |
HW_otherKeysUp(); |
|
198 |
break; |
|
199 |
default: |
|
3660 | 200 |
DLog(@"Nope"); |
3626 | 201 |
break; |
202 |
} |
|
203 |
||
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
204 |
doDim(); |
3626 | 205 |
} |
206 |
||
3697 | 207 |
// issue certain action based on the tag of the button |
3547 | 208 |
-(IBAction) buttonPressed:(id) sender { |
209 |
[self activateOverlay]; |
|
210 |
if (isPopoverVisible) { |
|
211 |
[self dismissPopover]; |
|
212 |
} |
|
3697 | 213 |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
214 |
if (!isGameRunning) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
215 |
return; |
3697 | 216 |
|
3547 | 217 |
UIButton *theButton = (UIButton *)sender; |
3697 | 218 |
|
3547 | 219 |
switch (theButton.tag) { |
220 |
case 0: |
|
221 |
HW_walkLeft(); |
|
222 |
break; |
|
223 |
case 1: |
|
224 |
HW_walkRight(); |
|
225 |
break; |
|
226 |
case 2: |
|
3649 | 227 |
[self performSelector:@selector(unsetPreciseStatus) withObject:nil afterDelay:0.8]; |
228 |
HW_preciseSet(YES); |
|
3547 | 229 |
HW_aimUp(); |
230 |
break; |
|
231 |
case 3: |
|
3649 | 232 |
[self performSelector:@selector(unsetPreciseStatus) withObject:nil afterDelay:0.8]; |
233 |
HW_preciseSet(YES); |
|
3547 | 234 |
HW_aimDown(); |
235 |
break; |
|
236 |
case 4: |
|
237 |
HW_shoot(); |
|
238 |
break; |
|
239 |
case 5: |
|
240 |
HW_jump(); |
|
241 |
break; |
|
242 |
case 6: |
|
243 |
HW_backjump(); |
|
244 |
break; |
|
245 |
case 7: |
|
246 |
HW_tab(); |
|
247 |
break; |
|
248 |
case 10: |
|
3667 | 249 |
HW_pause(); |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
250 |
removeConfirmationInput(); |
3547 | 251 |
[self showPopover]; |
252 |
break; |
|
3624 | 253 |
case 11: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
254 |
removeConfirmationInput(); |
3624 | 255 |
HW_ammoMenu(); |
256 |
break; |
|
3547 | 257 |
default: |
3626 | 258 |
DLog(@"Nope"); |
3547 | 259 |
break; |
260 |
} |
|
261 |
} |
|
262 |
||
3649 | 263 |
-(void) unsetPreciseStatus { |
264 |
HW_preciseSet(NO); |
|
265 |
} |
|
266 |
||
3547 | 267 |
// present a further check before closing game |
268 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
269 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
270 |
HW_terminate(NO); |
|
271 |
else |
|
3697 | 272 |
HW_pause(); |
3547 | 273 |
} |
274 |
||
275 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
276 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
|
277 |
-(IBAction) showPopover{ |
|
3667 | 278 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 279 |
isPopoverVisible = YES; |
280 |
||
281 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3697 | 282 |
if (popupMenu == nil) |
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
283 |
popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
3547 | 284 |
if (popoverController == nil) { |
285 |
popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
|
286 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
287 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
|
288 |
} |
|
3551 | 289 |
|
3667 | 290 |
[popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
3547 | 291 |
inView:self.view |
3667 | 292 |
permittedArrowDirections:UIPopoverArrowDirectionAny |
3547 | 293 |
animated:YES]; |
294 |
} else { |
|
3648 | 295 |
if (popupMenu == nil) |
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
296 |
popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3697 | 297 |
|
3547 | 298 |
[self.view addSubview:popupMenu.view]; |
3648 | 299 |
[popupMenu present]; |
3547 | 300 |
} |
301 |
popupMenu.tableView.scrollEnabled = NO; |
|
302 |
} |
|
303 |
||
304 |
// on ipad just dismiss it, on iphone transtion to the right |
|
305 |
-(void) dismissPopover { |
|
306 |
if (YES == isPopoverVisible) { |
|
307 |
isPopoverVisible = NO; |
|
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
308 |
if (HW_isPaused()) |
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
309 |
HW_pause(); |
3697 | 310 |
|
3547 | 311 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
3648 | 312 |
[(InGameMenuViewController *)popoverController.contentViewController removeChat]; |
3547 | 313 |
[popoverController dismissPopoverAnimated:YES]; |
314 |
} else { |
|
3648 | 315 |
[popupMenu dismiss]; |
3547 | 316 |
} |
317 |
[self buttonReleased:nil]; |
|
318 |
} |
|
319 |
} |
|
320 |
||
321 |
#pragma mark - |
|
322 |
#pragma mark Custom touch event handling |
|
323 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
324 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
325 |
UITouch *first, *second; |
3697 | 326 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
327 |
// hide in-game menu |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
328 |
if (isPopoverVisible) |
3547 | 329 |
[self dismissPopover]; |
3697 | 330 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
331 |
// reset default dimming |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
332 |
doDim(); |
3697 | 333 |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
334 |
HW_setPianoSound([allTouches count]); |
3697 | 335 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
336 |
switch ([allTouches count]) { |
3697 | 337 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
338 |
removeConfirmationInput(); |
3651 | 339 |
startingPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
340 |
if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
341 |
HW_zoomReset(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
342 |
break; |
3697 | 343 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
344 |
// pinching |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
345 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
346 |
second = [[allTouches allObjects] objectAtIndex:1]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
347 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
348 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
349 |
default: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
350 |
break; |
3547 | 351 |
} |
352 |
} |
|
353 |
||
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
354 |
//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
|
355 |
|
3547 | 356 |
-(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
|
357 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
358 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
359 |
CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3697 | 360 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
361 |
switch ([allTouches count]) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
362 |
case 1: |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
363 |
// 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
|
364 |
if (HW_isAmmoOpen()) { |
3680 | 365 |
HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
366 |
// 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
|
367 |
HW_click(); |
3697 | 368 |
} else |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
369 |
// 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
|
370 |
if (HW_isWeaponRequiringClick()) { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
371 |
// 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
|
372 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3697 | 373 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
374 |
// 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
|
375 |
UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
376 |
tapAgain.frame = CGRectMake(currentPosition.x - 75, currentPosition.y + 25, 150, 40); |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
377 |
tapAgain.tag = CONFIRMATION_TAG; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
378 |
tapAgain.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
379 |
[tapAgain addTarget:self action:@selector(sendHWClick) forControlEvents:UIControlEventTouchUpInside]; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
380 |
[tapAgain setTitle:NSLocalizedString(@"Tap to set!",@"from the overlay") forState:UIControlStateNormal]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
381 |
[self.view addSubview:tapAgain]; |
3697 | 382 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
383 |
// animation ftw! |
3697 | 384 |
[UIView beginAnimations:@"inserting button" context:NULL]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
385 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
386 |
[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
|
387 |
[UIView commitAnimations]; |
3697 | 388 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
389 |
// keep the overlay active, or the button will fade |
3650 | 390 |
[self activateOverlay]; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
391 |
doNotDim(); |
3650 | 392 |
} else |
393 |
if (HW_isWeaponTimerable()) { |
|
394 |
if (isSegmentVisible) { |
|
395 |
UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG]; |
|
3697 | 396 |
|
3650 | 397 |
[UIView beginAnimations:@"removing segmented control" context:NULL]; |
398 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
399 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
400 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
401 |
[UIView commitAnimations]; |
|
3697 | 402 |
|
3650 | 403 |
[grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION]; |
404 |
} else { |
|
405 |
NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; |
|
406 |
UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items]; |
|
407 |
[items release]; |
|
3697 | 408 |
|
3650 | 409 |
[grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged]; |
410 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
411 |
grenadeTime.selectedSegmentIndex = 2; |
|
412 |
grenadeTime.tag = GRENADE_TAG; |
|
413 |
[self.view addSubview:grenadeTime]; |
|
414 |
[grenadeTime release]; |
|
3697 | 415 |
|
3650 | 416 |
[UIView beginAnimations:@"inserting segmented control" context:NULL]; |
417 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
418 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
419 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50); |
|
420 |
[UIView commitAnimations]; |
|
3697 | 421 |
|
3650 | 422 |
[self activateOverlay]; |
423 |
doNotDim(); |
|
3697 | 424 |
} |
3650 | 425 |
isSegmentVisible = !isSegmentVisible; |
3661 | 426 |
} else |
427 |
if (HW_isWeaponSwitch()) |
|
428 |
HW_tab(); |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
429 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
430 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
431 |
HW_allKeysUp(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
432 |
break; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
433 |
default: |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
434 |
break; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
435 |
} |
3697 | 436 |
|
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
|
437 |
initialDistanceForPinching = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
438 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
439 |
|
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
440 |
-(void) sendHWClick { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
441 |
HW_click(); |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
442 |
removeConfirmationInput(); |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
443 |
doDim(); |
3547 | 444 |
} |
445 |
||
3650 | 446 |
-(void) setGrenadeTime:(id) sender { |
447 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
448 |
HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); |
|
449 |
} |
|
450 |
||
3547 | 451 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
452 |
[self touchesEnded:touches withEvent:event]; |
|
453 |
} |
|
454 |
||
455 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3551 | 456 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
457 |
NSSet *allTouches = [event allTouches]; |
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3661
diff
changeset
|
458 |
int x, y, dx, dy; |
3697 | 459 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
460 |
UITouch *touch, *first, *second; |
3547 | 461 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
462 |
switch ([allTouches count]) { |
3551 | 463 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
464 |
touch = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
465 |
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
|
466 |
|
3680 | 467 |
if (HW_isAmmoOpen()) { |
468 |
// no zoom consideration for this |
|
469 |
HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); |
|
470 |
} else |
|
471 |
if (HW_isWeaponRequiringClick()) { |
|
472 |
// moves the cursor around wrt zoom |
|
473 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
|
474 |
} else { |
|
475 |
// panning \o/ |
|
476 |
dx = startingPoint.x - currentPosition.x; |
|
477 |
dy = currentPosition.y - startingPoint.y; |
|
478 |
HW_getCursor(&x, &y); |
|
479 |
// momentum (or something like that) |
|
480 |
/*if (abs(dx) > 40) |
|
481 |
dx *= log(abs(dx)/4); |
|
482 |
if (abs(dy) > 40) |
|
483 |
dy *= log(abs(dy)/4);*/ |
|
484 |
HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor()); |
|
485 |
startingPoint = currentPosition; |
|
486 |
} |
|
3551 | 487 |
break; |
3547 | 488 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
489 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
490 |
second = [[allTouches allObjects] objectAtIndex:1]; |
3547 | 491 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
492 |
const int pinchDelta = 40; |
|
3697 | 493 |
|
3547 | 494 |
if (0 != initialDistanceForPinching) { |
495 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
496 |
HW_zoomIn(); |
|
497 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
498 |
} |
|
499 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
500 |
HW_zoomOut(); |
|
501 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
502 |
} |
|
3697 | 503 |
} else |
3547 | 504 |
initialDistanceForPinching = currentDistanceOfPinching; |
3697 | 505 |
|
3547 | 506 |
break; |
507 |
default: |
|
508 |
break; |
|
509 |
} |
|
510 |
} |
|
511 |
||
3650 | 512 |
#pragma mark - |
513 |
#pragma mark Functions called by pascal |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
514 |
// 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
|
515 |
void startSpinning() { |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
516 |
isGameRunning = NO; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
517 |
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
|
518 |
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
|
519 |
indicator.tag = 987654; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
520 |
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
|
521 |
indicator.hidesWhenStopped = YES; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
522 |
[indicator startAnimating]; |
3650 | 523 |
[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] addSubview:indicator]; |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
524 |
[indicator release]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
525 |
} |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
526 |
|
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
527 |
void stopSpinning() { |
3650 | 528 |
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654]; |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
529 |
[indicator stopAnimating]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
530 |
isGameRunning = YES; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
531 |
} |
3547 | 532 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
533 |
void clearView() { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
534 |
UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
535 |
UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; |
3650 | 536 |
UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG]; |
3697 | 537 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
538 |
[UIView beginAnimations:@"remove button" context:NULL]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
539 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
540 |
theButton.alpha = 0; |
3650 | 541 |
theSegment.alpha = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
542 |
[UIView commitAnimations]; |
3697 | 543 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
544 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3]; |
3697 | 545 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
546 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
547 |
|
3547 | 548 |
@end |