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