project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
changeset 6268 d773867f93db
parent 6260 025d50a6aeb0
child 6269 57523ab57218
equal deleted inserted replaced
6267:be5d40bb1e86 6268:d773867f93db
    43 
    43 
    44 -(void) viewDidLoad {
    44 -(void) viewDidLoad {
    45     NSArray *array = [[NSArray alloc] initWithObjects:
    45     NSArray *array = [[NSArray alloc] initWithObjects:
    46                       NSLocalizedString(@"Show Help", @""),
    46                       NSLocalizedString(@"Show Help", @""),
    47                       NSLocalizedString(@"Tag", @""),
    47                       NSLocalizedString(@"Tag", @""),
    48 //                      NSLocalizedString(@"Snapshot",@""),
       
    49                       NSLocalizedString(@"End Game", @""),
    48                       NSLocalizedString(@"End Game", @""),
    50                       nil];
    49                       nil];
    51     self.menuList = array;
    50     self.menuList = array;
    52     [array release];
    51     [array release];
    53 
    52 
    87         [UIView commitAnimations];
    86         [UIView commitAnimations];
    88         [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
    87         [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
    89     }
    88     }
    90 
    89 
    91     SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
    90     SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
    92 
       
    93     /*
       
    94     if (shouldTakeScreenshot) {
       
    95         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please wait"
       
    96                                                         message:nil
       
    97                                                        delegate:nil
       
    98                                               cancelButtonTitle:nil
       
    99                                               otherButtonTitles:nil];
       
   100         [alert show];
       
   101         UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
       
   102                                               initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
   103         indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 45);
       
   104         [indicator startAnimating];
       
   105         [alert addSubview:indicator];
       
   106         [indicator release];
       
   107 
       
   108         // all these hacks because of the PAUSE caption on top of everything...
       
   109         [self performSelector:@selector(saveCurrentScreenToPhotoAlbum:) withObject:alert afterDelay:0.3];
       
   110     }
       
   111     */
       
   112     shouldTakeScreenshot = NO;
       
   113 }
    91 }
   114 
    92 
   115 #pragma mark -
    93 #pragma mark -
   116 #pragma mark tableView methods
    94 #pragma mark tableView methods
   117 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    95 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
   118     return 1;
    96     return 1;
   119 }
    97 }
   120 
    98 
   121 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    99 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   122     return 3;
   100     return 3;
   123 //    return 4;
       
   124 }
   101 }
   125 
   102 
   126 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   103 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   127     static NSString *cellIdentifier = @"CellIdentifier";
   104     static NSString *cellIdentifier = @"CellIdentifier";
   128 
   105 
   139     return cell;
   116     return cell;
   140 }
   117 }
   141 
   118 
   142 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   119 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   143     UIActionSheet *actionSheet;
   120     UIActionSheet *actionSheet;
   144 //    UIAlertView *alert;
       
   145 
   121 
   146     switch ([indexPath row]) {
   122     switch ([indexPath row]) {
   147         case 0:
   123         case 0:
   148             [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
   124             [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
   149 
   125 
   152             HW_chat();
   128             HW_chat();
   153             SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow());
   129             SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow());
   154 
   130 
   155             break;
   131             break;
   156         case 2:
   132         case 2:
   157 /*
       
   158             alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Going to take a screenshot",@"")
       
   159                                                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",@"")
       
   160                                               delegate:nil
       
   161                                      cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
       
   162                                      otherButtonTitles:nil];
       
   163             [alert show];
       
   164             [alert release];
       
   165             shouldTakeScreenshot = YES;
       
   166 
       
   167             break;
       
   168         case 3:
       
   169 */
       
   170             actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
   133             actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
   171                                                       delegate:self
   134                                                       delegate:self
   172                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
   135                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
   173                                         destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
   136                                         destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
   174                                              otherButtonTitles:nil];
   137                                              otherButtonTitles:nil];
   191         SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
   154         SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
   192         HW_terminate(NO);
   155         HW_terminate(NO);
   193     }
   156     }
   194 }
   157 }
   195 
   158 
   196 //TODO: check this is still needed since we switched to SDL_GL_CreateContext()
       
   197 /*
       
   198 #pragma mark -
       
   199 #pragma mark save screenshot
       
   200 //by http://www.bit-101.com/blog/?p=1861
       
   201 // callback for CGDataProviderCreateWithData
       
   202 void releaseData(void *info, const void *data, size_t dataSize) {
       
   203     DLog(@"freeing raw data\n");
       
   204     free((void *)data);
       
   205 }
       
   206 
       
   207 // callback for UIImageWriteToSavedPhotosAlbum
       
   208 -(void) image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
       
   209     DLog(@"Save finished\n");
       
   210     [image release];
       
   211     UIAlertView *alert = (UIAlertView *)contextInfo;
       
   212     [alert dismissWithClickedButtonIndex:0 animated:YES];
       
   213     [alert release];
       
   214 }
       
   215 
       
   216 // the resolution of the buffer is always equal to the hardware device even if scaled
       
   217 -(void) saveCurrentScreenToPhotoAlbum:(UIAlertView *)alert {
       
   218     CGRect screenRect = [[UIScreen mainScreen] bounds];
       
   219     int width = screenRect.size.width;
       
   220     int height = screenRect.size.height;
       
   221 
       
   222     NSInteger size = width * height * 4;
       
   223     GLubyte *buffer = (GLubyte *) malloc(size * sizeof(GLubyte));
       
   224     GLubyte *buffer_flipped = (GLubyte *) malloc(size * sizeof(GLubyte));
       
   225 
       
   226     glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
       
   227     HW_screenshot();
       
   228     // flip the data as glReadPixels here reads upside down
       
   229     for(int y = 0; y <height; y++)
       
   230         for(int x = 0; x <width * 4; x++)
       
   231             buffer_flipped[(int)((height - 1 - y) * width * 4 + x)] = buffer[(int)(y * 4 * width + x)];
       
   232     free(buffer);
       
   233 
       
   234     CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer_flipped, size, releaseData);
       
   235     CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
       
   236     CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
       
   237     CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
       
   238     CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
       
   239 
       
   240     CGColorSpaceRelease(colorSpaceRef);
       
   241     CGDataProviderRelease(provider);
       
   242 
       
   243     UIImage *image;
       
   244     if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
       
   245         image = [[UIImage alloc] initWithCGImage:imageRef scale:1 orientation:UIImageOrientationRight];
       
   246     else
       
   247         image = [[UIImage alloc] initWithCGImage:imageRef];
       
   248     CGImageRelease(imageRef);
       
   249 
       
   250     // add callback for cleaning memory and removing alert
       
   251     UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (void *)alert);
       
   252 }
       
   253 */
       
   254 
       
   255 @end
   159 @end