author | koda |
Tue, 25 Oct 2011 22:51:10 +0200 | |
changeset 6208 | b831679e9467 |
parent 6078 | 8c0cc07731e5 |
child 6260 | 025d50a6aeb0 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
4976 | 3 |
* Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 25/03/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
22 |
#import "InGameMenuViewController.h" |
3547 | 23 |
#import "SDL_sysvideo.h" |
3922
44804043b691
iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents:
3829
diff
changeset
|
24 |
#import "SDL_uikitkeyboard.h" |
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
6076
diff
changeset
|
25 |
|
4935 | 26 |
|
27 |
#define VIEW_HEIGHT 200 |
|
3547 | 28 |
|
3647
0d0df215fb52
making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents:
3598
diff
changeset
|
29 |
@implementation InGameMenuViewController |
3547 | 30 |
@synthesize menuList; |
31 |
||
32 |
||
33 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
34 |
return rotationManager(interfaceOrientation); |
|
35 |
} |
|
36 |
||
37 |
-(void) didReceiveMemoryWarning { |
|
3971 | 38 |
self.menuList = nil; |
3547 | 39 |
[super didReceiveMemoryWarning]; |
40 |
} |
|
41 |
||
42 |
-(void) viewDidLoad { |
|
43 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
3701 | 44 |
NSLocalizedString(@"Show Help", @""), |
3737
2ba6ac8a114b
reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents:
3701
diff
changeset
|
45 |
NSLocalizedString(@"Tag", @""), |
5711 | 46 |
// NSLocalizedString(@"Snapshot",@""), |
3547 | 47 |
NSLocalizedString(@"End Game", @""), |
48 |
nil]; |
|
49 |
self.menuList = array; |
|
50 |
[array release]; |
|
3697 | 51 |
|
3926
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
52 |
[super viewDidLoad]; |
668b71f31e51
use dynamic data from engine instead of using hardcoded values
koda
parents:
3924
diff
changeset
|
53 |
} |
3697 | 54 |
|
3547 | 55 |
-(void) viewDidUnload { |
56 |
self.menuList = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3660
diff
changeset
|
57 |
MSG_DIDUNLOAD(); |
3547 | 58 |
[super viewDidUnload]; |
59 |
} |
|
60 |
||
61 |
-(void) dealloc { |
|
5208 | 62 |
releaseAndNil(menuList); |
3547 | 63 |
[super dealloc]; |
64 |
} |
|
65 |
||
66 |
#pragma mark - |
|
3648 | 67 |
#pragma mark animating |
68 |
-(void) present { |
|
69 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
|
70 |
self.view.backgroundColor = [UIColor clearColor]; |
|
4935 | 71 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, VIEW_HEIGHT); |
3697 | 72 |
|
3648 | 73 |
[UIView beginAnimations:@"showing popover" context:NULL]; |
74 |
[UIView setAnimationDuration:0.35]; |
|
4935 | 75 |
self.view.frame = CGRectMake(screen.size.height-200, 0, 200, VIEW_HEIGHT); |
3648 | 76 |
[UIView commitAnimations]; |
77 |
} |
|
78 |
||
79 |
-(void) dismiss { |
|
4912
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
80 |
if (IS_IPAD() == NO) { |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
81 |
CGRect screen = [[UIScreen mainScreen] bounds]; |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
82 |
[UIView beginAnimations:@"hiding popover" context:NULL]; |
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
83 |
[UIView setAnimationDuration:0.35]; |
4935 | 84 |
self.view.frame = CGRectMake(screen.size.height, 0, 200, VIEW_HEIGHT); |
4912
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
85 |
[UIView commitAnimations]; |
4924 | 86 |
[self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35]; |
4912
862b134284b2
change order of statspage/gamerun when running in dual screen
koda
parents:
4861
diff
changeset
|
87 |
} |
3697 | 88 |
|
5166
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5156
diff
changeset
|
89 |
SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow()); |
4935 | 90 |
|
6076 | 91 |
/* |
4935 | 92 |
if (shouldTakeScreenshot) { |
93 |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please wait" |
|
94 |
message:nil |
|
95 |
delegate:nil |
|
96 |
cancelButtonTitle:nil |
|
97 |
otherButtonTitles:nil]; |
|
98 |
[alert show]; |
|
99 |
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] |
|
100 |
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
|
101 |
indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 45); |
|
102 |
[indicator startAnimating]; |
|
103 |
[alert addSubview:indicator]; |
|
104 |
[indicator release]; |
|
105 |
||
106 |
// all these hacks because of the PAUSE caption on top of everything... |
|
107 |
[self performSelector:@selector(saveCurrentScreenToPhotoAlbum:) withObject:alert afterDelay:0.3]; |
|
108 |
} |
|
6076 | 109 |
*/ |
4935 | 110 |
shouldTakeScreenshot = NO; |
3648 | 111 |
} |
112 |
||
113 |
#pragma mark - |
|
3547 | 114 |
#pragma mark tableView methods |
115 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
116 |
return 1; |
|
117 |
} |
|
118 |
||
119 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
5711 | 120 |
return 3; |
121 |
// return 4; |
|
3547 | 122 |
} |
123 |
||
124 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
125 |
static NSString *cellIdentifier = @"CellIdentifier"; |
|
3697 | 126 |
|
3547 | 127 |
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier]; |
128 |
if (nil == cell) { |
|
129 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault |
|
130 |
reuseIdentifier:cellIdentifier] autorelease]; |
|
131 |
} |
|
4920 | 132 |
cell.textLabel.text = [self.menuList objectAtIndex:[indexPath row]]; |
3697 | 133 |
|
3996 | 134 |
if (IS_IPAD()) |
3668
3f7a95234d8a
tap to play piano notes, fix for audio and pause glitch
koda
parents:
3667
diff
changeset
|
135 |
cell.textLabel.textAlignment = UITextAlignmentCenter; |
3697 | 136 |
|
3547 | 137 |
return cell; |
138 |
} |
|
139 |
||
140 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
141 |
UIActionSheet *actionSheet; |
|
6019 | 142 |
// UIAlertView *alert; |
3697 | 143 |
|
3547 | 144 |
switch ([indexPath row]) { |
145 |
case 0: |
|
3791
98072b3871c1
help page for ingame, some other fixes here and there
koda
parents:
3737
diff
changeset
|
146 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil]; |
4935 | 147 |
|
3547 | 148 |
break; |
149 |
case 1: |
|
4920 | 150 |
HW_chat(); |
151 |
SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow()); |
|
4935 | 152 |
|
3547 | 153 |
break; |
154 |
case 2: |
|
5711 | 155 |
/* |
4935 | 156 |
alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Going to take a screenshot",@"") |
157 |
message:NSLocalizedString(@"The game snapshot will be placed in your Photo Album and it will be taken as soon as the pause menu is dismissed",@"") |
|
158 |
delegate:nil |
|
159 |
cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"") |
|
160 |
otherButtonTitles:nil]; |
|
161 |
[alert show]; |
|
162 |
[alert release]; |
|
163 |
shouldTakeScreenshot = YES; |
|
164 |
||
165 |
break; |
|
166 |
case 3: |
|
5711 | 167 |
*/ |
3547 | 168 |
actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"") |
169 |
delegate:self |
|
170 |
cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"") |
|
171 |
destructiveButtonTitle:NSLocalizedString(@"Of course!", @"") |
|
172 |
otherButtonTitles:nil]; |
|
5662
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5483
diff
changeset
|
173 |
[actionSheet showInView:(IS_IPAD() ? self.view : UIVIEW_HW_SDLVIEW)]; |
3547 | 174 |
[actionSheet release]; |
3697 | 175 |
|
3547 | 176 |
break; |
177 |
default: |
|
3660 | 178 |
DLog(@"Warning: unset case value in section!"); |
3547 | 179 |
break; |
180 |
} |
|
3697 | 181 |
|
3547 | 182 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
183 |
} |
|
184 |
||
185 |
#pragma mark - |
|
186 |
#pragma mark actionSheet methods |
|
187 |
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex { |
|
4924 | 188 |
if ([actionSheet cancelButtonIndex] != buttonIndex) { |
5166
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5156
diff
changeset
|
189 |
SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow()); |
4861
91f889289a47
(ios) perform a small change about how to close the game window, should hopefully save memory and avoid crashes (who am i kidding? that's the usual PR talk...)
koda
parents:
4358
diff
changeset
|
190 |
HW_terminate(NO); |
4924 | 191 |
} |
3547 | 192 |
} |
193 |
||
5662
99083392cd4f
FREE AT LAST!!! SDL came around a (mostly) sane way for implementing rotation events, so we can scrap all the workaround code that has been added to workaround it!! Also this allows us to use proper (internal) multitasking handling and can simplify optional settings and other yet unexplored features. Yay!
koda
parents:
5483
diff
changeset
|
194 |
//TODO: check this is still needed since we switched to SDL_GL_CreateContext() |
6076 | 195 |
/* |
5166
d1eb1560b4d5
and now for something completely different, overlay refactoring!
koda
parents:
5156
diff
changeset
|
196 |
#pragma mark - |
4935 | 197 |
#pragma mark save screenshot |
198 |
//by http://www.bit-101.com/blog/?p=1861 |
|
199 |
// callback for CGDataProviderCreateWithData |
|
200 |
void releaseData(void *info, const void *data, size_t dataSize) { |
|
201 |
DLog(@"freeing raw data\n"); |
|
202 |
free((void *)data); |
|
203 |
} |
|
204 |
||
205 |
// callback for UIImageWriteToSavedPhotosAlbum |
|
206 |
-(void) image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { |
|
207 |
DLog(@"Save finished\n"); |
|
208 |
[image release]; |
|
209 |
UIAlertView *alert = (UIAlertView *)contextInfo; |
|
210 |
[alert dismissWithClickedButtonIndex:0 animated:YES]; |
|
211 |
[alert release]; |
|
212 |
} |
|
213 |
||
214 |
// the resolution of the buffer is always equal to the hardware device even if scaled |
|
215 |
-(void) saveCurrentScreenToPhotoAlbum:(UIAlertView *)alert { |
|
216 |
CGRect screenRect = [[UIScreen mainScreen] bounds]; |
|
217 |
int width = screenRect.size.width; |
|
218 |
int height = screenRect.size.height; |
|
219 |
||
220 |
NSInteger size = width * height * 4; |
|
221 |
GLubyte *buffer = (GLubyte *) malloc(size * sizeof(GLubyte)); |
|
222 |
GLubyte *buffer_flipped = (GLubyte *) malloc(size * sizeof(GLubyte)); |
|
223 |
||
224 |
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); |
|
4939
6d512ba87f72
screenshot binding for library (on ios it just plays the sound)
koda
parents:
4935
diff
changeset
|
225 |
HW_screenshot(); |
4935 | 226 |
// flip the data as glReadPixels here reads upside down |
227 |
for(int y = 0; y <height; y++) |
|
228 |
for(int x = 0; x <width * 4; x++) |
|
229 |
buffer_flipped[(int)((height - 1 - y) * width * 4 + x)] = buffer[(int)(y * 4 * width + x)]; |
|
230 |
free(buffer); |
|
231 |
||
232 |
CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer_flipped, size, releaseData); |
|
233 |
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB(); |
|
234 |
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault; |
|
235 |
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault; |
|
236 |
CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent); |
|
237 |
||
238 |
CGColorSpaceRelease(colorSpaceRef); |
|
239 |
CGDataProviderRelease(provider); |
|
240 |
||
241 |
UIImage *image; |
|
242 |
if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) |
|
243 |
image = [[UIImage alloc] initWithCGImage:imageRef scale:1 orientation:UIImageOrientationRight]; |
|
244 |
else |
|
245 |
image = [[UIImage alloc] initWithCGImage:imageRef]; |
|
246 |
CGImageRelease(imageRef); |
|
247 |
||
5483
fc755bb8096d
ios: caught some leaks, merged two methods inside a fuction, postponed the rating popup
koda
parents:
5208
diff
changeset
|
248 |
// add callback for cleaning memory and removing alert |
fc755bb8096d
ios: caught some leaks, merged two methods inside a fuction, postponed the rating popup
koda
parents:
5208
diff
changeset
|
249 |
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (void *)alert); |
4935 | 250 |
} |
6076 | 251 |
*/ |
4935 | 252 |
|
3547 | 253 |
@end |