author | sheepluva |
Wed, 29 Dec 2010 14:59:56 +0100 | |
changeset 4774 | d81c6e14416d |
parent 4541 | c77c4f5d49d3 |
child 4855 | 2480ab325057 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 16/03/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "OverlayViewController.h" |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
23 |
#import "InGameMenuViewController.h" |
3792 | 24 |
#import "HelpPageViewController.h" |
3924 | 25 |
#import "AmmoMenuViewController.h" |
3547 | 26 |
#import "PascalImports.h" |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
27 |
#import "CommodityFunctions.h" |
3547 | 28 |
#import "CGPointUtils.h" |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
29 |
#import "SDL_config_iphoneos.h" |
3547 | 30 |
#import "SDL_mouse.h" |
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
31 |
#import "ObjcExports.h" |
3547 | 32 |
|
33 |
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
|
34 |
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
|
3941 | 35 |
#define doDim() [dimTimer setFireDate: (IS_DUALHEAD()) ? HIDING_TIME_NEVER : HIDING_TIME_DEFAULT] |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
36 |
#define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
3547 | 37 |
|
3697 | 38 |
#define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
3547 | 39 |
|
40 |
@implementation OverlayViewController |
|
4454 | 41 |
@synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation, containerWindow; |
3547 | 42 |
|
3976 | 43 |
#pragma mark - |
44 |
#pragma mark rotation |
|
3547 | 45 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
4356 | 46 |
// don't rotate until the game is running for performance and synchronization with the sdlview |
47 |
if (isGameRunning() == NO) |
|
48 |
return (interfaceOrientation == (UIInterfaceOrientation) self.initialOrientation); |
|
3977 | 49 |
return rotationManager(interfaceOrientation); |
3547 | 50 |
} |
51 |
||
3976 | 52 |
// pause the game and remove objc menus so that animation is smoother |
53 |
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration{ |
|
4356 | 54 |
if (isGameRunning() == NO) |
55 |
return; |
|
56 |
||
4454 | 57 |
HW_pause(); |
3976 | 58 |
[self dismissPopover]; |
4454 | 59 |
|
3976 | 60 |
if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
61 |
[self.amvc disappear]; |
|
62 |
wasVisible = YES; |
|
63 |
} else |
|
64 |
wasVisible = NO; |
|
65 |
||
66 |
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration]; |
|
4078 | 67 |
|
68 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
|
69 |
switch (toInterfaceOrientation) { |
|
70 |
case UIDeviceOrientationLandscapeLeft: |
|
71 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(a)); |
|
72 |
break; |
|
73 |
case UIDeviceOrientationLandscapeRight: |
|
74 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(b)); |
|
75 |
break; |
|
76 |
default: |
|
77 |
// a debug log would spam too much |
|
78 |
break; |
|
79 |
} |
|
3976 | 80 |
} |
81 |
||
82 |
// now restore previous state |
|
83 |
-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation) fromInterfaceOrientation { |
|
4356 | 84 |
if (isGameRunning() == NO) |
85 |
return; |
|
86 |
||
3976 | 87 |
if (wasVisible || IS_DUALHEAD()) |
88 |
[self.amvc appearInView:self.view]; |
|
4454 | 89 |
HW_pauseToggle(); |
3976 | 90 |
|
91 |
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; |
|
92 |
} |
|
93 |
||
4078 | 94 |
// while in dual head the above rotation functions are not called |
95 |
-(void) dualHeadRotation:(NSNotification *)notification { |
|
4356 | 96 |
if (isGameRunning() == NO) |
97 |
return; |
|
98 |
||
3547 | 99 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
3977 | 100 |
|
3547 | 101 |
[UIView beginAnimations:@"rotation" context:NULL]; |
3976 | 102 |
[UIView setAnimationDuration:0.7]; |
3547 | 103 |
switch (orientation) { |
104 |
case UIDeviceOrientationLandscapeLeft: |
|
4078 | 105 |
self.view.frame = [[UIScreen mainScreen] bounds]; |
106 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
3547 | 107 |
break; |
108 |
case UIDeviceOrientationLandscapeRight: |
|
4078 | 109 |
self.view.frame = [[UIScreen mainScreen] bounds]; |
110 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
111 |
break; |
3547 | 112 |
default: |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
113 |
// a debug log would spam too much |
3547 | 114 |
break; |
115 |
} |
|
116 |
[UIView commitAnimations]; |
|
117 |
} |
|
118 |
||
119 |
#pragma mark - |
|
120 |
#pragma mark View Management |
|
3976 | 121 |
-(id) initWithCoder:(NSCoder *)aDecoder { |
122 |
if ((self = [super initWithCoder:aDecoder])) { |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
123 |
objcExportsInit(); |
3976 | 124 |
isAttacking = NO; |
125 |
wasVisible = NO; |
|
126 |
isPopoverVisible = NO; // it is called "popover" even on the iphone |
|
127 |
} |
|
128 |
return self; |
|
129 |
} |
|
3948
24daa33a3114
some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
koda
parents:
3941
diff
changeset
|
130 |
|
3976 | 131 |
-(void) viewDidLoad { |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
132 |
CGRect screenRect = [[UIScreen mainScreen] bounds]; |
3977 | 133 |
self.view.frame = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width); |
3976 | 134 |
self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2); |
3978 | 135 |
self.view.alpha = 0; |
3697 | 136 |
|
3976 | 137 |
// detrmine the quanitiy and direction of the rotation |
138 |
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { |
|
139 |
a = 180; |
|
140 |
b = 0; |
|
141 |
} else { |
|
142 |
a = 0; |
|
143 |
b = 180; |
|
144 |
} |
|
145 |
||
3977 | 146 |
// get the number of screens to know the previous state whan a display is connected or detached |
4082 | 147 |
if ([UIScreen respondsToSelector:@selector(screens)]) |
148 |
initialScreenCount = [[UIScreen screens] count]; |
|
149 |
else |
|
150 |
initialScreenCount = 1; |
|
3977 | 151 |
|
152 |
// set initial orientation of the controller orientation |
|
153 |
if (IS_DUALHEAD()) { |
|
154 |
switch (self.interfaceOrientation) { |
|
155 |
case UIDeviceOrientationLandscapeLeft: |
|
156 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
157 |
break; |
|
158 |
case UIDeviceOrientationLandscapeRight: |
|
159 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
160 |
break; |
|
161 |
default: |
|
162 |
DLog(@"Nope"); |
|
163 |
break; |
|
164 |
} |
|
4078 | 165 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
166 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
167 |
selector:@selector(dualHeadRotation:) |
|
168 |
name:UIDeviceOrientationDidChangeNotification |
|
169 |
object:nil]; |
|
3977 | 170 |
} |
171 |
||
3976 | 172 |
// the timer used to dim the overlay |
3941 | 173 |
dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
3547 | 174 |
interval:1000 |
175 |
target:self |
|
176 |
selector:@selector(dimOverlay) |
|
177 |
userInfo:nil |
|
178 |
repeats:YES]; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
179 |
// add timer to runloop, otherwise it doesn't work |
3547 | 180 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
3697 | 181 |
|
3976 | 182 |
// become listener of some notifications |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
183 |
[[NSNotificationCenter defaultCenter] addObserver:self |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
184 |
selector:@selector(showHelp:) |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
185 |
name:@"show help ingame" |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
186 |
object:nil]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
187 |
|
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
188 |
[[NSNotificationCenter defaultCenter] addObserver:self |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
189 |
selector:@selector(cleanup) |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
190 |
name:@"remove overlay" |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
191 |
object:nil]; |
4082 | 192 |
|
4098
40df542b5f62
i give up and disable rotation on the iphone; also fix smaller compilation issues
koda
parents:
4082
diff
changeset
|
193 |
// for iOS >= 3.2 |
4082 | 194 |
if ([UIScreen respondsToSelector:@selector(screens)]) { |
195 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
196 |
selector:@selector(numberOfScreensIncreased) |
|
197 |
name:UIScreenDidConnectNotification |
|
198 |
object:nil]; |
|
199 |
||
200 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
201 |
selector:@selector(numberOfScreensDecreased) |
|
202 |
name:UIScreenDidDisconnectNotification |
|
203 |
object:nil]; |
|
204 |
} |
|
4454 | 205 |
|
206 |
self.containerWindow = [[UIApplication sharedApplication] keyWindow]; |
|
3976 | 207 |
|
208 |
// present the overlay |
|
3547 | 209 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
4098
40df542b5f62
i give up and disable rotation on the iphone; also fix smaller compilation issues
koda
parents:
4082
diff
changeset
|
210 |
[UIView setAnimationDuration:2]; |
3547 | 211 |
self.view.alpha = 1; |
212 |
[UIView commitAnimations]; |
|
213 |
} |
|
214 |
||
3941 | 215 |
-(void) numberOfScreensIncreased { |
216 |
if (initialScreenCount == 1) { |
|
217 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New display detected" |
|
218 |
message:NSLocalizedString(@"Hedgewars supports multi-monitor configurations, but the screen has to be connected before launching the game.",@"") |
|
219 |
delegate:nil |
|
220 |
cancelButtonTitle:@"Ok" |
|
221 |
otherButtonTitles:nil]; |
|
222 |
[alert show]; |
|
223 |
[alert release]; |
|
4454 | 224 |
HW_pause(); |
3941 | 225 |
} |
226 |
} |
|
227 |
||
228 |
-(void) numberOfScreensDecreased { |
|
229 |
if (initialScreenCount == 2) { |
|
230 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oh noes! Display disconnected" |
|
231 |
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.",@"") |
|
232 |
delegate:nil |
|
233 |
cancelButtonTitle:@"Ok" |
|
234 |
otherButtonTitles:nil]; |
|
235 |
[alert show]; |
|
236 |
[alert release]; |
|
237 |
[self cleanup]; |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
||
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
242 |
-(void) showHelp:(id) sender { |
4144 | 243 |
if (self.helpPage == nil) { |
244 |
NSString *xib; |
|
245 |
if (IS_IPAD()) |
|
246 |
xib = @"HelpPageInGameViewController-iPad"; |
|
247 |
else |
|
248 |
xib = @"HelpPageInGameViewController-iPhone"; |
|
249 |
self.helpPage = [[HelpPageViewController alloc] initWithNibName:xib bundle:nil]; |
|
250 |
} |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
251 |
self.helpPage.view.alpha = 0; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
252 |
[self.view addSubview:helpPage.view]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
253 |
[UIView beginAnimations:@"helpingame" context:NULL]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
254 |
self.helpPage.view.alpha = 1; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
255 |
[UIView commitAnimations]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
256 |
doNotDim(); |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
257 |
} |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
258 |
|
3976 | 259 |
-(void) cleanup { |
260 |
[self dismissPopover]; |
|
4082 | 261 |
setGameRunning(NO); |
3976 | 262 |
HW_terminate(NO); |
263 |
[self.view removeFromSuperview]; |
|
264 |
} |
|
265 |
||
3783 | 266 |
-(void) didReceiveMemoryWarning { |
267 |
if (self.popupMenu.view.superview == nil) |
|
268 |
self.popupMenu = nil; |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
269 |
if (self.helpPage.view.superview == nil) |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
270 |
self.helpPage = nil; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
271 |
if (self.amvc.view.superview == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
272 |
self.amvc = nil; |
3996 | 273 |
if (IS_IPAD()) |
3971 | 274 |
if (((UIPopoverController *)self.popoverController).contentViewController.view.superview == nil) |
275 |
self.popoverController = nil; |
|
276 |
||
3783 | 277 |
MSG_MEMCLEAN(); |
3971 | 278 |
[super didReceiveMemoryWarning]; |
3783 | 279 |
} |
280 |
||
3547 | 281 |
-(void) viewDidUnload { |
3783 | 282 |
// only objects initialized in viewDidLoad should be here |
4098
40df542b5f62
i give up and disable rotation on the iphone; also fix smaller compilation issues
koda
parents:
4082
diff
changeset
|
283 |
if (IS_DUALHEAD()) |
40df542b5f62
i give up and disable rotation on the iphone; also fix smaller compilation issues
koda
parents:
4082
diff
changeset
|
284 |
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications]; |
3783 | 285 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
3978 | 286 |
[NSObject cancelPreviousPerformRequestsWithTarget:self |
287 |
selector:@selector(unsetPreciseStatus) |
|
288 |
object:nil]; |
|
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
|
289 |
dimTimer = nil; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
290 |
self.helpPage = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
291 |
[self dismissPopover]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
292 |
self.popoverController = nil; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
293 |
self.amvc = nil; |
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
|
294 |
MSG_DIDUNLOAD(); |
3547 | 295 |
[super viewDidUnload]; |
296 |
} |
|
297 |
||
298 |
-(void) dealloc { |
|
299 |
[popupMenu release]; |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
300 |
[helpPage release]; |
3547 | 301 |
[popoverController release]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
302 |
[amvc release]; |
3547 | 303 |
// dimTimer is autoreleased |
304 |
[super dealloc]; |
|
305 |
} |
|
306 |
||
307 |
#pragma mark - |
|
3976 | 308 |
#pragma mark overlay user interaction |
3547 | 309 |
// nice transition for dimming, should be called only by the timer himself |
310 |
-(void) dimOverlay { |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
311 |
if (isGameRunning()) { |
3547 | 312 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
313 |
[UIView setAnimationDuration:0.6]; |
|
314 |
self.view.alpha = 0.2; |
|
315 |
[UIView commitAnimations]; |
|
316 |
} |
|
317 |
} |
|
318 |
||
319 |
// set the overlay visible and put off the timer for enough time |
|
320 |
-(void) activateOverlay { |
|
321 |
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
|
322 |
doNotDim(); |
3547 | 323 |
} |
324 |
||
3626 | 325 |
// dim the overlay when there's no more input for a certain amount of time |
326 |
-(IBAction) buttonReleased:(id) sender { |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
327 |
if (isGameRunning() == NO) |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
328 |
return; |
3697 | 329 |
|
3626 | 330 |
UIButton *theButton = (UIButton *)sender; |
3697 | 331 |
|
3626 | 332 |
switch (theButton.tag) { |
333 |
case 0: |
|
334 |
case 1: |
|
335 |
case 2: |
|
336 |
case 3: |
|
3649 | 337 |
[NSObject cancelPreviousPerformRequestsWithTarget:self |
338 |
selector:@selector(unsetPreciseStatus) |
|
339 |
object:nil]; |
|
3626 | 340 |
HW_walkingKeysUp(); |
341 |
break; |
|
342 |
case 4: |
|
343 |
case 5: |
|
344 |
case 6: |
|
345 |
HW_otherKeysUp(); |
|
346 |
break; |
|
347 |
default: |
|
3660 | 348 |
DLog(@"Nope"); |
3626 | 349 |
break; |
350 |
} |
|
351 |
||
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
352 |
isAttacking = NO; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
353 |
doDim(); |
3626 | 354 |
} |
355 |
||
3697 | 356 |
// issue certain action based on the tag of the button |
3547 | 357 |
-(IBAction) buttonPressed:(id) sender { |
358 |
[self activateOverlay]; |
|
3904
22e4d74240e5
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents:
3829
diff
changeset
|
359 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
360 |
if (isGameRunning() == NO) |
3904
22e4d74240e5
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents:
3829
diff
changeset
|
361 |
return; |
22e4d74240e5
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents:
3829
diff
changeset
|
362 |
|
22e4d74240e5
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents:
3829
diff
changeset
|
363 |
if (isPopoverVisible) |
3547 | 364 |
[self dismissPopover]; |
3779
3351a017d4ad
tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents:
3765
diff
changeset
|
365 |
|
3547 | 366 |
UIButton *theButton = (UIButton *)sender; |
367 |
switch (theButton.tag) { |
|
368 |
case 0: |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
369 |
if (isAttacking == NO) |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
370 |
HW_walkLeft(); |
3547 | 371 |
break; |
372 |
case 1: |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
373 |
if (isAttacking == NO) |
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
374 |
HW_walkRight(); |
3547 | 375 |
break; |
376 |
case 2: |
|
3649 | 377 |
[self performSelector:@selector(unsetPreciseStatus) withObject:nil afterDelay:0.8]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
378 |
HW_preciseSet(!HW_isWeaponRope()); |
3547 | 379 |
HW_aimUp(); |
380 |
break; |
|
381 |
case 3: |
|
3649 | 382 |
[self performSelector:@selector(unsetPreciseStatus) withObject:nil afterDelay:0.8]; |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
383 |
HW_preciseSet(!HW_isWeaponRope()); |
3547 | 384 |
HW_aimDown(); |
385 |
break; |
|
386 |
case 4: |
|
387 |
HW_shoot(); |
|
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
388 |
isAttacking = YES; |
3547 | 389 |
break; |
390 |
case 5: |
|
391 |
HW_jump(); |
|
392 |
break; |
|
393 |
case 6: |
|
394 |
HW_backjump(); |
|
395 |
break; |
|
396 |
case 10: |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
397 |
playSound(@"clickSound"); |
4504
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4454
diff
changeset
|
398 |
clearView(); |
3667 | 399 |
HW_pause(); |
3941 | 400 |
if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
401 |
doDim(); |
3935 | 402 |
[self.amvc disappear]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
403 |
} |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
404 |
removeConfirmationInput(); |
3547 | 405 |
[self showPopover]; |
406 |
break; |
|
3624 | 407 |
case 11: |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
408 |
playSound(@"clickSound"); |
4504
8906b2409d97
add the appirater class for getting more positive reviews
koda
parents:
4454
diff
changeset
|
409 |
clearView(); |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
410 |
removeConfirmationInput(); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
411 |
|
3941 | 412 |
if (IS_DUALHEAD() || self.useClassicMenu == NO) { |
3935 | 413 |
if (self.amvc == nil) |
414 |
self.amvc = [[AmmoMenuViewController alloc] init]; |
|
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
415 |
setAmmoMenuInstance(amvc); |
3935 | 416 |
if (self.amvc.isVisible) { |
417 |
doDim(); |
|
418 |
[self.amvc disappear]; |
|
419 |
} else { |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
420 |
if (HW_isAmmoMenuNotAllowed() == NO) { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
421 |
doNotDim(); |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
422 |
[self.amvc appearInView:self.view]; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
423 |
} |
3935 | 424 |
} |
3941 | 425 |
} else { |
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
426 |
setAmmoMenuInstance(nil); |
3941 | 427 |
HW_ammoMenu(); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
428 |
} |
3624 | 429 |
break; |
3547 | 430 |
default: |
3626 | 431 |
DLog(@"Nope"); |
3547 | 432 |
break; |
433 |
} |
|
434 |
} |
|
435 |
||
3649 | 436 |
-(void) unsetPreciseStatus { |
437 |
HW_preciseSet(NO); |
|
438 |
} |
|
439 |
||
3976 | 440 |
-(void) sendHWClick { |
441 |
HW_click(); |
|
442 |
removeConfirmationInput(); |
|
443 |
doDim(); |
|
444 |
} |
|
445 |
||
446 |
-(void) setGrenadeTime:(id) sender { |
|
447 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
448 |
if (cachedGrenadeTime() != theSegment.selectedSegmentIndex) { |
3976 | 449 |
HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); |
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
450 |
setGrenadeTime(theSegment.selectedSegmentIndex); |
3976 | 451 |
} |
452 |
} |
|
453 |
||
454 |
#pragma mark - |
|
455 |
#pragma mark other menu |
|
3547 | 456 |
// present a further check before closing game |
457 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
458 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
3924 | 459 |
[self cleanup]; |
3547 | 460 |
else |
3697 | 461 |
HW_pause(); |
3547 | 462 |
} |
463 |
||
464 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
465 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
|
466 |
-(IBAction) showPopover{ |
|
3667 | 467 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 468 |
isPopoverVisible = YES; |
469 |
||
3996 | 470 |
if (IS_IPAD()) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
471 |
if (self.popupMenu == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
472 |
self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
473 |
if (self.popoverController == nil) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
474 |
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.popupMenu]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
475 |
[self.popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
476 |
[self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
3547 | 477 |
} |
3551 | 478 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
479 |
[self.popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
3547 | 480 |
inView:self.view |
3667 | 481 |
permittedArrowDirections:UIPopoverArrowDirectionAny |
3547 | 482 |
animated:YES]; |
483 |
} else { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
484 |
if (self.popupMenu == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
485 |
self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3697 | 486 |
|
3547 | 487 |
[self.view addSubview:popupMenu.view]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
488 |
[self.popupMenu present]; |
3547 | 489 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
490 |
self.popupMenu.tableView.scrollEnabled = NO; |
3547 | 491 |
} |
492 |
||
493 |
// on ipad just dismiss it, on iphone transtion to the right |
|
494 |
-(void) dismissPopover { |
|
495 |
if (YES == isPopoverVisible) { |
|
496 |
isPopoverVisible = NO; |
|
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
497 |
if (HW_isPaused()) |
4454 | 498 |
HW_pauseToggle(); |
3697 | 499 |
|
3996 | 500 |
if (IS_IPAD()) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
501 |
[(InGameMenuViewController *)[[self popoverController] contentViewController] removeChat]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
502 |
[self.popoverController dismissPopoverAnimated:YES]; |
3547 | 503 |
} else { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
504 |
[self.popupMenu dismiss]; |
3547 | 505 |
} |
506 |
[self buttonReleased:nil]; |
|
507 |
} |
|
508 |
} |
|
509 |
||
510 |
#pragma mark - |
|
511 |
#pragma mark Custom touch event handling |
|
4541 | 512 |
-(BOOL) shouldIgnoreTouch:(NSSet *)allTouches { |
513 |
if (isGameRunning() == NO) |
|
514 |
return YES; |
|
515 |
||
516 |
// ignore activity near the dpad and buttons |
|
517 |
CGPoint touchPoint = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
|
518 |
CGSize screen = [[UIScreen mainScreen] bounds].size; |
|
519 |
||
520 |
if ((touchPoint.x < 160 && touchPoint.y > screen.width - 155 ) || |
|
521 |
(touchPoint.x > screen.height - 135 && touchPoint.y > screen.width - 140)) |
|
522 |
return YES; |
|
523 |
return NO; |
|
524 |
} |
|
525 |
||
3547 | 526 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
527 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
528 |
UITouch *first, *second; |
3697 | 529 |
|
4541 | 530 |
if ([self shouldIgnoreTouch:allTouches] == YES) |
3765
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3739
diff
changeset
|
531 |
return; |
ebfe7c9b3085
set flake to non critical, no touches until game is starding, moved some variables to be initialized in the right place
koda
parents:
3739
diff
changeset
|
532 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
533 |
// hide in-game menu |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
534 |
if (isPopoverVisible) |
3547 | 535 |
[self dismissPopover]; |
3697 | 536 |
|
3941 | 537 |
if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
538 |
doDim(); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
539 |
[self.amvc disappear]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
540 |
} |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
541 |
// reset default dimming |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
542 |
doDim(); |
3697 | 543 |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
544 |
HW_setPianoSound([allTouches count]); |
3697 | 545 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
546 |
switch ([allTouches count]) { |
3697 | 547 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
548 |
removeConfirmationInput(); |
3651 | 549 |
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
|
550 |
if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
551 |
HW_zoomReset(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
552 |
break; |
3697 | 553 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
554 |
// pinching |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
555 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
556 |
second = [[allTouches allObjects] objectAtIndex:1]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
557 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
558 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
559 |
default: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
560 |
break; |
3547 | 561 |
} |
562 |
} |
|
563 |
||
564 |
-(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
|
565 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
566 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
567 |
CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3697 | 568 |
|
4541 | 569 |
if ([self shouldIgnoreTouch:allTouches] == YES) |
3904
22e4d74240e5
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents:
3829
diff
changeset
|
570 |
return; |
4541 | 571 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
572 |
switch ([allTouches count]) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
573 |
case 1: |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
574 |
// if we're in the menu we just click in the point |
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
575 |
if (HW_isAmmoMenuOpen()) { |
3680 | 576 |
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
|
577 |
// 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
|
578 |
HW_click(); |
3697 | 579 |
} else |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
580 |
// 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
|
581 |
if (HW_isWeaponRequiringClick()) { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
582 |
// 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
|
583 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3697 | 584 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
585 |
// 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
|
586 |
UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
587 |
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
|
588 |
tapAgain.tag = CONFIRMATION_TAG; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
589 |
tapAgain.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
590 |
[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
|
591 |
[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
|
592 |
[self.view addSubview:tapAgain]; |
3697 | 593 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
594 |
// animation ftw! |
3697 | 595 |
[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
|
596 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
597 |
[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
|
598 |
[UIView commitAnimations]; |
3697 | 599 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
600 |
// keep the overlay active, or the button will fade |
3650 | 601 |
[self activateOverlay]; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
602 |
doNotDim(); |
3650 | 603 |
} else |
604 |
if (HW_isWeaponTimerable()) { |
|
605 |
if (isSegmentVisible) { |
|
606 |
UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG]; |
|
3697 | 607 |
|
3650 | 608 |
[UIView beginAnimations:@"removing segmented control" context:NULL]; |
609 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
610 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
611 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
612 |
[UIView commitAnimations]; |
|
3697 | 613 |
|
3650 | 614 |
[grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION]; |
615 |
} else { |
|
616 |
NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; |
|
617 |
UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items]; |
|
618 |
[items release]; |
|
3697 | 619 |
|
3650 | 620 |
[grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged]; |
621 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
622 |
grenadeTime.selectedSegmentIndex = cachedGrenadeTime(); |
3650 | 623 |
grenadeTime.tag = GRENADE_TAG; |
624 |
[self.view addSubview:grenadeTime]; |
|
625 |
[grenadeTime release]; |
|
3697 | 626 |
|
3650 | 627 |
[UIView beginAnimations:@"inserting segmented control" context:NULL]; |
628 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
629 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
630 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50); |
|
631 |
[UIView commitAnimations]; |
|
3697 | 632 |
|
3650 | 633 |
[self activateOverlay]; |
634 |
doNotDim(); |
|
3697 | 635 |
} |
3650 | 636 |
isSegmentVisible = !isSegmentVisible; |
3661 | 637 |
} else |
638 |
if (HW_isWeaponSwitch()) |
|
639 |
HW_tab(); |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
640 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
641 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
642 |
HW_allKeysUp(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
643 |
break; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
644 |
default: |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
645 |
break; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
646 |
} |
3697 | 647 |
|
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
|
648 |
initialDistanceForPinching = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
649 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
650 |
|
3547 | 651 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
652 |
[self touchesEnded:touches withEvent:event]; |
|
653 |
} |
|
654 |
||
655 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3551 | 656 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
657 |
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
|
658 |
int x, y, dx, dy; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
659 |
UITouch *touch, *first, *second; |
3547 | 660 |
|
4541 | 661 |
if ([self shouldIgnoreTouch:allTouches] == YES) |
3904
22e4d74240e5
finishing touches to save games handling (help label, dim on overlay, edit text only when table is editable)
koda
parents:
3829
diff
changeset
|
662 |
return; |
4541 | 663 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
664 |
switch ([allTouches count]) { |
3551 | 665 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
666 |
touch = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
667 |
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
|
668 |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
669 |
if (HW_isAmmoMenuOpen()) { |
3680 | 670 |
// no zoom consideration for this |
671 |
HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); |
|
672 |
} else |
|
673 |
if (HW_isWeaponRequiringClick()) { |
|
674 |
// moves the cursor around wrt zoom |
|
675 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
|
676 |
} else { |
|
677 |
// panning \o/ |
|
678 |
dx = startingPoint.x - currentPosition.x; |
|
679 |
dy = currentPosition.y - startingPoint.y; |
|
680 |
HW_getCursor(&x, &y); |
|
681 |
// momentum (or something like that) |
|
682 |
/*if (abs(dx) > 40) |
|
683 |
dx *= log(abs(dx)/4); |
|
684 |
if (abs(dy) > 40) |
|
685 |
dy *= log(abs(dy)/4);*/ |
|
686 |
HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor()); |
|
687 |
startingPoint = currentPosition; |
|
688 |
} |
|
3551 | 689 |
break; |
3547 | 690 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
691 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
692 |
second = [[allTouches allObjects] objectAtIndex:1]; |
3547 | 693 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
694 |
const int pinchDelta = 40; |
|
3697 | 695 |
|
3547 | 696 |
if (0 != initialDistanceForPinching) { |
697 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
698 |
HW_zoomIn(); |
|
699 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
700 |
} |
|
701 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
702 |
HW_zoomOut(); |
|
703 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
704 |
} |
|
3697 | 705 |
} else |
3547 | 706 |
initialDistanceForPinching = currentDistanceOfPinching; |
707 |
break; |
|
708 |
default: |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
709 |
DLog(@"Nope"); |
3547 | 710 |
break; |
711 |
} |
|
712 |
} |
|
713 |
||
714 |
@end |