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