cocoaTouch/popupMenuViewController.m
changeset 3090 51629e69da51
child 3091 9d05c8000ed4
equal deleted inserted replaced
3089:8ad00781be08 3090:51629e69da51
       
     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;
       
    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     [super viewDidLoad];
       
    51 }
       
    52 
       
    53 
       
    54 - (void)dealloc {
       
    55     [menuTable release];
       
    56     [super dealloc];
       
    57 }
       
    58 
       
    59 #pragma mark -
       
    60 #pragma mark TableView Methods
       
    61 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
    62 	return 1;
       
    63 }
       
    64 
       
    65 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
       
    66 	return 3;
       
    67 }
       
    68 
       
    69 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
    70 	static NSString *cellIdentifier = @"CellIdentifier";
       
    71 	
       
    72 	UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
       
    73     if (nil == cell) {
       
    74 		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
       
    75                                        reuseIdentifier:cellIdentifier] autorelease];
       
    76 	}
       
    77 	
       
    78 	switch ([indexPath row]) {
       
    79 		case 0:
       
    80             cell.textLabel.text = NSLocalizedString(@"Pause Game", @"");
       
    81             //cell.accessoryView = username;
       
    82             break;
       
    83         case 1:
       
    84 			cell.textLabel.text = NSLocalizedString(@"Chat", @"");
       
    85             //cell.accessoryView = password;
       
    86             break;
       
    87         case 2:
       
    88 			cell.textLabel.text = NSLocalizedString(@"End Game", @"");
       
    89             break;
       
    90         default:
       
    91 			NSLog(@"Warning: unset case value in kNetworkFields section!");
       
    92 			break;
       
    93     }
       
    94 	
       
    95 	return cell;
       
    96 }
       
    97 
       
    98 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
    99     UIActionSheet *actionSheet;
       
   100     
       
   101     switch ([indexPath row]) {
       
   102 		case 0:
       
   103             HW_pause();
       
   104             isPaused = !isPaused;
       
   105             break;
       
   106         case 1:
       
   107 			HW_chat();
       
   108             break;
       
   109         case 2:
       
   110 			actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
       
   111                                                       delegate:self
       
   112                                              cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
       
   113                                         destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
       
   114                                              otherButtonTitles:nil];
       
   115             [actionSheet showInView:self.view];
       
   116             [actionSheet release];
       
   117             
       
   118             if (!isPaused) 
       
   119                 HW_pause();
       
   120             break;
       
   121         default:
       
   122 			NSLog(@"Warning: unset case value in section!");
       
   123 			break;
       
   124     }
       
   125 }
       
   126 
       
   127 - (void)tableView:(UITableView *)aTableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
       
   128     [aTableView deselectRowAtIndexPath: indexPath animated:YES];
       
   129 }
       
   130 
       
   131 -(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
       
   132 	if ([actionSheet cancelButtonIndex] != buttonIndex)
       
   133 	    HW_terminate(NO);
       
   134 	else
       
   135         if (!isPaused) 
       
   136             HW_pause();		
       
   137 }
       
   138 
       
   139 
       
   140 @end