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