author | koda |
Sun, 19 Sep 2010 02:25:31 +0200 | |
changeset 3880 | 24810907e853 |
parent 3829 | 81db3c85784b |
child 3904 | 22e4d74240e5 |
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" |
|
23 |
#import "SDL_uikitappdelegate.h" |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
24 |
#import "InGameMenuViewController.h" |
3792 | 25 |
#import "HelpPageViewController.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" |
31 |
||
32 |
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
|
33 |
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
34 |
#define doDim() [dimTimer setFireDate:HIDING_TIME_DEFAULT] |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
35 |
#define doNotDim() [dimTimer setFireDate:HIDING_TIME_NEVER] |
3547 | 36 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
37 |
#define CONFIRMATION_TAG 5959 |
3650 | 38 |
#define GRENADE_TAG 9595 |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
39 |
#define ANIMATION_DURATION 0.25 |
3697 | 40 |
#define removeConfirmationInput() [[self.view viewWithTag:CONFIRMATION_TAG] removeFromSuperview]; |
3547 | 41 |
|
42 |
@implementation OverlayViewController |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
43 |
@synthesize popoverController, popupMenu, helpPage; |
3547 | 44 |
|
45 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
46 |
return rotationManager(interfaceOrientation); |
|
47 |
} |
|
48 |
||
3697 | 49 |
-(void) didRotate:(NSNotification *)notification { |
3547 | 50 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
51 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
|
52 |
CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); |
|
3648 | 53 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
3697 | 54 |
|
3547 | 55 |
[UIView beginAnimations:@"rotation" context:NULL]; |
56 |
[UIView setAnimationDuration:0.8f]; |
|
57 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
|
58 |
switch (orientation) { |
|
59 |
case UIDeviceOrientationLandscapeLeft: |
|
3680 | 60 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
61 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
3547 | 62 |
HW_setLandscape(YES); |
63 |
break; |
|
64 |
case UIDeviceOrientationLandscapeRight: |
|
3680 | 65 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
66 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
3547 | 67 |
HW_setLandscape(YES); |
68 |
break; |
|
3551 | 69 |
/* |
3547 | 70 |
case UIDeviceOrientationPortrait: |
71 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
72 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
|
73 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
|
74 |
[self chatAppear]; |
|
75 |
HW_setLandscape(NO); |
|
76 |
} |
|
77 |
break; |
|
78 |
case UIDeviceOrientationPortraitUpsideDown: |
|
79 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
80 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
|
81 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
|
82 |
[self chatAppear]; |
|
83 |
HW_setLandscape(NO); |
|
84 |
} |
|
85 |
break; |
|
3551 | 86 |
*/ |
3547 | 87 |
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
|
88 |
// a debug log would spam too much |
3547 | 89 |
break; |
90 |
} |
|
91 |
self.view.frame = usefulRect; |
|
92 |
//sdlView.frame = usefulRect; |
|
93 |
[UIView commitAnimations]; |
|
94 |
} |
|
95 |
||
96 |
#pragma mark - |
|
97 |
#pragma mark View Management |
|
98 |
-(void) viewDidLoad { |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
99 |
isGameRunning = NO; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
100 |
cachedGrenadeTime = 2; |
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
|
101 |
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
|
102 |
|
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
|
103 |
// i called it a popover even on the iphone |
3547 | 104 |
isPopoverVisible = NO; |
105 |
self.view.alpha = 0; |
|
106 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
|
3697 | 107 |
|
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
|
108 |
// set initial orientation wrt the controller orientation |
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
|
109 |
UIDeviceOrientation orientation = self.interfaceOrientation; |
3650 | 110 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG]; |
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
111 |
switch (orientation) { |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
112 |
case UIDeviceOrientationLandscapeLeft: |
3680 | 113 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(0)); |
114 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(90)); |
|
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
115 |
break; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
116 |
case UIDeviceOrientationLandscapeRight: |
3680 | 117 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadians(180)); |
118 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadians(-90)); |
|
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
119 |
break; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
120 |
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
|
121 |
DLog(@"unknown orientation"); |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
122 |
break; |
3627
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
123 |
} |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
124 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
f1da1d8fb56c
the game now respects the orientation of the frontend
koda
parents:
3626
diff
changeset
|
125 |
self.view.frame = CGRectMake(0, 0, rect.size.width, rect.size.height); |
3697 | 126 |
|
3547 | 127 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
128 |
interval:1000 |
|
129 |
target:self |
|
130 |
selector:@selector(dimOverlay) |
|
131 |
userInfo:nil |
|
132 |
repeats:YES]; |
|
3697 | 133 |
|
3547 | 134 |
// add timer too runloop, otherwise it doesn't work |
135 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
|
3697 | 136 |
|
137 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
3547 | 138 |
[[NSNotificationCenter defaultCenter] addObserver:self |
139 |
selector:@selector(didRotate:) |
|
3598 | 140 |
name:UIDeviceOrientationDidChangeNotification |
3547 | 141 |
object:nil]; |
142 |
||
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
143 |
[[NSNotificationCenter defaultCenter] addObserver:self |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
144 |
selector:@selector(showHelp:) |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
145 |
name:@"show help ingame" |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
146 |
object:nil]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
147 |
|
3547 | 148 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
149 |
[UIView setAnimationDuration:1]; |
|
150 |
self.view.alpha = 1; |
|
151 |
[UIView commitAnimations]; |
|
3697 | 152 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
153 |
// find the sdl window we're on |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
154 |
SDL_VideoDevice *_this = SDL_GetVideoDevice(); |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
155 |
SDL_VideoDisplay *display = &_this->displays[0]; |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
156 |
sdlwindow = display->windows; |
3547 | 157 |
} |
158 |
||
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
159 |
-(void) showHelp:(id) sender { |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
160 |
if (self.helpPage == nil) |
3792 | 161 |
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
|
162 |
self.helpPage.view.alpha = 0; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
163 |
[self.view addSubview:helpPage.view]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
164 |
[UIView beginAnimations:@"helpingame" context:NULL]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
165 |
self.helpPage.view.alpha = 1; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
166 |
[UIView commitAnimations]; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
167 |
doNotDim(); |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
168 |
} |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
169 |
|
3783 | 170 |
-(void) didReceiveMemoryWarning { |
171 |
[super didReceiveMemoryWarning]; |
|
172 |
if (self.popupMenu.view.superview == nil) |
|
173 |
self.popupMenu = nil; |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
174 |
if (self.helpPage.view.superview == nil) |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
175 |
self.helpPage = nil; |
3783 | 176 |
MSG_MEMCLEAN(); |
177 |
} |
|
178 |
||
3547 | 179 |
-(void) viewDidUnload { |
3783 | 180 |
// only objects initialized in viewDidLoad should be here |
181 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
|
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
|
182 |
dimTimer = nil; |
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
|
183 |
MSG_DIDUNLOAD(); |
3547 | 184 |
[super viewDidUnload]; |
185 |
} |
|
186 |
||
187 |
-(void) dealloc { |
|
188 |
[popupMenu release]; |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
189 |
[helpPage release]; |
3547 | 190 |
[popoverController release]; |
191 |
// dimTimer is autoreleased |
|
192 |
[super dealloc]; |
|
193 |
} |
|
194 |
||
195 |
#pragma mark - |
|
196 |
#pragma mark Overlay actions and members |
|
197 |
// nice transition for dimming, should be called only by the timer himself |
|
198 |
-(void) dimOverlay { |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
199 |
if (isGameRunning) { |
3547 | 200 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
201 |
[UIView setAnimationDuration:0.6]; |
|
202 |
self.view.alpha = 0.2; |
|
203 |
[UIView commitAnimations]; |
|
204 |
} |
|
205 |
} |
|
206 |
||
207 |
// set the overlay visible and put off the timer for enough time |
|
208 |
-(void) activateOverlay { |
|
209 |
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
|
210 |
doNotDim(); |
3547 | 211 |
} |
212 |
||
3626 | 213 |
// dim the overlay when there's no more input for a certain amount of time |
214 |
-(IBAction) buttonReleased:(id) sender { |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
215 |
if (!isGameRunning) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
216 |
return; |
3697 | 217 |
|
3626 | 218 |
UIButton *theButton = (UIButton *)sender; |
3697 | 219 |
|
3626 | 220 |
switch (theButton.tag) { |
221 |
case 0: |
|
222 |
case 1: |
|
223 |
case 2: |
|
224 |
case 3: |
|
3649 | 225 |
[NSObject cancelPreviousPerformRequestsWithTarget:self |
226 |
selector:@selector(unsetPreciseStatus) |
|
227 |
object:nil]; |
|
3626 | 228 |
HW_walkingKeysUp(); |
229 |
break; |
|
230 |
case 4: |
|
231 |
case 5: |
|
232 |
case 6: |
|
233 |
HW_otherKeysUp(); |
|
234 |
break; |
|
235 |
default: |
|
3660 | 236 |
DLog(@"Nope"); |
3626 | 237 |
break; |
238 |
} |
|
239 |
||
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
|
240 |
isAttacking = NO; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
241 |
doDim(); |
3626 | 242 |
} |
243 |
||
3697 | 244 |
// issue certain action based on the tag of the button |
3547 | 245 |
-(IBAction) buttonPressed:(id) sender { |
246 |
[self activateOverlay]; |
|
247 |
if (isPopoverVisible) { |
|
248 |
[self dismissPopover]; |
|
249 |
} |
|
3697 | 250 |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
251 |
if (!isGameRunning) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
252 |
return; |
3697 | 253 |
|
3779
3351a017d4ad
tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents:
3765
diff
changeset
|
254 |
if (HW_isWaiting()) |
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3783
diff
changeset
|
255 |
HW_dismissReady(); |
3779
3351a017d4ad
tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents:
3765
diff
changeset
|
256 |
|
3547 | 257 |
UIButton *theButton = (UIButton *)sender; |
258 |
switch (theButton.tag) { |
|
259 |
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
|
260 |
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
|
261 |
HW_walkLeft(); |
3547 | 262 |
break; |
263 |
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
|
264 |
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
|
265 |
HW_walkRight(); |
3547 | 266 |
break; |
267 |
case 2: |
|
3649 | 268 |
[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
|
269 |
HW_preciseSet(!HW_isWeaponRope()); |
3547 | 270 |
HW_aimUp(); |
271 |
break; |
|
272 |
case 3: |
|
3649 | 273 |
[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
|
274 |
HW_preciseSet(!HW_isWeaponRope()); |
3547 | 275 |
HW_aimDown(); |
276 |
break; |
|
277 |
case 4: |
|
278 |
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
|
279 |
isAttacking = YES; |
3547 | 280 |
break; |
281 |
case 5: |
|
282 |
HW_jump(); |
|
283 |
break; |
|
284 |
case 6: |
|
285 |
HW_backjump(); |
|
286 |
break; |
|
287 |
case 10: |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
288 |
playSound(@"clickSound"); |
3667 | 289 |
HW_pause(); |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
290 |
removeConfirmationInput(); |
3547 | 291 |
[self showPopover]; |
292 |
break; |
|
3624 | 293 |
case 11: |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
294 |
playSound(@"clickSound"); |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
295 |
removeConfirmationInput(); |
3624 | 296 |
HW_ammoMenu(); |
297 |
break; |
|
3547 | 298 |
default: |
3626 | 299 |
DLog(@"Nope"); |
3547 | 300 |
break; |
301 |
} |
|
302 |
} |
|
303 |
||
3649 | 304 |
-(void) unsetPreciseStatus { |
305 |
HW_preciseSet(NO); |
|
306 |
} |
|
307 |
||
3547 | 308 |
// present a further check before closing game |
309 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
310 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
311 |
HW_terminate(NO); |
|
312 |
else |
|
3697 | 313 |
HW_pause(); |
3547 | 314 |
} |
315 |
||
316 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
317 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
|
318 |
-(IBAction) showPopover{ |
|
3667 | 319 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3547 | 320 |
isPopoverVisible = YES; |
321 |
||
322 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3697 | 323 |
if (popupMenu == nil) |
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
324 |
popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
3547 | 325 |
if (popoverController == nil) { |
326 |
popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
|
327 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
328 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
|
329 |
} |
|
3551 | 330 |
|
3667 | 331 |
[popoverController presentPopoverFromRect:CGRectMake(screen.size.height / 2, screen.size.width / 2, 1, 1) |
3547 | 332 |
inView:self.view |
3667 | 333 |
permittedArrowDirections:UIPopoverArrowDirectionAny |
3547 | 334 |
animated:YES]; |
335 |
} else { |
|
3648 | 336 |
if (popupMenu == nil) |
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
337 |
popupMenu = [[InGameMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3697 | 338 |
|
3547 | 339 |
[self.view addSubview:popupMenu.view]; |
3648 | 340 |
[popupMenu present]; |
3547 | 341 |
} |
342 |
popupMenu.tableView.scrollEnabled = NO; |
|
343 |
} |
|
344 |
||
345 |
// on ipad just dismiss it, on iphone transtion to the right |
|
346 |
-(void) dismissPopover { |
|
347 |
if (YES == isPopoverVisible) { |
|
348 |
isPopoverVisible = NO; |
|
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
349 |
if (HW_isPaused()) |
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
350 |
HW_pause(); |
3697 | 351 |
|
3547 | 352 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
3648 | 353 |
[(InGameMenuViewController *)popoverController.contentViewController removeChat]; |
3547 | 354 |
[popoverController dismissPopoverAnimated:YES]; |
355 |
} else { |
|
3648 | 356 |
[popupMenu dismiss]; |
3547 | 357 |
} |
358 |
[self buttonReleased:nil]; |
|
359 |
} |
|
360 |
} |
|
361 |
||
362 |
#pragma mark - |
|
363 |
#pragma mark Custom touch event handling |
|
364 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
365 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
366 |
UITouch *first, *second; |
3697 | 367 |
|
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
|
368 |
if (isGameRunning == NO) |
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
|
369 |
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
|
370 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
371 |
// hide in-game menu |
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3646
diff
changeset
|
372 |
if (isPopoverVisible) |
3547 | 373 |
[self dismissPopover]; |
3697 | 374 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
375 |
// reset default dimming |
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
376 |
doDim(); |
3697 | 377 |
|
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
378 |
HW_setPianoSound([allTouches count]); |
3697 | 379 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
380 |
switch ([allTouches count]) { |
3697 | 381 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
382 |
removeConfirmationInput(); |
3651 | 383 |
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
|
384 |
if (2 == [[[allTouches allObjects] objectAtIndex:0] tapCount]) |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
385 |
HW_zoomReset(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
386 |
break; |
3697 | 387 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
388 |
// pinching |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
389 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
390 |
second = [[allTouches allObjects] objectAtIndex:1]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
391 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
392 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
393 |
default: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
394 |
break; |
3547 | 395 |
} |
396 |
} |
|
397 |
||
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
398 |
//if (currentPosition.y < screen.size.width - 130 || (currentPosition.x > 130 && currentPosition.x < screen.size.height - 130)) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
399 |
|
3547 | 400 |
-(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
|
401 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
402 |
NSSet *allTouches = [event allTouches]; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
403 |
CGPoint currentPosition = [[[allTouches allObjects] objectAtIndex:0] locationInView:self.view]; |
3697 | 404 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
405 |
switch ([allTouches count]) { |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
406 |
case 1: |
3779
3351a017d4ad
tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents:
3765
diff
changeset
|
407 |
// this dismisses the "get ready" |
3351a017d4ad
tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents:
3765
diff
changeset
|
408 |
if (HW_isWaiting()) |
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3783
diff
changeset
|
409 |
HW_dismissReady(); |
3779
3351a017d4ad
tap to dismiss 'get ready', add a toggle to enable/disable it
koda
parents:
3765
diff
changeset
|
410 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
411 |
// if we're in the menu we just click in the point |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
412 |
if (HW_isAmmoOpen()) { |
3680 | 413 |
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
|
414 |
// 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
|
415 |
HW_click(); |
3697 | 416 |
} else |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
417 |
// 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
|
418 |
if (HW_isWeaponRequiringClick()) { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
419 |
// 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
|
420 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
3697 | 421 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
422 |
// 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
|
423 |
UIButton *tapAgain = [UIButton buttonWithType:UIButtonTypeRoundedRect]; |
3672
f225b94a4411
shrink confirmation button, double tap resets zoom and centers hog
koda
parents:
3668
diff
changeset
|
424 |
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
|
425 |
tapAgain.tag = CONFIRMATION_TAG; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
426 |
tapAgain.alpha = 0; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
427 |
[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
|
428 |
[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
|
429 |
[self.view addSubview:tapAgain]; |
3697 | 430 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
431 |
// animation ftw! |
3697 | 432 |
[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
|
433 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
434 |
[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
|
435 |
[UIView commitAnimations]; |
3697 | 436 |
|
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
437 |
// keep the overlay active, or the button will fade |
3650 | 438 |
[self activateOverlay]; |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
439 |
doNotDim(); |
3650 | 440 |
} else |
441 |
if (HW_isWeaponTimerable()) { |
|
442 |
if (isSegmentVisible) { |
|
443 |
UISegmentedControl *grenadeTime = (UISegmentedControl *)[self.view viewWithTag:GRENADE_TAG]; |
|
3697 | 444 |
|
3650 | 445 |
[UIView beginAnimations:@"removing segmented control" context:NULL]; |
446 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
447 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
448 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
449 |
[UIView commitAnimations]; |
|
3697 | 450 |
|
3650 | 451 |
[grenadeTime performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:ANIMATION_DURATION]; |
452 |
} else { |
|
453 |
NSArray *items = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",nil]; |
|
454 |
UISegmentedControl *grenadeTime = [[UISegmentedControl alloc] initWithItems:items]; |
|
455 |
[items release]; |
|
3697 | 456 |
|
3650 | 457 |
[grenadeTime addTarget:self action:@selector(setGrenadeTime:) forControlEvents:UIControlEventValueChanged]; |
458 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width, 250, 50); |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
459 |
grenadeTime.selectedSegmentIndex = cachedGrenadeTime; |
3650 | 460 |
grenadeTime.tag = GRENADE_TAG; |
461 |
[self.view addSubview:grenadeTime]; |
|
462 |
[grenadeTime release]; |
|
3697 | 463 |
|
3650 | 464 |
[UIView beginAnimations:@"inserting segmented control" context:NULL]; |
465 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
|
466 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; |
|
467 |
grenadeTime.frame = CGRectMake(screen.size.height / 2 - 125, screen.size.width - 100, 250, 50); |
|
468 |
[UIView commitAnimations]; |
|
3697 | 469 |
|
3650 | 470 |
[self activateOverlay]; |
471 |
doNotDim(); |
|
3697 | 472 |
} |
3650 | 473 |
isSegmentVisible = !isSegmentVisible; |
3661 | 474 |
} else |
475 |
if (HW_isWeaponSwitch()) |
|
476 |
HW_tab(); |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
477 |
break; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
478 |
case 2: |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
479 |
HW_allKeysUp(); |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
480 |
break; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
481 |
default: |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
482 |
break; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
483 |
} |
3697 | 484 |
|
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
|
485 |
initialDistanceForPinching = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
486 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
487 |
|
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
488 |
-(void) sendHWClick { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
489 |
HW_click(); |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
490 |
removeConfirmationInput(); |
3646
a3271158d93b
don't make the confirmation button disappear, present an alert if game doesn't start
koda
parents:
3639
diff
changeset
|
491 |
doDim(); |
3547 | 492 |
} |
493 |
||
3650 | 494 |
-(void) setGrenadeTime:(id) sender { |
495 |
UISegmentedControl *theSegment = (UISegmentedControl *)sender; |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
496 |
if (cachedGrenadeTime != theSegment.selectedSegmentIndex) { |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
497 |
HW_setGrenadeTime(theSegment.selectedSegmentIndex + 1); |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
498 |
cachedGrenadeTime = theSegment.selectedSegmentIndex; |
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
499 |
} |
3650 | 500 |
} |
501 |
||
3547 | 502 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
503 |
[self touchesEnded:touches withEvent:event]; |
|
504 |
} |
|
505 |
||
506 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
|
3551 | 507 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
508 |
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
|
509 |
int x, y, dx, dy; |
3697 | 510 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
511 |
UITouch *touch, *first, *second; |
3547 | 512 |
|
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
513 |
switch ([allTouches count]) { |
3551 | 514 |
case 1: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
515 |
touch = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
516 |
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
|
517 |
|
3680 | 518 |
if (HW_isAmmoOpen()) { |
519 |
// no zoom consideration for this |
|
520 |
HW_setCursor(HWXZ(currentPosition.x), HWYZ(currentPosition.y)); |
|
521 |
} else |
|
522 |
if (HW_isWeaponRequiringClick()) { |
|
523 |
// moves the cursor around wrt zoom |
|
524 |
HW_setCursor(HWX(currentPosition.x), HWY(currentPosition.y)); |
|
525 |
} else { |
|
526 |
// panning \o/ |
|
527 |
dx = startingPoint.x - currentPosition.x; |
|
528 |
dy = currentPosition.y - startingPoint.y; |
|
529 |
HW_getCursor(&x, &y); |
|
530 |
// momentum (or something like that) |
|
531 |
/*if (abs(dx) > 40) |
|
532 |
dx *= log(abs(dx)/4); |
|
533 |
if (abs(dy) > 40) |
|
534 |
dy *= log(abs(dy)/4);*/ |
|
535 |
HW_setCursor(x + dx/HW_zoomFactor(), y + dy/HW_zoomFactor()); |
|
536 |
startingPoint = currentPosition; |
|
537 |
} |
|
3551 | 538 |
break; |
3547 | 539 |
case 2: |
3638
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
540 |
first = [[allTouches allObjects] objectAtIndex:0]; |
33ee433749ba
touch overlay reworked, improvements to zoom and confirmation
koda
parents:
3637
diff
changeset
|
541 |
second = [[allTouches allObjects] objectAtIndex:1]; |
3547 | 542 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
543 |
const int pinchDelta = 40; |
|
3697 | 544 |
|
3547 | 545 |
if (0 != initialDistanceForPinching) { |
546 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
547 |
HW_zoomIn(); |
|
548 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
549 |
} |
|
550 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
551 |
HW_zoomOut(); |
|
552 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
553 |
} |
|
3697 | 554 |
} else |
3547 | 555 |
initialDistanceForPinching = currentDistanceOfPinching; |
3697 | 556 |
|
3547 | 557 |
break; |
558 |
default: |
|
559 |
break; |
|
560 |
} |
|
561 |
} |
|
562 |
||
3650 | 563 |
#pragma mark - |
564 |
#pragma mark Functions called by pascal |
|
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
565 |
// called from AddProgress and FinishProgress (respectively) |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
566 |
void startSpinning() { |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
567 |
isGameRunning = NO; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
568 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
569 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
570 |
indicator.tag = 987654; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
571 |
indicator.center = CGPointMake(screen.size.width/2 - 118, screen.size.height/2); |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
572 |
indicator.hidesWhenStopped = YES; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
573 |
[indicator startAnimating]; |
3650 | 574 |
[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] addSubview:indicator]; |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
575 |
[indicator release]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
576 |
} |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
577 |
|
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
578 |
void stopSpinning() { |
3650 | 579 |
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[[[[UIApplication sharedApplication] keyWindow] viewWithTag:SDL_VIEW_TAG] viewWithTag:987654]; |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
580 |
[indicator stopAnimating]; |
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
581 |
isGameRunning = YES; |
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
|
582 |
HW_zoomSet(1.7); |
3629
86212d2b116a
redo spinning wheel, redo fix for detail selection, redo ammo quantity and name in ammomenu
koda
parents:
3628
diff
changeset
|
583 |
} |
3547 | 584 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
585 |
void clearView() { |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
586 |
UIWindow *theWindow = [[UIApplication sharedApplication] keyWindow]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
587 |
UIButton *theButton = (UIButton *)[theWindow viewWithTag:CONFIRMATION_TAG]; |
3650 | 588 |
UISegmentedControl *theSegment = (UISegmentedControl *)[theWindow viewWithTag:GRENADE_TAG]; |
3697 | 589 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
590 |
[UIView beginAnimations:@"remove button" context:NULL]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
591 |
[UIView setAnimationDuration:ANIMATION_DURATION]; |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
592 |
theButton.alpha = 0; |
3650 | 593 |
theSegment.alpha = 0; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
594 |
[UIView commitAnimations]; |
3697 | 595 |
|
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
596 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theButton afterDelay:0.3]; |
3697 | 597 |
[theWindow performSelector:@selector(removeFromSuperview) withObject:theSegment afterDelay:0.3]; |
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
598 |
|
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3789
diff
changeset
|
599 |
cachedGrenadeTime = 2; |
3639
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
600 |
} |
b5cdbcc89b61
use a button instead of label and simplify a lot touch interaction
koda
parents:
3638
diff
changeset
|
601 |
|
3547 | 602 |
@end |