cocoaTouch/popupMenuViewController.m
author koda
Sat, 27 Mar 2010 00:03:25 +0000
changeset 3091 9d05c8000ed4
parent 3090 51629e69da51
child 3113 2829ea0dd47c
permissions -rw-r--r--
some code polish for the ifrontend inu patch for translation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
     1
    //
51629e69da51 restore compilation
koda
parents:
diff changeset
     2
//  popupMenuViewController.m
51629e69da51 restore compilation
koda
parents:
diff changeset
     3
//  HedgewarsMobile
51629e69da51 restore compilation
koda
parents:
diff changeset
     4
//
51629e69da51 restore compilation
koda
parents:
diff changeset
     5
//  Created by Vittorio on 25/03/10.
51629e69da51 restore compilation
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
51629e69da51 restore compilation
koda
parents:
diff changeset
     7
//
51629e69da51 restore compilation
koda
parents:
diff changeset
     8
51629e69da51 restore compilation
koda
parents:
diff changeset
     9
#import "popupMenuViewController.h"
51629e69da51 restore compilation
koda
parents:
diff changeset
    10
#import "PascalImports.h"
51629e69da51 restore compilation
koda
parents:
diff changeset
    11
51629e69da51 restore compilation
koda
parents:
diff changeset
    12
@implementation popupMenuViewController
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    13
@synthesize menuTable, menuList;
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    14
51629e69da51 restore compilation
koda
parents:
diff changeset
    15
/*
51629e69da51 restore compilation
koda
parents:
diff changeset
    16
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
51629e69da51 restore compilation
koda
parents:
diff changeset
    17
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
51629e69da51 restore compilation
koda
parents:
diff changeset
    18
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
51629e69da51 restore compilation
koda
parents:
diff changeset
    19
        // Custom initialization
51629e69da51 restore compilation
koda
parents:
diff changeset
    20
    }
51629e69da51 restore compilation
koda
parents:
diff changeset
    21
    return self;
51629e69da51 restore compilation
koda
parents:
diff changeset
    22
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    23
*/
51629e69da51 restore compilation
koda
parents:
diff changeset
    24
51629e69da51 restore compilation
koda
parents:
diff changeset
    25
/*
51629e69da51 restore compilation
koda
parents:
diff changeset
    26
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
51629e69da51 restore compilation
koda
parents:
diff changeset
    27
- (void)viewDidLoad {
51629e69da51 restore compilation
koda
parents:
diff changeset
    28
    [super viewDidLoad];
51629e69da51 restore compilation
koda
parents:
diff changeset
    29
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    30
*/
51629e69da51 restore compilation
koda
parents:
diff changeset
    31
51629e69da51 restore compilation
koda
parents:
diff changeset
    32
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    33
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    34
    // Overriden to allow any orientation.
51629e69da51 restore compilation
koda
parents:
diff changeset
    35
    return YES;
51629e69da51 restore compilation
koda
parents:
diff changeset
    36
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    37
51629e69da51 restore compilation
koda
parents:
diff changeset
    38
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    39
-(void) didReceiveMemoryWarning {
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    40
    // Releases the view if it doesn't have a superview.
51629e69da51 restore compilation
koda
parents:
diff changeset
    41
    [super didReceiveMemoryWarning];
51629e69da51 restore compilation
koda
parents:
diff changeset
    42
    
51629e69da51 restore compilation
koda
parents:
diff changeset
    43
    // Release any cached data, images, etc that aren't in use.
51629e69da51 restore compilation
koda
parents:
diff changeset
    44
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    45
51629e69da51 restore compilation
koda
parents:
diff changeset
    46
51629e69da51 restore compilation
koda
parents:
diff changeset
    47
-(void) viewDidLoad {
51629e69da51 restore compilation
koda
parents:
diff changeset
    48
    isPaused = NO;
51629e69da51 restore compilation
koda
parents:
diff changeset
    49
    menuTable.allowsSelection = YES;
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    50
    menuList = [[NSArray alloc] initWithObjects:NSLocalizedString(@"Pause Game", @""), NSLocalizedString(@"Chat", @""), NSLocalizedString(@"End Game", @""),nil];
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    51
    [super viewDidLoad];
51629e69da51 restore compilation
koda
parents:
diff changeset
    52
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    53
51629e69da51 restore compilation
koda
parents:
diff changeset
    54
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    55
-(void) dealloc {
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    56
    [menuList release];
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    57
    [menuTable release];
51629e69da51 restore compilation
koda
parents:
diff changeset
    58
    [super dealloc];
51629e69da51 restore compilation
koda
parents:
diff changeset
    59
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    60
51629e69da51 restore compilation
koda
parents:
diff changeset
    61
#pragma mark -
51629e69da51 restore compilation
koda
parents:
diff changeset
    62
#pragma mark TableView Methods
51629e69da51 restore compilation
koda
parents:
diff changeset
    63
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
51629e69da51 restore compilation
koda
parents:
diff changeset
    64
	return 1;
51629e69da51 restore compilation
koda
parents:
diff changeset
    65
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    66
51629e69da51 restore compilation
koda
parents:
diff changeset
    67
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
51629e69da51 restore compilation
koda
parents:
diff changeset
    68
	return 3;
51629e69da51 restore compilation
koda
parents:
diff changeset
    69
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    70
51629e69da51 restore compilation
koda
parents:
diff changeset
    71
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
51629e69da51 restore compilation
koda
parents:
diff changeset
    72
	static NSString *cellIdentifier = @"CellIdentifier";
51629e69da51 restore compilation
koda
parents:
diff changeset
    73
	
51629e69da51 restore compilation
koda
parents:
diff changeset
    74
	UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
51629e69da51 restore compilation
koda
parents:
diff changeset
    75
    if (nil == cell) {
51629e69da51 restore compilation
koda
parents:
diff changeset
    76
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
51629e69da51 restore compilation
koda
parents:
diff changeset
    77
                                       reuseIdentifier:cellIdentifier] autorelease];
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    78
        cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    79
	}
51629e69da51 restore compilation
koda
parents:
diff changeset
    80
	
51629e69da51 restore compilation
koda
parents:
diff changeset
    81
	return cell;
51629e69da51 restore compilation
koda
parents:
diff changeset
    82
}
51629e69da51 restore compilation
koda
parents:
diff changeset
    83
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
    84
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
    85
    UIActionSheet *actionSheet;
51629e69da51 restore compilation
koda
parents:
diff changeset
    86
    
51629e69da51 restore compilation
koda
parents:
diff changeset
    87
    switch ([indexPath row]) {
51629e69da51 restore compilation
koda
parents:
diff changeset
    88
		case 0:
51629e69da51 restore compilation
koda
parents:
diff changeset
    89
            HW_pause();
51629e69da51 restore compilation
koda
parents:
diff changeset
    90
            isPaused = !isPaused;
51629e69da51 restore compilation
koda
parents:
diff changeset
    91
            break;
51629e69da51 restore compilation
koda
parents:
diff changeset
    92
        case 1:
51629e69da51 restore compilation
koda
parents:
diff changeset
    93
			HW_chat();
51629e69da51 restore compilation
koda
parents:
diff changeset
    94
            break;
51629e69da51 restore compilation
koda
parents:
diff changeset
    95
        case 2:
51629e69da51 restore compilation
koda
parents:
diff changeset
    96
			actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
51629e69da51 restore compilation
koda
parents:
diff changeset
    97
                                                      delegate:self
51629e69da51 restore compilation
koda
parents:
diff changeset
    98
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
51629e69da51 restore compilation
koda
parents:
diff changeset
    99
                                        destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
51629e69da51 restore compilation
koda
parents:
diff changeset
   100
                                             otherButtonTitles:nil];
51629e69da51 restore compilation
koda
parents:
diff changeset
   101
            [actionSheet showInView:self.view];
51629e69da51 restore compilation
koda
parents:
diff changeset
   102
            [actionSheet release];
51629e69da51 restore compilation
koda
parents:
diff changeset
   103
            
51629e69da51 restore compilation
koda
parents:
diff changeset
   104
            if (!isPaused) 
51629e69da51 restore compilation
koda
parents:
diff changeset
   105
                HW_pause();
51629e69da51 restore compilation
koda
parents:
diff changeset
   106
            break;
51629e69da51 restore compilation
koda
parents:
diff changeset
   107
        default:
51629e69da51 restore compilation
koda
parents:
diff changeset
   108
			NSLog(@"Warning: unset case value in section!");
51629e69da51 restore compilation
koda
parents:
diff changeset
   109
			break;
51629e69da51 restore compilation
koda
parents:
diff changeset
   110
    }
51629e69da51 restore compilation
koda
parents:
diff changeset
   111
}
51629e69da51 restore compilation
koda
parents:
diff changeset
   112
3091
9d05c8000ed4 some code polish for the ifrontend
koda
parents: 3090
diff changeset
   113
-(void) tableView:(UITableView *)aTableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
3090
51629e69da51 restore compilation
koda
parents:
diff changeset
   114
    [aTableView deselectRowAtIndexPath: indexPath animated:YES];
51629e69da51 restore compilation
koda
parents:
diff changeset
   115
}
51629e69da51 restore compilation
koda
parents:
diff changeset
   116
51629e69da51 restore compilation
koda
parents:
diff changeset
   117
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
51629e69da51 restore compilation
koda
parents:
diff changeset
   118
	if ([actionSheet cancelButtonIndex] != buttonIndex)
51629e69da51 restore compilation
koda
parents:
diff changeset
   119
	    HW_terminate(NO);
51629e69da51 restore compilation
koda
parents:
diff changeset
   120
	else
51629e69da51 restore compilation
koda
parents:
diff changeset
   121
        if (!isPaused) 
51629e69da51 restore compilation
koda
parents:
diff changeset
   122
            HW_pause();		
51629e69da51 restore compilation
koda
parents:
diff changeset
   123
}
51629e69da51 restore compilation
koda
parents:
diff changeset
   124
51629e69da51 restore compilation
koda
parents:
diff changeset
   125
51629e69da51 restore compilation
koda
parents:
diff changeset
   126
@end