author | koda |
Wed, 23 Jun 2010 01:00:52 +0200 | |
changeset 3535 | 9e78c1f3d8d8 |
parent 3525 | 1d7b056ff866 |
child 3546 | ccf4854df294 |
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 |
3525 | 23 |
@synthesize popoverController, popupMenu, writeChatTextField, spinningWheel; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
24 |
|
3335 | 25 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
26 |
return rotationManager(interfaceOrientation); |
|
27 |
} |
|
28 |
||
29 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
30 |
-(void) didReceiveMemoryWarning { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
31 |
// 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
|
32 |
[super didReceiveMemoryWarning]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
33 |
// Release any cached data, images, etc that aren't in use. |
3490 | 34 |
if (popupMenu.view.superview == nil) |
35 |
popupMenu = nil; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
36 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
37 |
|
3385 | 38 |
-(void) didRotate:(NSNotification *)notification { |
39 |
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; |
|
40 |
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
|
41 |
CGRect usefulRect = CGRectMake(0, 0, rect.size.width, rect.size.height); |
3463 | 42 |
UIView *sdlView = [[[UIApplication sharedApplication] keyWindow] viewWithTag:12345]; |
3385 | 43 |
|
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
|
44 |
[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
|
45 |
[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
|
46 |
[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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
3463 | 51 |
[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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
3385 | 56 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); |
3463 | 57 |
[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
|
58 |
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
|
59 |
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
|
60 |
case UIDeviceOrientationPortrait: |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
61 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
62 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(270)); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
63 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(0)); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
64 |
[self chatAppear]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
65 |
HW_setLandscape(NO); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
66 |
} |
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
|
67 |
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
|
68 |
case UIDeviceOrientationPortraitUpsideDown: |
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
69 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
70 |
sdlView.transform = CGAffineTransformMakeRotation(degreesToRadian(90)); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
71 |
self.view.transform = CGAffineTransformMakeRotation(degreesToRadian(180)); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
72 |
[self chatAppear]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
73 |
HW_setLandscape(NO); |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
74 |
} |
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
|
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 |
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
|
77 |
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
|
78 |
} |
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 |
self.view.frame = usefulRect; |
3463 | 80 |
//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
|
81 |
[UIView commitAnimations]; |
3340 | 82 |
} |
3385 | 83 |
|
3463 | 84 |
-(void) chatAppear { |
85 |
if (writeChatTextField == nil) { |
|
86 |
writeChatTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 100, 768, [UIFont systemFontSize]+8)]; |
|
87 |
writeChatTextField.textColor = [UIColor whiteColor]; |
|
88 |
writeChatTextField.backgroundColor = [UIColor blueColor]; |
|
89 |
writeChatTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; |
|
90 |
writeChatTextField.autocorrectionType = UITextAutocorrectionTypeNo; |
|
91 |
writeChatTextField.enablesReturnKeyAutomatically = NO; |
|
92 |
writeChatTextField.keyboardAppearance = UIKeyboardAppearanceDefault; |
|
93 |
writeChatTextField.keyboardType = UIKeyboardTypeDefault; |
|
94 |
writeChatTextField.returnKeyType = UIReturnKeyDefault; |
|
95 |
writeChatTextField.secureTextEntry = NO; |
|
96 |
[self.view addSubview:writeChatTextField]; |
|
97 |
} |
|
98 |
writeChatTextField.alpha = 1; |
|
3479 | 99 |
[self activateOverlay]; |
100 |
[dimTimer setFireDate:HIDING_TIME_NEVER]; |
|
3463 | 101 |
} |
102 |
||
103 |
-(void) chatDisappear { |
|
104 |
writeChatTextField.alpha = 0; |
|
105 |
[writeChatTextField resignFirstResponder]; |
|
106 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
107 |
} |
|
108 |
||
3523 | 109 |
#pragma mark - |
110 |
#pragma mark View Management |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
111 |
-(void) viewDidLoad { |
3308 | 112 |
isPopoverVisible = NO; |
3525 | 113 |
singleton = self.spinningWheel; |
114 |
canDim = NO; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
115 |
self.view.alpha = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
116 |
self.view.center = CGPointMake(self.view.frame.size.height/2.0, self.view.frame.size.width/2.0); |
3385 | 117 |
|
3317
198ec44b6d92
minor tweaks, icon for ipad, merged overlayviewcontroller, pop viewcontroller when selected a hat
koda
parents:
3308
diff
changeset
|
118 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
119 |
dimTimer = [[NSTimer alloc] initWithFireDate:[NSDate dateWithTimeIntervalSinceNow:6] |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
120 |
interval:1000 |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
121 |
target:self |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
122 |
selector:@selector(dimOverlay) |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
123 |
userInfo:nil |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
124 |
repeats:YES]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
125 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
126 |
// add timer too runloop, otherwise it doesn't work |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
127 |
[[NSRunLoop currentRunLoop] addTimer:dimTimer forMode:NSDefaultRunLoopMode]; |
3357 | 128 |
|
129 |
// listen for dismissal of the popover (see below) |
|
130 |
[[NSNotificationCenter defaultCenter] addObserver:self |
|
131 |
selector:@selector(dismissPopover) |
|
132 |
name:@"dismissPopover" |
|
133 |
object:nil]; |
|
3385 | 134 |
|
3513
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
135 |
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
136 |
[[NSNotificationCenter defaultCenter] addObserver:self |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
137 |
selector:@selector(didRotate:) |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
138 |
name:@"UIDeviceOrientationDidChangeNotification" |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
139 |
object:nil]; |
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
140 |
|
f589230fa21b
now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents:
3490
diff
changeset
|
141 |
//self.view.transform = CGAffineTransformRotate(self.view.transform, (M_PI/2.0)); |
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; |
|
3525 | 152 |
self.spinningWheel = nil; |
3463 | 153 |
[super viewDidUnload]; |
3490 | 154 |
MSG_DIDUNLOAD(); |
3463 | 155 |
} |
156 |
||
157 |
-(void) dealloc { |
|
158 |
[dimTimer invalidate]; |
|
159 |
[writeChatTextField release]; |
|
160 |
[popupMenu release]; |
|
161 |
[popoverController release]; |
|
162 |
// dimTimer is autoreleased |
|
3525 | 163 |
[spinningWheel release]; |
3463 | 164 |
[super dealloc]; |
165 |
} |
|
166 |
||
3523 | 167 |
#pragma mark - |
168 |
#pragma mark Overlay actions and members |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
169 |
// 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
|
170 |
-(IBAction) buttonReleased:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
171 |
HW_allKeysUp(); |
3463 | 172 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
173 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
174 |
|
3463 | 175 |
// 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
|
176 |
-(void) dimOverlay { |
3525 | 177 |
if (canDim) { |
178 |
[UIView beginAnimations:@"overlay dim" context:NULL]; |
|
179 |
[UIView setAnimationDuration:0.6]; |
|
180 |
self.view.alpha = 0.2; |
|
181 |
[UIView commitAnimations]; |
|
182 |
} |
|
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 |
// 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
|
186 |
-(void) activateOverlay { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
187 |
self.view.alpha = 1; |
3463 | 188 |
[dimTimer setFireDate:HIDING_TIME_NEVER]; |
3117
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 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
191 |
// 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
|
192 |
-(IBAction) buttonPressed:(id) sender { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
193 |
[self activateOverlay]; |
3308 | 194 |
if (isPopoverVisible) { |
195 |
[self dismissPopover]; |
|
196 |
} |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
197 |
UIButton *theButton = (UIButton *)sender; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
198 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
199 |
switch (theButton.tag) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
200 |
case 0: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
201 |
HW_walkLeft(); |
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 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
204 |
HW_walkRight(); |
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 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
207 |
HW_aimUp(); |
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 3: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
210 |
HW_aimDown(); |
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 4: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
213 |
HW_shoot(); |
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 5: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
216 |
HW_jump(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
217 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
218 |
case 6: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
219 |
HW_backjump(); |
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 |
case 7: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
222 |
HW_tab(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
223 |
break; |
3308 | 224 |
case 10: |
225 |
[self showPopover]; |
|
226 |
break; |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
227 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
228 |
NSLog(@"Nope"); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
229 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
230 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
231 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
232 |
|
3305 | 233 |
// present a further check before closing game |
234 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
235 |
if ([actionSheet cancelButtonIndex] != buttonIndex) |
|
236 |
HW_terminate(NO); |
|
237 |
else |
|
238 |
HW_pause(); |
|
239 |
} |
|
240 |
||
241 |
// show up a popover containing a popupMenuViewController; we hook it with setPopoverContentSize |
|
3308 | 242 |
// on iphone instead just use the tableViewController directly (and implement manually all animations) |
3305 | 243 |
-(IBAction) showPopover{ |
3308 | 244 |
isPopoverVisible = YES; |
3463 | 245 |
CGRect anchorForPopover; |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
246 |
|
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
247 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
3490 | 248 |
if (popupMenu == nil) |
249 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStylePlain]; |
|
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
250 |
if (popoverController == nil) { |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
251 |
popoverController = [[UIPopoverController alloc] initWithContentViewController:popupMenu]; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
252 |
[popoverController setPopoverContentSize:CGSizeMake(220, 170) animated:YES]; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
253 |
[popoverController setPassthroughViews:[NSArray arrayWithObject:self.view]]; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
254 |
} |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
255 |
|
3463 | 256 |
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) |
257 |
anchorForPopover = CGRectMake(960, 0, 220, 32); |
|
258 |
else |
|
259 |
anchorForPopover = CGRectMake(736, 0, 220, 32); |
|
3305 | 260 |
|
3463 | 261 |
[popoverController presentPopoverFromRect:anchorForPopover |
3308 | 262 |
inView:self.view |
3463 | 263 |
permittedArrowDirections:UIPopoverArrowDirectionUp |
3308 | 264 |
animated:YES]; |
3305 | 265 |
} else { |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
266 |
if (popupMenu == nil) { |
3490 | 267 |
popupMenu = [[PopoverMenuViewController alloc] initWithStyle:UITableViewStyleGrouped]; |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
268 |
popupMenu.view.backgroundColor = [UIColor clearColor]; |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
269 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
270 |
} |
3308 | 271 |
[self.view addSubview:popupMenu.view]; |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
272 |
|
3308 | 273 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
274 |
[UIView setAnimationDuration:0.35]; |
|
275 |
popupMenu.view.frame = CGRectMake(280, 0, 200, 170); |
|
276 |
[UIView commitAnimations]; |
|
277 |
} |
|
278 |
popupMenu.tableView.scrollEnabled = NO; |
|
279 |
} |
|
280 |
||
3463 | 281 |
// on ipad just dismiss it, on iphone transtion to the right |
3308 | 282 |
-(void) dismissPopover { |
283 |
if (YES == isPopoverVisible) { |
|
284 |
isPopoverVisible = NO; |
|
285 |
||
286 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
287 |
[popoverController dismissPopoverAnimated:YES]; |
|
288 |
} else { |
|
289 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
|
290 |
[UIView setAnimationDuration:0.35]; |
|
291 |
popupMenu.view.frame = CGRectMake(480, 0, 200, 170); |
|
292 |
[UIView commitAnimations]; |
|
293 |
||
294 |
[popupMenu.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
|
295 |
} |
|
296 |
[self buttonReleased:nil]; |
|
3305 | 297 |
} |
298 |
} |
|
299 |
||
3463 | 300 |
-(void) textFieldDoneEditing:(id) sender{ |
301 |
[sender resignFirstResponder]; |
|
302 |
} |
|
3305 | 303 |
|
3525 | 304 |
// this function is called by pascal FinishProgress and removes the spinning wheel when loading is done |
305 |
void spinningWheelDone (void) { |
|
306 |
[UIView beginAnimations:@"hiding spinning wheel" context:NULL]; |
|
307 |
[UIView setAnimationDuration:0.7]; |
|
308 |
singleton.alpha = 0; |
|
309 |
[UIView commitAnimations]; |
|
310 |
[singleton performSelector:@selector(stopAnimating) withObject:nil afterDelay:0.7]; |
|
311 |
canDim = YES; |
|
312 |
} |
|
313 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
314 |
#pragma mark - |
3305 | 315 |
#pragma mark Custom touch event handling |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
316 |
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
317 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
318 |
UITouch *touch = [touches anyObject]; |
3305 | 319 |
|
3308 | 320 |
if (isPopoverVisible) { |
321 |
[self dismissPopover]; |
|
322 |
} |
|
3463 | 323 |
if (writeChatTextField) { |
324 |
[self.writeChatTextField resignFirstResponder]; |
|
325 |
[dimTimer setFireDate:HIDING_TIME_DEFAULT]; |
|
326 |
} |
|
3347 | 327 |
|
328 |
gestureStartPoint = [touch locationInView:self.view]; |
|
3308 | 329 |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
330 |
switch ([touches count]) { |
3523 | 331 |
/*case 1: |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
332 |
initialDistanceForPinching = 0; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
333 |
switch ([touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
334 |
case 1: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
335 |
NSLog(@"X:%d Y:%d", (int)gestureStartPoint.x, (int)gestureStartPoint.y ); |
3347 | 336 |
//SDL_WarpMouseInWindow([SDLUIKitDelegate sharedAppDelegate].window, |
337 |
// (int)gestureStartPoint.y, width - (int)gestureStartPoint.x); |
|
338 |
//HW_click(); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
339 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
340 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
341 |
HW_ammoMenu(); |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
342 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
343 |
default: |
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 |
} |
3523 | 346 |
break;*/ |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
347 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
348 |
if (2 == [touch tapCount]) { |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
349 |
HW_zoomReset(); |
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 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
352 |
// pinching |
3523 | 353 |
gestureStartPoint = CGPointMake(0, 0); |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
354 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
355 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
356 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
357 |
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
|
358 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
359 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
360 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
361 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
362 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
363 |
} |
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 |
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { |
3523 | 366 |
gestureStartPoint = CGPointMake(0, 0); |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
367 |
initialDistanceForPinching = 0; |
3523 | 368 |
//HW_allKeysUp(); |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
369 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
370 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
371 |
-(void) touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { |
3347 | 372 |
// 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
|
373 |
[self touchesEnded:touches withEvent:event]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
374 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
375 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
376 |
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { |
3364 | 377 |
CGFloat minimumGestureLength; |
3347 | 378 |
int logCoeff; |
379 |
||
380 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
3364 | 381 |
minimumGestureLength = 5.0f; |
3347 | 382 |
logCoeff = 19; |
383 |
} else { |
|
3364 | 384 |
minimumGestureLength = 3.0f; |
3347 | 385 |
logCoeff = 3; |
386 |
} |
|
387 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
388 |
NSArray *twoTouches; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
389 |
CGPoint currentPosition; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
390 |
UITouch *touch = [touches anyObject]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
391 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
392 |
switch ([touches count]) { |
3523 | 393 |
/*case 1: |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
394 |
currentPosition = [touch locationInView:self.view]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
395 |
// panning |
3347 | 396 |
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); |
397 |
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); |
|
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
398 |
|
3523 | 399 |
// the two ifs are not mutually exclusive |
3347 | 400 |
if (deltaX >= minimumGestureLength) { |
3535
9e78c1f3d8d8
update the project to ios4 by removing pre-3.2 references
koda
parents:
3525
diff
changeset
|
401 |
DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY); |
3364 | 402 |
if (currentPosition.x > gestureStartPoint.x) { |
3356 | 403 |
HW_cursorLeft(logCoeff*log(deltaX)); |
3347 | 404 |
} else { |
3356 | 405 |
HW_cursorRight(logCoeff*log(deltaX)); |
3347 | 406 |
} |
407 |
||
408 |
} |
|
409 |
if (deltaY >= minimumGestureLength) { |
|
3523 | 410 |
DLog(@"deltaX: %f deltaY: %f", deltaX, deltaY); |
3364 | 411 |
if (currentPosition.y < gestureStartPoint.y) { |
3356 | 412 |
HW_cursorDown(logCoeff*log(deltaY)); |
3347 | 413 |
} else { |
3356 | 414 |
HW_cursorUp(logCoeff*log(deltaY)); |
3347 | 415 |
} |
416 |
} |
|
417 |
||
3523 | 418 |
break;*/ |
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
419 |
case 2: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
420 |
twoTouches = [touches allObjects]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
421 |
UITouch *first = [twoTouches objectAtIndex:0]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
422 |
UITouch *second = [twoTouches objectAtIndex:1]; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
423 |
CGFloat currentDistanceOfPinching = distanceBetweenPoints([first locationInView:self.view], [second locationInView:self.view]); |
3523 | 424 |
const int pinchDelta = 40; |
425 |
||
426 |
if (0 != initialDistanceForPinching) { |
|
427 |
if (currentDistanceOfPinching - initialDistanceForPinching > pinchDelta) { |
|
428 |
HW_zoomIn(); |
|
429 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
430 |
} |
|
431 |
else if (initialDistanceForPinching - currentDistanceOfPinching > pinchDelta) { |
|
432 |
HW_zoomOut(); |
|
433 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
434 |
} |
|
435 |
} else |
|
436 |
initialDistanceForPinching = currentDistanceOfPinching; |
|
437 |
||
3117
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
438 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
439 |
default: |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
440 |
break; |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
441 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
442 |
} |
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
443 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
444 |
|
f3e363a9b7db
complete previous commit (which broken my local copy as well)
koda
parents:
diff
changeset
|
445 |
@end |