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