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