author | sheepluva |
Wed, 16 Jun 2010 21:14:23 +0200 | |
changeset 3508 | a7ca07614a2d |
parent 3490 | 016b3172b645 |
child 3513 | f589230fa21b |
permissions | -rw-r--r-- |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
1 |
// |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
2 |
// overlayViewController.m |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
3 |
// HedgewarsMobile |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
4 |
// |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
5 |
// Created by Vittorio on 16/03/10. |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
7 |
// |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
8 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
9 |
#import "OverlayViewController.h" |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
10 |
#import "SDL_uikitappdelegate.h" |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
11 |
#import "PascalImports.h" |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
12 |
#import "CGPointUtils.h" |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
13 |
#import "SDL_mouse.h" |
3463 | 14 |
#import "SDL_config_iphoneos.h" |
3305 | 15 |
#import "PopoverMenuViewController.h" |
3335 | 16 |
#import "CommodityFunctions.h" |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
17 |
|
3463 | 18 |
#define HIDING_TIME_DEFAULT [NSDate dateWithTimeIntervalSinceNow:2.7] |
19 |
#define HIDING_TIME_NEVER [NSDate dateWithTimeIntervalSinceNow:10000] |
|
20 |
||
21 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
22 |
@implementation OverlayViewController |
3463 | 23 |
@synthesize popoverController, popupMenu, writeChatTextField; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
24 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
25 |
|
3335 | 26 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
27 |
return rotationManager(interfaceOrientation); |
|
28 |
} |
|
29 |
||
30 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
31 |
-(void) didReceiveMemoryWarning { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
32 |
// Releases the view if it doesn't have a superview. |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
33 |
[super didReceiveMemoryWarning]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
34 |
// Release any cached data, images, etc that aren't in use. |
3490 | 35 |
if (popupMenu.view.superview == nil) |
36 |
popupMenu = nil; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
37 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
38 |
|
3385 | 39 |
-(void) didRotate:(NSNotification *)notification { |
40 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
|
41 |
CGRect rect = [[UIScreen mainScreen] bounds]; |
|
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
42 |
CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); |
3463 | 43 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345]; |
3385 | 44 |
|
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
45 |
[UIView beginAnimations:@"rotation" context:NULL]; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
46 |
[UIView setAnimationDuration:0.8f]; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
47 |
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
48 |
switch (orientation) { |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
49 |
case UIDeviceOrientationLandscapeLeft: |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
50 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
51 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
3463 | 52 |
[self chatDisappear]; |
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
53 |
HW_setLandscape(YES); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
54 |
break; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
55 |
case UIDeviceOrientationLandscapeRight: |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
56 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
3385 | 57 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
3463 | 58 |
[self chatDisappear]; |
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
59 |
HW_setLandscape(YES); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
60 |
break; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
61 |
case UIDeviceOrientationPortrait: |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
62 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
63 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
3463 | 64 |
[self chatAppear]; |
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
65 |
HW_setLandscape(NO); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
66 |
break; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
67 |
case UIDeviceOrientationPortraitUpsideDown: |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
68 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
69 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
3463 | 70 |
[self chatAppear]; |
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
71 |
HW_setLandscape(NO); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
72 |
break; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
73 |
default: |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
74 |
NSLog(@"warning - Unknown rotation status"); |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
75 |
break; |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
76 |
} |
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
77 |
self.view.frame = usefulRect; |
3463 | 78 |
//sdlView.frame = usefulRect; |
3395
095273ad0e08
adding a somewhat working autoration for ipad (uStore.pas and uWorld.pas got mixed in the last two commits)
koda
parents:
3385
diff
changeset
|
79 |
[UIView commitAnimations]; |
3340 | 80 |
} |
3385 | 81 |
|
3463 | 82 |
-(void) chatAppear { |
83 |
if (writeChatTextField == nil) { |
|
84 |
writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)]; |
|
85 |
writeChatTextField.textColor = [UIColor whiteColor]; |
|
86 |
writeChatTextField.backgroundColor = [UIColor blueColor]; |
|
87 |
writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; |
|
88 |
writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo; |
|
89 |
writeChatTextField.enablesReturnKeyAutomatically = NO; |
|
90 |
writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault; |
|
91 |
writeChatTextField.keyboardType = UIKeyboardTypeDefault; |
|
92 |
writeChatTextField.returnKeyType = UIReturnKeyDefault; |
|
93 |
writeChatTextField.secureTextEntry = NO; |
|
94 |
[self.view addSubview:writeChatTextField]; |
|
95 |
} |
|
96 |
writeChatTextField.alpha = 1; |
|
3479 | 97 |
[self activateOverlay]; |
98 |
[dimTimer setFireDate:HIDING_TIME_NEVER]; |
|
3463 | 99 |
} |
100 |
||
101 |
-(void) chatDisappear { |
|
102 |
writeChatTextField.alpha = 0; |
|
103 |
[writeChatTextField resignFirstResponder]; |
|
104 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
105 |
} |
|
106 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
107 |
-(void) viewDidLoad { |
3308 | 108 |
isPopoverVisible = NO; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
109 |
self.view.alpha = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
110 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
3385 | 111 |
|
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3308
diff
changeset
|
112 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
113 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
114 |
interval:1000 |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
115 |
target:self |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
116 |
selector:@selector(dimOverlay) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
117 |
userInfo:nil |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
118 |
repeats:YES]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
119 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
120 |
// add timer too runloop, otherwise it doesn't work |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
121 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
3357 | 122 |
|
123 |
// listen for dismissal of the popover (see below) |
|
124 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
125 |
selector:@selector(dismissPopover) |
|
126 |
name:@"dismissPopover" |
|
127 |
object:nil]; |
|
3385 | 128 |
|
129 |
// need to split paths because iphone doesn't rotate (so we don't need to subscribe to any notification |
|
130 |
// nor perform engine actions when rotating |
|
131 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
132 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
|
133 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
134 |
selector:@selector(didRotate:) |
|
135 |
name:@"UIDeviceOrientationDidChangeNotification" |
|
136 |
object:nil]; |
|
137 |
||
138 |
[self didRotate:nil]; |
|
139 |
} else |
|
140 |
self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); |
|
141 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
142 |
[UIView beginAnimations:@"showing overlay" context:NULL]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
143 |
[UIView setAnimationDuration:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
144 |
self.view.alpha = 1; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
145 |
[UIView commitAnimations]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
146 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
147 |
|
3463 | 148 |
-(void) viewDidUnload { |
149 |
self.writeChatTextField = nil; |
|
150 |
self.popoverController = nil; |
|
151 |
self.popupMenu = nil; |
|
152 |
[super viewDidUnload]; |
|
3490 | 153 |
MSG_DIDUNLOAD(); |
3463 | 154 |
} |
155 |
||
156 |
-(void) dealloc { |
|
157 |
[dimTimer invalidate]; |
|
158 |
[writeChatTextField release]; |
|
159 |
[popupMenu release]; |
|
160 |
[popoverController release]; |
|
161 |
// dimTimer is autoreleased |
|
162 |
[super dealloc]; |
|
163 |
} |
|
164 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
165 |
// dim the overlay when there's no more input for a certain amount of time |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
166 |
-(IBAction) buttonReleased:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
167 |
HW_allKeysUp(); |
3463 | 168 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
169 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
170 |
|
3463 | 171 |
// nice transition for dimming, should be called only by the timer himself |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
172 |
-(void) dimOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
173 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
174 |
[UIView setAnimationDuration:0.6]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
175 |
self.view.alpha = 0.2; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
176 |
[UIView commitAnimations]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
177 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
178 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
179 |
// set the overlay visible and put off the timer for enough time |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
180 |
-(void) activateOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
181 |
self.view.alpha = 1; |
3463 | 182 |
[dimTimer setFireDate:HIDING_TIME_NEVER]; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
183 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
184 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
185 |
// issue certain action based on the tag of the button |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
186 |
-(IBAction) buttonPressed:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
187 |
[self activateOverlay]; |
3308 | 188 |
if (isPopoverVisible) { |
189 |
[self dismissPopover]; |
|
190 |
} |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
191 |
UIButton *theButton = (UIButton *)sender; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
192 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
193 |
switch (theButton.tag) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
194 |
case 0: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
195 |
HW_walkLeft(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
196 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
197 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
198 |
HW_walkRight(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
199 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
200 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
201 |
HW_aimUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
202 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
203 |
case 3: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
204 |
HW_aimDown(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
205 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
206 |
case 4: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
207 |
HW_shoot(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
208 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
209 |
case 5: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
210 |
HW_jump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
211 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
212 |
case 6: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
213 |
HW_backjump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
214 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
215 |
case 7: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
216 |
HW_tab(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
217 |
break; |
3308 | 218 |
case 10: |
219 |
[self showPopover]; |
|
220 |
break; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
221 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
222 |
NSLog(@"Nope"); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
223 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
224 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
225 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
226 |
|
3305 | 227 |
// present a further check before closing game |
228 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
229 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
230 |
HW_terminate(NO); |
|
231 |
else |
|
232 |
HW_pause(); |
|
233 |
} |
|
234 |
||
235 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
3308 | 236 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
3305 | 237 |
-(IBAction) showPopover{ |
3308 | 238 |
isPopoverVisible = YES; |
3463 | 239 |
CGRect anchorForPopover; |
3308 | 240 |
Class popoverControllerClass = NSClassFromString(@"UIPopoverController"); |
241 |
if (popoverControllerClass) { |
|
3490 | 242 |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2 |
243 |
if (popupMenu == nil) |
|
244 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
|
3308 | 245 |
popoverController = [[popoverControllerClass alloc] initWithContentViewController:popupMenu]; |
246 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
|
247 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
|
3463 | 248 |
|
249 |
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) |
|
250 |
anchorForPopover = CGRectMake(960, 0, 220, 32); |
|
251 |
else |
|
252 |
anchorForPopover = CGRectMake(736, 0, 220, 32); |
|
3305 | 253 |
|
3463 | 254 |
[popoverController presentPopoverFromRect:anchorForPopover |
3308 | 255 |
inView:self.view |
3463 | 256 |
permittedArrowDirections:UIPopoverArrowDirectionUp |
3308 | 257 |
animated:YES]; |
3305 | 258 |
#endif |
259 |
} else { |
|
3490 | 260 |
if (popupMenu == nil) |
261 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
|
3308 | 262 |
popupMenu.view.backgroundColor = [UIColor clearColor]; |
263 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
264 |
[self.view addSubview:popupMenu.view]; |
|
265 |
||
266 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
|
267 |
[UIView setAnimationDuration:0.35]; |
|
268 |
popupMenu.view.frame = CGRectMake(280, 0, 200, 170); |
|
269 |
[UIView commitAnimations]; |
|
270 |
} |
|
271 |
popupMenu.tableView.scrollEnabled = NO; |
|
272 |
} |
|
273 |
||
3463 | 274 |
// on ipad just dismiss it, on iphone transtion to the right |
3308 | 275 |
-(void) dismissPopover { |
276 |
if (YES == isPopoverVisible) { |
|
277 |
isPopoverVisible = NO; |
|
278 |
||
279 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3490 | 280 |
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_3_2 |
3308 | 281 |
[popoverController dismissPopoverAnimated:YES]; |
282 |
#endif |
|
283 |
} else { |
|
284 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
285 |
[UIView setAnimationDuration:0.35]; |
|
286 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
287 |
[UIView commitAnimations]; |
|
288 |
||
289 |
[popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
290 |
[popupMenu performSelector:@selector(release) withObject:nil afterDelay:0.35]; |
|
291 |
} |
|
292 |
[self buttonReleased:nil]; |
|
3305 | 293 |
} |
294 |
} |
|
295 |
||
3463 | 296 |
-(void) textFieldDoneEditing:(id) sender{ |
297 |
[sender resignFirstResponder]; |
|
298 |
} |
|
3305 | 299 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
300 |
#pragma mark - |
3305 | 301 |
#pragma mark Custom touch event handling |
302 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
303 |
#define kMinimumPinchDelta 50 |
3347 | 304 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
305 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
306 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
307 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
308 |
UITouch *touch = [touches anyObject]; |
3305 | 309 |
|
3308 | 310 |
if (isPopoverVisible) { |
311 |
[self dismissPopover]; |
|
312 |
} |
|
3463 | 313 |
if (writeChatTextField) { |
314 |
[self.writeChatTextField resignFirstResponder]; |
|
315 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
316 |
} |
|
3347 | 317 |
|
318 |
gestureStartPoint = [touch locationInView:self.view]; |
|
3308 | 319 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
320 |
switch ([touches count]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
321 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
322 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
323 |
switch ([touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
324 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
325 |
NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
3347 | 326 |
//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
327 |
// (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
|
328 |
//HW_click(); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
329 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
330 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
331 |
HW_ammoMenu(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
332 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
333 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
334 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
335 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
336 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
337 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
338 |
if (2 == [touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
339 |
HW_zoomReset(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
340 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
341 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
342 |
// pinching |
3347 | 343 |
gestureStartPoint.x = 0; |
344 |
gestureStartPoint.y = 0; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
345 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
346 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
347 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
348 |
initialDistanceForPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
349 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
350 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
351 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
352 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
353 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
354 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
355 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
356 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
357 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
358 |
HW_allKeysUp(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
359 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
360 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
361 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
3347 | 362 |
// this can happen if the user puts more than 5 touches on the screen at once, or perhaps in other circumstances |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
363 |
[self touchesEnded:touches withEvent:event]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
364 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
365 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
366 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
3364 | 367 |
CGFloat minimumGestureLength; |
3347 | 368 |
int logCoeff; |
369 |
||
370 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3364 | 371 |
minimumGestureLength = 5.0f; |
3347 | 372 |
logCoeff = 19; |
373 |
} else { |
|
3364 | 374 |
minimumGestureLength = 3.0f; |
3347 | 375 |
logCoeff = 3; |
376 |
} |
|
377 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
378 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
379 |
CGPoint currentPosition; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
380 |
UITouch *touch = [touches anyObject]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
381 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
382 |
switch ([touches count]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
383 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
384 |
currentPosition = [touch locationInView:self.view]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
385 |
// panning |
3347 | 386 |
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
387 |
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
388 |
|
3347 | 389 |
if (deltaX >= minimumGestureLength) { |
390 |
NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
3364 | 391 |
if (currentPosition.x > gestureStartPoint.x) { |
3356 | 392 |
HW_cursorLeft(logCoeff*log(deltaX)); |
3347 | 393 |
} else { |
3356 | 394 |
HW_cursorRight(logCoeff*log(deltaX)); |
3347 | 395 |
} |
396 |
||
397 |
} |
|
398 |
if (deltaY >= minimumGestureLength) { |
|
399 |
NSLog(@"Horizontal swipe detected, deltaX: %f deltaY: %f",deltaX, deltaY); |
|
3364 | 400 |
if (currentPosition.y < gestureStartPoint.y) { |
3356 | 401 |
HW_cursorDown(logCoeff*log(deltaY)); |
3347 | 402 |
} else { |
3356 | 403 |
HW_cursorUp(logCoeff*log(deltaY)); |
3347 | 404 |
} |
405 |
} |
|
406 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
407 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
408 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
409 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
410 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
411 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
412 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
413 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
414 |
if (0 == initialDistanceForPinching) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
415 |
initialDistanceForPinching = currentDistanceOfPinching; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
416 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
417 |
if (currentDistanceOfPinching < initialDistanceForPinching + kMinimumPinchDelta) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
418 |
HW_zoomOut(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
419 |
else if (currentDistanceOfPinching > initialDistanceForPinching + kMinimumPinchDelta) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
420 |
HW_zoomIn(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
421 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
422 |
currentDistanceOfPinching = initialDistanceForPinching; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
423 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
424 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
425 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
426 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
427 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
428 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
429 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
430 |
@end |