author | nemo |
Tue, 07 Dec 2010 17:29:02 -0500 | |
changeset 4479 | 59e11a5a3bfa |
parent 4454 | 42bfc1a70968 |
child 4504 | 8906b2409d97 |
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"); |
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]; |
|
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
413 |
setAmmoMenuInstance(amvc); |
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 { |
4362
8dae325dc625
added missing graphics and fixed some glitches/crashes/bugs
koda
parents:
4356
diff
changeset
|
424 |
setAmmoMenuInstance(nil); |
3941 | 425 |
HW_ammoMenu(); |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
426 |
} |
3624 | 427 |
break; |
3547 | 428 |
default: |
3626 | 429 |
DLog(@"Nope"); |
3547 | 430 |
break; |
431 |
} |
|
432 |
} |
|
433 |
||
3649 | 434 |
-(void) unsetPreciseStatus { |
435 |
HW_preciseSet(NO); |
|
436 |
} |
|
437 |
||
3976 | 438 |
-(void) sendHWClick { |
439 |
HW_click(); |
|
440 |
removeConfirmationInput(); |
|
441 |
doDim(); |
|
442 |
} |
|
443 |
||
444 |
-(void) setGrenadeTime:(id) sender { |
|
445 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
446 |
if (cachedGrenadeTime() != theSegment.selectedSegmentIndex) { |
3976 | 447 |
HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); |
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
448 |
setGrenadeTime(theSegment.selectedSegmentIndex); |
3976 | 449 |
} |
450 |
} |
|
451 |
||
452 |
#pragma mark - |
|
453 |
#pragma mark other menu |
|
3547 | 454 |
// present a further check before closing game |
455 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
456 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
3924 | 457 |
[self cleanup]; |
3547 | 458 |
else |
3697 | 459 |
HW_pause(); |
3547 | 460 |
} |
461 |
||
462 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
463 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
|
464 |
-(IBAction) showPopover{ |
|
3667 | 465 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 466 |
isPopoverVisible = YES; |
467 |
||
3996 | 468 |
if (IS_IPAD()) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
469 |
if (self.popupMenu == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
470 |
self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
471 |
if (self.popoverController == nil) { |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
472 |
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:self.popupMenu]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
473 |
[self.popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
474 |
[self.popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
3547 | 475 |
} |
3551 | 476 |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
477 |
[self.popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
3547 | 478 |
inView:self.view |
3667 | 479 |
permittedArrowDirections:UIPopoverArrowDirectionAny |
3547 | 480 |
animated:YES]; |
481 |
} else { |
|
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
482 |
if (self.popupMenu == nil) |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
483 |
self.popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3697 | 484 |
|
3547 | 485 |
[self.view addSubview:popupMenu.view]; |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
486 |
[self.popupMenu present]; |
3547 | 487 |
} |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
488 |
self.popupMenu.tableView.scrollEnabled = NO; |
3547 | 489 |
} |
490 |
||
491 |
// on ipad just dismiss it, on iphone transtion to the right |
|
492 |
-(void) dismissPopover { |
|
493 |
if (YES == isPopoverVisible) { |
|
494 |
isPopoverVisible = NO; |
|
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
495 |
if (HW_isPaused()) |
4454 | 496 |
HW_pauseToggle(); |
3697 | 497 |
|
3996 | 498 |
if (IS_IPAD()) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
499 |
[(InGameMenuViewController *)[[self popoverController] contentViewController] removeChat]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
500 |
[self.popoverController dismissPopoverAnimated:YES]; |
3547 | 501 |
} else { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
502 |
[self.popupMenu dismiss]; |
3547 | 503 |
} |
504 |
[self buttonReleased:nil]; |
|
505 |
} |
|
506 |
} |
|
507 |
||
508 |
#pragma mark - |
|
509 |
#pragma mark Custom touch event handling |
|
510 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
511 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
512 |
UITouch *first, *second; |
3697 | 513 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
514 |
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
|
515 |
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
|
516 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
517 |
// hide in-game menu |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
518 |
if (isPopoverVisible) |
3547 | 519 |
[self dismissPopover]; |
3697 | 520 |
|
3941 | 521 |
if (self.amvc.isVisible && IS_DUALHEAD() == NO) { |
3933
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
522 |
doDim(); |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
523 |
[self.amvc disappear]; |
1a873262f5dd
polishing the cocoa ammomenu a little, still requires work
koda
parents:
3926
diff
changeset
|
524 |
} |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
525 |
// reset default dimming |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
526 |
doDim(); |
3697 | 527 |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
528 |
HW_setPianoSound([allTouches count]); |
3697 | 529 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
530 |
switch ([allTouches count]) { |
3697 | 531 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
532 |
removeConfirmationInput(); |
3651 | 533 |
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
|
534 |
if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
535 |
HW_zoomReset(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
536 |
break; |
3697 | 537 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
538 |
// pinching |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
539 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
540 |
second = [[allTouches allObjects] objectAtIndex:1]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
541 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
542 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
543 |
default: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
544 |
break; |
3547 | 545 |
} |
546 |
} |
|
547 |
||
548 |
-(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
|
549 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
550 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
551 |
CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3697 | 552 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
553 |
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
|
554 |
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
|
555 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
556 |
switch ([allTouches count]) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
557 |
case 1: |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
558 |
// 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
|
559 |
if (HW_isAmmoMenuOpen()) { |
3680 | 560 |
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
|
561 |
// 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
|
562 |
HW_click(); |
3697 | 563 |
} else |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
564 |
// 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
|
565 |
if (HW_isWeaponRequiringClick()) { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
566 |
// 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
|
567 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3697 | 568 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
569 |
// 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
|
570 |
UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
571 |
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
|
572 |
tapAgain.tag = CONFIRMATION_TAG; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
573 |
tapAgain.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
574 |
[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
|
575 |
[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
|
576 |
[self.view addSubview:tapAgain]; |
3697 | 577 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
578 |
// animation ftw! |
3697 | 579 |
[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
|
580 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
581 |
[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
|
582 |
[UIView commitAnimations]; |
3697 | 583 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
584 |
// keep the overlay active, or the button will fade |
3650 | 585 |
[self activateOverlay]; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
586 |
doNotDim(); |
3650 | 587 |
} else |
588 |
if (HW_isWeaponTimerable()) { |
|
589 |
if (isSegmentVisible) { |
|
590 |
UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG]; |
|
3697 | 591 |
|
3650 | 592 |
[UIView beginAnimations:@"removing segmented control" context:NULL]; |
593 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
594 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
595 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
596 |
[UIView commitAnimations]; |
|
3697 | 597 |
|
3650 | 598 |
[grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION]; |
599 |
} else { |
|
600 |
NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; |
|
601 |
UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items]; |
|
602 |
[items release]; |
|
3697 | 603 |
|
3650 | 604 |
[grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged]; |
605 |
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
|
606 |
grenadeTime.selectedSegmentIndex = cachedGrenadeTime(); |
3650 | 607 |
grenadeTime.tag = GRENADE_TAG; |
608 |
[self.view addSubview:grenadeTime]; |
|
609 |
[grenadeTime release]; |
|
3697 | 610 |
|
3650 | 611 |
[UIView beginAnimations:@"inserting segmented control" context:NULL]; |
612 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
613 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
614 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50); |
|
615 |
[UIView commitAnimations]; |
|
3697 | 616 |
|
3650 | 617 |
[self activateOverlay]; |
618 |
doNotDim(); |
|
3697 | 619 |
} |
3650 | 620 |
isSegmentVisible = !isSegmentVisible; |
3661 | 621 |
} else |
622 |
if (HW_isWeaponSwitch()) |
|
623 |
HW_tab(); |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
624 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
625 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
626 |
HW_allKeysUp(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
627 |
break; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
628 |
default: |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
629 |
break; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
630 |
} |
3697 | 631 |
|
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
|
632 |
initialDistanceForPinching = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
633 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
634 |
|
3547 | 635 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
636 |
[self touchesEnded:touches withEvent:event]; |
|
637 |
} |
|
638 |
||
639 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3551 | 640 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
641 |
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
|
642 |
int x, y, dx, dy; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
643 |
UITouch *touch, *first, *second; |
3547 | 644 |
|
4028
eb371ada631d
move functions called by pascal code outside controller
koda
parents:
3996
diff
changeset
|
645 |
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
|
646 |
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
|
647 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
648 |
switch ([allTouches count]) { |
3551 | 649 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
650 |
touch = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
651 |
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
|
652 |
|
3952
d6412423da45
moved some utilities to a separate column with round buttons
koda
parents:
3948
diff
changeset
|
653 |
if (HW_isAmmoMenuOpen()) { |
3680 | 654 |
// no zoom consideration for this |
655 |
HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); |
|
656 |
} else |
|
657 |
if (HW_isWeaponRequiringClick()) { |
|
658 |
// moves the cursor around wrt zoom |
|
659 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
|
660 |
} else { |
|
661 |
// panning \o/ |
|
662 |
dx = startingPoint.x - currentPosition.x; |
|
663 |
dy = currentPosition.y - startingPoint.y; |
|
664 |
HW_getCursor(&x, &y); |
|
665 |
// momentum (or something like that) |
|
666 |
/*if (abs(dx) > 40) |
|
667 |
dx *= log(abs(dx)/4); |
|
668 |
if (abs(dy) > 40) |
|
669 |
dy *= log(abs(dy)/4);*/ |
|
670 |
HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor()); |
|
671 |
startingPoint = currentPosition; |
|
672 |
} |
|
3551 | 673 |
break; |
3547 | 674 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
675 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
676 |
second = [[allTouches allObjects] objectAtIndex:1]; |
3547 | 677 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
678 |
const int pinchDelta = 40; |
|
3697 | 679 |
|
3547 | 680 |
if (0 != initialDistanceForPinching) { |
681 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
682 |
HW_zoomIn(); |
|
683 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
684 |
} |
|
685 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
686 |
HW_zoomOut(); |
|
687 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
688 |
} |
|
3697 | 689 |
} else |
3547 | 690 |
initialDistanceForPinching = currentDistanceOfPinching; |
691 |
break; |
|
692 |
default: |
|
3940
cc29628976cc
some optimizations to drawing and fetching data of new ammomenu
koda
parents:
3935
diff
changeset
|
693 |
DLog(@"Nope"); |
3547 | 694 |
break; |
695 |
} |
|
696 |
} |
|
697 |
||
698 |
@end |