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