author | koda |
Thu, 25 Nov 2010 02:45:52 +0100 | |
changeset 4356 | d1d26f8963a3 |
parent 4144 | cda2685feeb4 |
child 4362 | 8dae325dc625 |
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 |
|
4356 | 41 |
@synthesize popoverController, popupMenu, helpPage, amvc, isNetGame, useClassicMenu, initialOrientation; |
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 |
||
3976 | 57 |
[self dismissPopover]; |
58 |
if (HW_isPaused() == NO) |
|
59 |
HW_pause(); |
|
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]; |
|
89 |
if (HW_isPaused() == YES) |
|
90 |
HW_pause(); |
|
91 |
||
92 |
[super didRotateFromInterfaceOrientation:fromInterfaceOrientation]; |
|
93 |
} |
|
94 |
||
4078 | 95 |
// while in dual head the above rotation functions are not called |
96 |
-(void) dualHeadRotation:(NSNotification *)notification { |
|
4356 | 97 |
if (isGameRunning() == NO) |
98 |
return; |
|
99 |
||
3547 | 100 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
3977 | 101 |
|
3547 | 102 |
[UIView beginAnimations:@"rotation" context:NULL]; |
3976 | 103 |
[UIView setAnimationDuration:0.7]; |
3547 | 104 |
switch (orientation) { |
105 |
case UIDeviceOrientationLandscapeLeft: |
|
4078 | 106 |
self.view.frame = [[UIScreen mainScreen] bounds]; |
107 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
3547 | 108 |
break; |
109 |
case UIDeviceOrientationLandscapeRight: |
|
4078 | 110 |
self.view.frame = [[UIScreen mainScreen] bounds]; |
111 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
112 |
break; |
3547 | 113 |
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
|
114 |
// a debug log would spam too much |
3547 | 115 |
break; |
116 |
} |
|
117 |
[UIView commitAnimations]; |
|
118 |
} |
|
119 |
||
120 |
#pragma mark - |
|
121 |
#pragma mark View Management |
|
3976 | 122 |
-(id) initWithCoder:(NSCoder *)aDecoder { |
123 |
if ((self = [super initWithCoder:aDecoder])) { |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
124 |
objcExportsInit(); |
3976 | 125 |
isAttacking = NO; |
126 |
wasVisible = NO; |
|
127 |
isPopoverVisible = NO; // it is called "popover" even on the iphone |
|
128 |
} |
|
129 |
return self; |
|
130 |
} |
|
3948
24daa33a3114
some rethinking of initial menu presentation and initial orientation (also merging images should be threadsafe now)
koda
parents:
3941
diff
changeset
|
131 |
|
3976 | 132 |
-(void) viewDidLoad { |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
133 |
CGRect screenRect = [[UIScreen mainScreen] bounds]; |
3977 | 134 |
self.view.frame = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width); |
3976 | 135 |
self.view.center = CGPointMake(self.view.frame.size.height/2, self.view.frame.size.width/2); |
3978 | 136 |
self.view.alpha = 0; |
3697 | 137 |
|
3976 | 138 |
// detrmine the quanitiy and direction of the rotation |
139 |
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { |
|
140 |
a = 180; |
|
141 |
b = 0; |
|
142 |
} else { |
|
143 |
a = 0; |
|
144 |
b = 180; |
|
145 |
} |
|
146 |
||
3977 | 147 |
// get the number of screens to know the previous state whan a display is connected or detached |
4082 | 148 |
if ([UIScreen respondsToSelector:@selector(screens)]) |
149 |
initialScreenCount = [[UIScreen screens] count]; |
|
150 |
else |
|
151 |
initialScreenCount = 1; |
|
3977 | 152 |
|
153 |
// set initial orientation of the controller orientation |
|
154 |
if (IS_DUALHEAD()) { |
|
155 |
switch (self.interfaceOrientation) { |
|
156 |
case UIDeviceOrientationLandscapeLeft: |
|
157 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
158 |
break; |
|
159 |
case UIDeviceOrientationLandscapeRight: |
|
160 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
161 |
break; |
|
162 |
default: |
|
163 |
DLog(@"Nope"); |
|
164 |
break; |
|
165 |
} |
|
4078 | 166 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
167 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
168 |
selector:@selector(dualHeadRotation:) |
|
169 |
name:UIDeviceOrientationDidChangeNotification |
|
170 |
object:nil]; |
|
3977 | 171 |
} |
172 |
||
3976 | 173 |
// the timer used to dim the overlay |
3941 | 174 |
dimTimer = [[NSTimer alloc] initWithFireDate:(IS_DUALHEAD()) ? HIDING_TIME_NEVER : [NSDate dateWithTimeIntervalSinceNow:6] |
3547 | 175 |
interval:1000 |
176 |
target:self |
|
177 |
selector:@selector(dimOverlay) |
|
178 |
userInfo:nil |
|
179 |
repeats:YES]; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
180 |
// add timer to runloop, otherwise it doesn't work |
3547 | 181 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
3697 | 182 |
|
3976 | 183 |
// become listener of some notifications |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
184 |
[[NSNotificationCenter defaultCenter] addObserver:self |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
185 |
selector:@selector(showHelp:) |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
186 |
name:@"show help ingame" |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
187 |
object:nil]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
188 |
|
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
189 |
[[NSNotificationCenter defaultCenter] addObserver:self |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
190 |
selector:@selector(cleanup) |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
191 |
name:@"remove overlay" |
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3906
diff
changeset
|
192 |
object:nil]; |
4082 | 193 |
|
4098
40df542b5f62
i give up and disable rotation on the iphone; also fix smaller compilation issues
koda
parents:
4082
diff
changeset
|
194 |
// for iOS >= 3.2 |
4082 | 195 |
if ([UIScreen respondsToSelector:@selector(screens)]) { |
196 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
197 |
selector:@selector(numberOfScreensIncreased) |
|
198 |
name:UIScreenDidConnectNotification |
|
199 |
object:nil]; |
|
200 |
||
201 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
202 |
selector:@selector(numberOfScreensDecreased) |
|
203 |
name:UIScreenDidDisconnectNotification |
|
204 |
object:nil]; |
|
205 |
} |
|
3976 | 206 |
|
207 |
// present the overlay |
|
3547 | 208 |
[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
|
209 |
[UIView setAnimationDuration:2]; |
3547 | 210 |
self.view.alpha = 1; |
211 |
[UIView commitAnimations]; |
|
212 |
} |
|
213 |
||
3941 | 214 |
-(void) numberOfScreensIncreased { |
215 |
if (initialScreenCount == 1) { |
|
216 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New display detected" |
|
217 |
message:NSLocalizedString(@"Hedgewars supports multi-monitor configurations, but the screen has to be connected before launching the game.",@"") |
|
218 |
delegate:nil |
|
219 |
cancelButtonTitle:@"Ok" |
|
220 |
otherButtonTitles:nil]; |
|
221 |
[alert show]; |
|
222 |
[alert release]; |
|
223 |
if (HW_isPaused() == NO) |
|
224 |
HW_pause(); |
|
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"); |
3667 | 398 |
HW_pause(); |
3941 | 399 |
if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
400 |
doDim(); |
3935 | 401 |
[self.amvc disappear]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
402 |
} |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
403 |
removeConfirmationInput(); |
3547 | 404 |
[self showPopover]; |
405 |
break; |
|
3624 | 406 |
case 11: |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
407 |
playSound(@"clickSound"); |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
408 |
removeConfirmationInput(); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
409 |
|
3941 | 410 |
if (IS_DUALHEAD() || self.useClassicMenu == NO) { |
3935 | 411 |
if (self.amvc == nil) |
412 |
self.amvc = [[AmmoMenuViewController alloc] init]; |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
413 |
|
3935 | 414 |
if (self.amvc.isVisible) { |
415 |
doDim(); |
|
416 |
[self.amvc disappear]; |
|
417 |
} else { |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
418 |
if (HW_isAmmoMenuNotAllowed() == NO) { |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
419 |
doNotDim(); |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
420 |
[self.amvc appearInView:self.view]; |
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
421 |
} |
3935 | 422 |
} |
3941 | 423 |
} else { |
424 |
HW_ammoMenu(); |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
425 |
} |
3624 | 426 |
break; |
3547 | 427 |
default: |
3626 | 428 |
DLog(@"Nope"); |
3547 | 429 |
break; |
430 |
} |
|
431 |
} |
|
432 |
||
3649 | 433 |
-(void) unsetPreciseStatus { |
434 |
HW_preciseSet(NO); |
|
435 |
} |
|
436 |
||
3976 | 437 |
-(void) sendHWClick { |
438 |
HW_click(); |
|
439 |
removeConfirmationInput(); |
|
440 |
doDim(); |
|
441 |
} |
|
442 |
||
443 |
-(void) setGrenadeTime:(id) sender { |
|
444 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
445 |
if (cachedGrenadeTime() != theSegment.selectedSegmentIndex) { |
3976 | 446 |
HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); |
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
447 |
setGrenadeTime(theSegment.selectedSegmentIndex); |
3976 | 448 |
} |
449 |
} |
|
450 |
||
451 |
#pragma mark - |
|
452 |
#pragma mark other menu |
|
3547 | 453 |
// present a further check before closing game |
454 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
455 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
3924 | 456 |
[self cleanup]; |
3547 | 457 |
else |
3697 | 458 |
HW_pause(); |
3547 | 459 |
} |
460 |
||
461 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
462 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
|
463 |
-(IBAction) showPopover{ |
|
3667 | 464 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 465 |
isPopoverVisible = YES; |
466 |
||
3996 | 467 |
if (IS_IPAD()) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
468 |
if (self.popupMenu == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
469 |
self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
470 |
if (self.popoverController == nil) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
471 |
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.popupMenu]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
472 |
[self.popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
473 |
[self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
3547 | 474 |
} |
3551 | 475 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
476 |
[self.popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
3547 | 477 |
inView:self.view |
3667 | 478 |
permittedArrowDirections:UIPopoverArrowDirectionAny |
3547 | 479 |
animated:YES]; |
480 |
} else { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
481 |
if (self.popupMenu == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
482 |
self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3697 | 483 |
|
3547 | 484 |
[self.view addSubview:popupMenu.view]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
485 |
[self.popupMenu present]; |
3547 | 486 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
487 |
self.popupMenu.tableView.scrollEnabled = NO; |
3547 | 488 |
} |
489 |
||
490 |
// on ipad just dismiss it, on iphone transtion to the right |
|
491 |
-(void) dismissPopover { |
|
492 |
if (YES == isPopoverVisible) { |
|
493 |
isPopoverVisible = NO; |
|
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
494 |
if (HW_isPaused()) |
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
495 |
HW_pause(); |
3697 | 496 |
|
3996 | 497 |
if (IS_IPAD()) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
498 |
[(InGameMenuViewController *)[[self popoverController] contentViewController] removeChat]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
499 |
[self.popoverController dismissPopoverAnimated:YES]; |
3547 | 500 |
} else { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
501 |
[self.popupMenu dismiss]; |
3547 | 502 |
} |
503 |
[self buttonReleased:nil]; |
|
504 |
} |
|
505 |
} |
|
506 |
||
507 |
#pragma mark - |
|
508 |
#pragma mark Custom touch event handling |
|
509 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
510 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
511 |
UITouch *first, *second; |
3697 | 512 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
513 |
if (isGameRunning() == NO) |
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
|
514 |
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
|
515 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
516 |
// hide in-game menu |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
517 |
if (isPopoverVisible) |
3547 | 518 |
[self dismissPopover]; |
3697 | 519 |
|
3941 | 520 |
if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
521 |
doDim(); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
522 |
[self.amvc disappear]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
523 |
} |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
524 |
// reset default dimming |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
525 |
doDim(); |
3697 | 526 |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
527 |
HW_setPianoSound([allTouches count]); |
3697 | 528 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
529 |
switch ([allTouches count]) { |
3697 | 530 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
531 |
removeConfirmationInput(); |
3651 | 532 |
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
|
533 |
if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
534 |
HW_zoomReset(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
535 |
break; |
3697 | 536 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
537 |
// pinching |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
538 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
539 |
second = [[allTouches allObjects] objectAtIndex:1]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
540 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
541 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
542 |
default: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
543 |
break; |
3547 | 544 |
} |
545 |
} |
|
546 |
||
547 |
-(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
|
548 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
549 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
550 |
CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3697 | 551 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
552 |
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
|
553 |
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
|
554 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
555 |
switch ([allTouches count]) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
556 |
case 1: |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
557 |
// 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
|
558 |
if (HW_isAmmoMenuOpen()) { |
3680 | 559 |
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
|
560 |
// 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
|
561 |
HW_click(); |
3697 | 562 |
} else |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
563 |
// 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
|
564 |
if (HW_isWeaponRequiringClick()) { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
565 |
// 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
|
566 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3697 | 567 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
568 |
// 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
|
569 |
UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
570 |
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
|
571 |
tapAgain.tag = CONFIRMATION_TAG; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
572 |
tapAgain.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
573 |
[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
|
574 |
[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
|
575 |
[self.view addSubview:tapAgain]; |
3697 | 576 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
577 |
// animation ftw! |
3697 | 578 |
[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
|
579 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
580 |
[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
|
581 |
[UIView commitAnimations]; |
3697 | 582 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
583 |
// keep the overlay active, or the button will fade |
3650 | 584 |
[self activateOverlay]; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
585 |
doNotDim(); |
3650 | 586 |
} else |
587 |
if (HW_isWeaponTimerable()) { |
|
588 |
if (isSegmentVisible) { |
|
589 |
UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG]; |
|
3697 | 590 |
|
3650 | 591 |
[UIView beginAnimations:@"removing segmented control" context:NULL]; |
592 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
593 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
594 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
595 |
[UIView commitAnimations]; |
|
3697 | 596 |
|
3650 | 597 |
[grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION]; |
598 |
} else { |
|
599 |
NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; |
|
600 |
UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items]; |
|
601 |
[items release]; |
|
3697 | 602 |
|
3650 | 603 |
[grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged]; |
604 |
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
|
605 |
grenadeTime.selectedSegmentIndex = cachedGrenadeTime(); |
3650 | 606 |
grenadeTime.tag = GRENADE_TAG; |
607 |
[self.view addSubview:grenadeTime]; |
|
608 |
[grenadeTime release]; |
|
3697 | 609 |
|
3650 | 610 |
[UIView beginAnimations:@"inserting segmented control" context:NULL]; |
611 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
612 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
613 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50); |
|
614 |
[UIView commitAnimations]; |
|
3697 | 615 |
|
3650 | 616 |
[self activateOverlay]; |
617 |
doNotDim(); |
|
3697 | 618 |
} |
3650 | 619 |
isSegmentVisible = !isSegmentVisible; |
3661 | 620 |
} else |
621 |
if (HW_isWeaponSwitch()) |
|
622 |
HW_tab(); |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
623 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
624 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
625 |
HW_allKeysUp(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
626 |
break; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
627 |
default: |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
628 |
break; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
629 |
} |
3697 | 630 |
|
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
|
631 |
initialDistanceForPinching = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
632 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
633 |
|
3547 | 634 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
635 |
[self touchesEnded:touches withEvent:event]; |
|
636 |
} |
|
637 |
||
638 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3551 | 639 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
640 |
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
|
641 |
int x, y, dx, dy; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
642 |
UITouch *touch, *first, *second; |
3547 | 643 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
644 |
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
|
645 |
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
|
646 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
647 |
switch ([allTouches count]) { |
3551 | 648 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
649 |
touch = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
650 |
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
|
651 |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
652 |
if (HW_isAmmoMenuOpen()) { |
3680 | 653 |
// no zoom consideration for this |
654 |
HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); |
|
655 |
} else |
|
656 |
if (HW_isWeaponRequiringClick()) { |
|
657 |
// moves the cursor around wrt zoom |
|
658 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
|
659 |
} else { |
|
660 |
// panning \o/ |
|
661 |
dx = startingPoint.x - currentPosition.x; |
|
662 |
dy = currentPosition.y - startingPoint.y; |
|
663 |
HW_getCursor(&x, &y); |
|
664 |
// momentum (or something like that) |
|
665 |
/*if (abs(dx) > 40) |
|
666 |
dx *= log(abs(dx)/4); |
|
667 |
if (abs(dy) > 40) |
|
668 |
dy *= log(abs(dy)/4);*/ |
|
669 |
HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor()); |
|
670 |
startingPoint = currentPosition; |
|
671 |
} |
|
3551 | 672 |
break; |
3547 | 673 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
674 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
675 |
second = [[allTouches allObjects] objectAtIndex:1]; |
3547 | 676 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
677 |
const int pinchDelta = 40; |
|
3697 | 678 |
|
3547 | 679 |
if (0 != initialDistanceForPinching) { |
680 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
681 |
HW_zoomIn(); |
|
682 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
683 |
} |
|
684 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
685 |
HW_zoomOut(); |
|
686 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
687 |
} |
|
3697 | 688 |
} else |
3547 | 689 |
initialDistanceForPinching = currentDistanceOfPinching; |
690 |
break; |
|
691 |
default: |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
692 |
DLog(@"Nope"); |
3547 | 693 |
break; |
694 |
} |
|
695 |
} |
|
696 |
||
697 |
@end |