project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
changeset 3647 0d0df215fb52
parent 3598 a8aa06bae895
child 3648 2477029463ed
equal deleted inserted replaced
3646:a3271158d93b 3647:0d0df215fb52
       
     1     //
       
     2 //  popupMenuViewController.m
       
     3 //  HedgewarsMobile
       
     4 //
       
     5 //  Created by Vittorio on 25/03/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "SDL_uikitappdelegate.h"
       
    10 #import "InGameMenuViewController.h"
       
    11 #import "PascalImports.h"
       
    12 #import "CommodityFunctions.h"
       
    13 #import "SDL_sysvideo.h"
       
    14 
       
    15 @implementation InGameMenuViewController
       
    16 @synthesize menuList;
       
    17 
       
    18 
       
    19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
       
    20     return rotationManager(interfaceOrientation);
       
    21 }
       
    22 
       
    23 -(void) didReceiveMemoryWarning {
       
    24     // Releases the view if it doesn't have a superview.
       
    25     [super didReceiveMemoryWarning];
       
    26 }
       
    27 
       
    28 -(void) viewDidLoad {
       
    29     isPaused = NO;
       
    30 
       
    31     NSArray *array = [[NSArray alloc] initWithObjects:
       
    32                       NSLocalizedString(@"Pause Game", @""),
       
    33                       NSLocalizedString(@"Chat", @""),
       
    34                       NSLocalizedString(@"End Game", @""),
       
    35                       nil];
       
    36     self.menuList = array;
       
    37     [array release];
       
    38     
       
    39     // save the sdl window (!= uikit window) for future reference
       
    40     SDL_VideoDevice *_this = SDL_GetVideoDevice();
       
    41     SDL_VideoDisplay *display = &_this->displays[0];
       
    42     sdlwindow = display->windows;
       
    43     
       
    44     [super viewDidLoad];
       
    45 }
       
    46 
       
    47 -(void) viewDidUnload {
       
    48     self.menuList = nil;
       
    49     [super viewDidUnload];
       
    50     MSG_DIDUNLOAD();
       
    51 }
       
    52 
       
    53 -(void) dealloc {
       
    54     [menuList release];
       
    55     [super dealloc];
       
    56 }
       
    57 
       
    58 #pragma mark -
       
    59 #pragma mark tableView methods
       
    60 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    61     return 1;
       
    62 }
       
    63 
       
    64 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    65     return 3;
       
    66 }
       
    67 
       
    68 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    69     static NSString *cellIdentifier = @"CellIdentifier";
       
    70     
       
    71     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
       
    72     if (nil == cell) {
       
    73         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
       
    74                                        reuseIdentifier:cellIdentifier] autorelease];
       
    75     }
       
    76     cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
       
    77     
       
    78     return cell;
       
    79 }
       
    80 
       
    81 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
    82     UIActionSheet *actionSheet;
       
    83     
       
    84     switch ([indexPath row]) {
       
    85         case 0:
       
    86             HW_pause();
       
    87             isPaused = !isPaused;
       
    88             break;
       
    89         case 1:
       
    90             HW_chat();
       
    91             SDL_iPhoneKeyboardShow(sdlwindow);
       
    92             break;
       
    93         case 2:
       
    94             // expand the view (and table) so that the actionsheet can be selected on the iPhone
       
    95             if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
       
    96                 [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
       
    97                 [UIView beginAnimations:@"table width more" context:NULL];
       
    98                 [UIView setAnimationDuration:0.2];
       
    99                 self.view.frame = CGRectMake(0, 0, 480, 320);
       
   100                 [UIView commitAnimations];
       
   101             }
       
   102             actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
       
   103                                                       delegate:self
       
   104                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
       
   105                                         destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
       
   106                                              otherButtonTitles:nil];
       
   107             [actionSheet showInView:self.view];
       
   108             [actionSheet release];
       
   109             
       
   110             if (!isPaused) 
       
   111                 HW_pause();
       
   112             break;
       
   113         default:
       
   114             NSLog(@"Warning: unset case value in section!");
       
   115             break;
       
   116     }
       
   117     
       
   118     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
       
   119 }
       
   120 
       
   121 #pragma mark -
       
   122 #pragma mark actionSheet methods
       
   123 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
       
   124     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
       
   125         [UIView beginAnimations:@"table width less" context:NULL];
       
   126         [UIView setAnimationDuration:0.2];
       
   127         self.view.frame = CGRectMake(280, 0, 200, 170);
       
   128         [UIView commitAnimations];
       
   129     }
       
   130     
       
   131     if ([actionSheet cancelButtonIndex] != buttonIndex)
       
   132         HW_terminate(NO);
       
   133     else
       
   134         if (!isPaused) 
       
   135             HW_pause();     
       
   136 }
       
   137 
       
   138 @end