project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
changeset 3697 d5b30d6373fc
parent 3668 3f7a95234d8a
child 3701 8c449776ebe6
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    31                       NSLocalizedString(@"Chat", @""),
    31                       NSLocalizedString(@"Chat", @""),
    32                       NSLocalizedString(@"End Game", @""),
    32                       NSLocalizedString(@"End Game", @""),
    33                       nil];
    33                       nil];
    34     self.menuList = array;
    34     self.menuList = array;
    35     [array release];
    35     [array release];
    36     
    36 
    37     // save the sdl window (!= uikit window) for future reference
    37     // save the sdl window (!= uikit window) for future reference
    38     SDL_VideoDevice *_this = SDL_GetVideoDevice();
    38     SDL_VideoDevice *_this = SDL_GetVideoDevice();
    39     SDL_VideoDisplay *display = &_this->displays[0];
    39     SDL_VideoDisplay *display = &_this->displays[0];
    40     sdlwindow = display->windows;
    40     sdlwindow = display->windows;
    41         
    41 
    42     [super viewDidLoad];
    42     [super viewDidLoad];
    43 }
    43 }
    44 
    44 
    45 -(void) viewDidUnload {
    45 -(void) viewDidUnload {
    46     self.menuList = nil;
    46     self.menuList = nil;
    57 #pragma mark animating
    57 #pragma mark animating
    58 -(void) present {
    58 -(void) present {
    59     CGRect screen = [[UIScreen mainScreen] bounds];
    59     CGRect screen = [[UIScreen mainScreen] bounds];
    60     self.view.backgroundColor = [UIColor clearColor];
    60     self.view.backgroundColor = [UIColor clearColor];
    61     self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
    61     self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
    62     
    62 
    63     [UIView beginAnimations:@"showing popover" context:NULL];
    63     [UIView beginAnimations:@"showing popover" context:NULL];
    64     [UIView setAnimationDuration:0.35];
    64     [UIView setAnimationDuration:0.35];
    65     self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
    65     self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
    66     [UIView commitAnimations];
    66     [UIView commitAnimations];
    67 }
    67 }
    70     CGRect screen = [[UIScreen mainScreen] bounds];
    70     CGRect screen = [[UIScreen mainScreen] bounds];
    71     [UIView beginAnimations:@"hiding popover" context:NULL];
    71     [UIView beginAnimations:@"hiding popover" context:NULL];
    72     [UIView setAnimationDuration:0.35];
    72     [UIView setAnimationDuration:0.35];
    73     self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
    73     self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
    74     [UIView commitAnimations];
    74     [UIView commitAnimations];
    75         
    75 
    76     [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
    76     [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
    77     
    77 
    78     [self removeChat];
    78     [self removeChat];
    79 }
    79 }
    80 
    80 
    81 #pragma mark -
    81 #pragma mark -
    82 #pragma mark tableView methods
    82 #pragma mark tableView methods
    88     return 3;
    88     return 3;
    89 }
    89 }
    90 
    90 
    91 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    91 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    92     static NSString *cellIdentifier = @"CellIdentifier";
    92     static NSString *cellIdentifier = @"CellIdentifier";
    93     
    93 
    94     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    94     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    95     if (nil == cell) {
    95     if (nil == cell) {
    96         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
    96         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
    97                                        reuseIdentifier:cellIdentifier] autorelease];
    97                                        reuseIdentifier:cellIdentifier] autorelease];
    98     }
    98     }
    99     cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
    99     cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
   100     
   100 
   101     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   101     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   102         cell.textLabel.textAlignment = UITextAlignmentCenter;
   102         cell.textLabel.textAlignment = UITextAlignmentCenter;
   103     
   103 
   104     return cell;
   104     return cell;
   105 }
   105 }
   106 
   106 
   107 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   107 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   108     UIActionSheet *actionSheet;
   108     UIActionSheet *actionSheet;
   109     
   109 
   110     switch ([indexPath row]) {
   110     switch ([indexPath row]) {
   111         case 0:
   111         case 0:
   112             HW_pause();
   112             HW_pause();
   113             break;
   113             break;
   114         case 1:
   114         case 1:
   134                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
   134                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
   135                                         destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
   135                                         destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
   136                                              otherButtonTitles:nil];
   136                                              otherButtonTitles:nil];
   137             [actionSheet showInView:self.view];
   137             [actionSheet showInView:self.view];
   138             [actionSheet release];
   138             [actionSheet release];
   139             
   139 
   140             break;
   140             break;
   141         default:
   141         default:
   142             DLog(@"Warning: unset case value in section!");
   142             DLog(@"Warning: unset case value in section!");
   143             break;
   143             break;
   144     }
   144     }
   145     
   145 
   146     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   146     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   147 }
   147 }
   148 
   148 
   149 -(void) removeChat {
   149 -(void) removeChat {
   150     if (SDL_iPhoneKeyboardIsShown(sdlwindow)) {
   150     if (SDL_iPhoneKeyboardIsShown(sdlwindow)) {
   161         [UIView beginAnimations:@"table width less" context:NULL];
   161         [UIView beginAnimations:@"table width less" context:NULL];
   162         [UIView setAnimationDuration:0.2];
   162         [UIView setAnimationDuration:0.2];
   163         self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
   163         self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
   164         [UIView commitAnimations];
   164         [UIView commitAnimations];
   165     }
   165     }
   166     
   166 
   167     if ([actionSheet cancelButtonIndex] != buttonIndex)
   167     if ([actionSheet cancelButtonIndex] != buttonIndex)
   168         HW_terminate(NO);     
   168         HW_terminate(NO);
   169 }
   169 }
   170 
   170 
   171 @end
   171 @end