cocoaTouch/popupMenuViewController.m
changeset 3116 97dc65a47b15
parent 3115 831bd0f7050d
child 3117 f3e363a9b7db
equal deleted inserted replaced
3115:831bd0f7050d 3116:97dc65a47b15
     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 "popupMenuViewController.h"
       
    10 #import "PascalImports.h"
       
    11 
       
    12 @implementation popupMenuViewController
       
    13 @synthesize menuTable, menuList;
       
    14 
       
    15 /*
       
    16  // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
       
    17 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
       
    18     if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
       
    19         // Custom initialization
       
    20     }
       
    21     return self;
       
    22 }
       
    23 */
       
    24 
       
    25 /*
       
    26 // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
       
    27 - (void)viewDidLoad {
       
    28     [super viewDidLoad];
       
    29 }
       
    30 */
       
    31 
       
    32 
       
    33 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    34     // Overriden to allow any orientation.
       
    35     return YES;
       
    36 }
       
    37 
       
    38 
       
    39 -(void) didReceiveMemoryWarning {
       
    40     // Releases the view if it doesn't have a superview.
       
    41     [super didReceiveMemoryWarning];
       
    42     
       
    43     // Release any cached data, images, etc that aren't in use.
       
    44 }
       
    45 
       
    46 
       
    47 -(void) viewDidLoad {
       
    48     isPaused = NO;
       
    49     menuTable.allowsSelection = YES;
       
    50     menuList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"Pause Game", @""), NSLocalizedString(@"Chat", @""), NSLocalizedString(@"End Game", @""),nil];
       
    51     [super viewDidLoad];
       
    52 }
       
    53 
       
    54 
       
    55 -(void) dealloc {
       
    56     [menuList release];
       
    57     [menuTable release];
       
    58     [super dealloc];
       
    59 }
       
    60 
       
    61 #pragma mark -
       
    62 #pragma mark TableView Methods
       
    63 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    64 	return 1;
       
    65 }
       
    66 
       
    67 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    68 	return 3;
       
    69 }
       
    70 
       
    71 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    72 	static NSString *cellIdentifier = @"CellIdentifier";
       
    73 	
       
    74 	UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
       
    75     if (nil == cell) {
       
    76 		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
       
    77                                        reuseIdentifier:cellIdentifier] autorelease];
       
    78         cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
       
    79 	}
       
    80 	
       
    81 	return cell;
       
    82 }
       
    83 
       
    84 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
    85     UIActionSheet *actionSheet;
       
    86     
       
    87     switch ([indexPath row]) {
       
    88 		case 0:
       
    89             HW_pause();
       
    90             isPaused = !isPaused;
       
    91             break;
       
    92         case 1:
       
    93 			HW_chat();
       
    94             break;
       
    95         case 2:
       
    96 			actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
       
    97                                                       delegate:self
       
    98                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
       
    99                                         destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
       
   100                                              otherButtonTitles:nil];
       
   101             [actionSheet showInView:self.view];
       
   102             [actionSheet release];
       
   103             
       
   104             if (!isPaused) 
       
   105                 HW_pause();
       
   106             break;
       
   107         default:
       
   108 			NSLog(@"Warning: unset case value in section!");
       
   109 			break;
       
   110     }
       
   111 }
       
   112 
       
   113 -(void) tableView:(UITableView *)aTableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
       
   114     [aTableView deselectRowAtIndexPath: indexPath animated:YES];
       
   115 }
       
   116 
       
   117 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
       
   118 	if ([actionSheet cancelButtonIndex] != buttonIndex) {
       
   119         [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover"  object:nil];
       
   120         HW_terminate(NO);
       
   121     }
       
   122 	else
       
   123         if (!isPaused) 
       
   124             HW_pause();		
       
   125 }
       
   126 
       
   127 
       
   128 @end