project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
changeset 4920 bc3c077e15a2
parent 4912 862b134284b2
child 4924 616b618814b5
equal deleted inserted replaced
4918:c6d3aec73f93 4920:bc3c077e15a2
    46                       NSLocalizedString(@"End Game", @""),
    46                       NSLocalizedString(@"End Game", @""),
    47                       nil];
    47                       nil];
    48     self.menuList = array;
    48     self.menuList = array;
    49     [array release];
    49     [array release];
    50 
    50 
    51     // save the sdl window (!= uikit window) for future reference
       
    52     SDL_VideoDevice *videoDevice = SDL_GetVideoDevice();
       
    53     if (videoDevice) {
       
    54         SDL_VideoDisplay *display = &videoDevice->displays[0];
       
    55         if (display)
       
    56             sdlwindow = display->windows;
       
    57     }
       
    58     [super viewDidLoad];
    51     [super viewDidLoad];
    59 }
       
    60 
       
    61 -(void) viewWillAppear:(BOOL)animated {
       
    62     if (sdlwindow == NULL) {
       
    63         SDL_VideoDevice *_this = SDL_GetVideoDevice();
       
    64         if (_this) {
       
    65             SDL_VideoDisplay *display = &_this->displays[0];
       
    66             if (display)
       
    67                 sdlwindow = display->windows;
       
    68         }
       
    69     }
       
    70     [super viewWillAppear:animated];
       
    71 }
    52 }
    72 
    53 
    73 -(void) viewDidUnload {
    54 -(void) viewDidUnload {
    74     self.menuList = nil;
    55     self.menuList = nil;
    75     sdlwindow = NULL;
       
    76     MSG_DIDUNLOAD();
    56     MSG_DIDUNLOAD();
    77     [super viewDidUnload];
    57     [super viewDidUnload];
    78 }
    58 }
    79 
    59 
    80 -(void) dealloc {
    60 -(void) dealloc {
   104         [UIView commitAnimations];
    84         [UIView commitAnimations];
   105     }
    85     }
   106 
    86 
   107     [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
    87     [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
   108 
    88 
   109     [self removeChat];
    89     HW_chatEnd();
       
    90     SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
   110 }
    91 }
   111 
    92 
   112 #pragma mark -
    93 #pragma mark -
   113 #pragma mark tableView methods
    94 #pragma mark tableView methods
   114 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    95 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
   125     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
   106     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
   126     if (nil == cell) {
   107     if (nil == cell) {
   127         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
   108         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
   128                                        reuseIdentifier:cellIdentifier] autorelease];
   109                                        reuseIdentifier:cellIdentifier] autorelease];
   129     }
   110     }
   130     cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
   111     cell.textLabel.text = [self.menuList objectAtIndex:[indexPath row]];
   131 
   112 
   132     if (IS_IPAD())
   113     if (IS_IPAD())
   133         cell.textLabel.textAlignment = UITextAlignmentCenter;
   114         cell.textLabel.textAlignment = UITextAlignmentCenter;
   134 
   115 
   135     return cell;
   116     return cell;
   141     switch ([indexPath row]) {
   122     switch ([indexPath row]) {
   142         case 0:
   123         case 0:
   143             [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
   124             [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
   144             break;
   125             break;
   145         case 1:
   126         case 1:
   146             if (SDL_iPhoneKeyboardIsShown(sdlwindow))
   127             HW_chat();
   147                 [self removeChat];
   128             SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow());
   148             else {
       
   149                 HW_chat();
       
   150                 SDL_iPhoneKeyboardShow(sdlwindow);
       
   151             }
       
   152             break;
   129             break;
   153         case 2:
   130         case 2:
   154             // expand the view (and table) so that the actionsheet can be selected on the iPhone
   131             // expand the view (and table) so that the actionsheet can be selected on the iPhone
   155             if (IS_IPAD() == NO) {
   132             if (IS_IPAD() == NO) {
   156                 CGRect screen = [[UIScreen mainScreen] bounds];
   133                 CGRect screen = [[UIScreen mainScreen] bounds];
   175     }
   152     }
   176 
   153 
   177     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   154     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   178 }
   155 }
   179 
   156 
   180 -(void) removeChat {
       
   181     if (SDL_iPhoneKeyboardIsShown(sdlwindow)) {
       
   182         SDL_iPhoneKeyboardHide(sdlwindow);
       
   183         HW_chatEnd();
       
   184     }
       
   185 }
       
   186 
       
   187 #pragma mark -
   157 #pragma mark -
   188 #pragma mark actionSheet methods
   158 #pragma mark actionSheet methods
   189 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
   159 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
   190     if (IS_IPAD() == NO) {
   160     if (IS_IPAD() == NO) {
   191         CGRect screen = [[UIScreen mainScreen] bounds];
   161         CGRect screen = [[UIScreen mainScreen] bounds];