cocoaTouch/iPad/PopupMenuViewController.m
author palewolf
Sun, 28 Mar 2010 23:41:58 +0000
changeset 3151 3f23113d9df4
parent 3122 e005359efc59
child 3250 d5cd1a617123
permissions -rw-r--r--
AfterAttack was issued twice
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
3122
e005359efc59 hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents: 3116
diff changeset
     9
#import "SDL_uikitappdelegate.h"
3116
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    10
#import "PopupMenuViewController.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    11
#import "PascalImports.h"
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    12
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    13
@implementation PopupMenuViewController
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    14
@synthesize menuTable, menuList;
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
/*
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    17
 // 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
    18
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    19
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    20
        // Custom initialization
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    21
    }
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    22
    return self;
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
/*
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    27
// 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
    28
- (void)viewDidLoad {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    29
    [super viewDidLoad];
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    34
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    35
    // Overriden to allow any orientation.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    36
    return YES;
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    40
-(void) didReceiveMemoryWarning {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    41
    // Releases the view if it doesn't have a superview.
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    42
    [super didReceiveMemoryWarning];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    43
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    44
    // 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
    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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    48
-(void) viewDidLoad {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    49
    isPaused = NO;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    50
    menuTable.allowsSelection = YES;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    51
    menuList = [[NSArray alloc] initWithObjects:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    52
                NSLocalizedString(@"Pause Game", @""),
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    53
                NSLocalizedString(@"Chat", @""),
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    54
                NSLocalizedString(@"End Game", @""),
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    55
                nil];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    56
    [super viewDidLoad];
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    60
-(void) dealloc {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    61
    [menuList release];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    62
    [menuTable release];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    63
    [super dealloc];
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    66
#pragma mark -
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    67
#pragma mark TableView Methods
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    68
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    69
	return 1;
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    72
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    73
	return 3;
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    76
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    77
	static NSString *cellIdentifier = @"CellIdentifier";
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    78
	
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    79
	UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    80
    if (nil == cell) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    81
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    82
                                       reuseIdentifier:cellIdentifier] autorelease];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    83
        cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
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
	
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    86
	return cell;
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    89
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    90
    UIActionSheet *actionSheet;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    91
    
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    92
    switch ([indexPath row]) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    93
		case 0:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    94
            HW_pause();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    95
            isPaused = !isPaused;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    96
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    97
        case 1:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
    98
			HW_chat();
3122
e005359efc59 hide the background gl context that remains active (might be worth freeing ithide the background gl context that remains active (might be worth freeing it))
koda
parents: 3116
diff changeset
    99
            //SDL_iPhoneKeyboardShow([SDLUIKitDelegate sharedAppDelegate].window);
3116
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   100
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   101
        case 2:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   102
			actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   103
                                                      delegate:self
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   104
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   105
                                        destructiveButtonTitle:NSLocalizedString(@"As sure as I can be!", @"")
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   106
                                             otherButtonTitles:nil];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   107
            [actionSheet showInView:self.view];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   108
            [actionSheet release];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   109
            
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   110
            if (!isPaused) 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   111
                HW_pause();
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   112
            break;
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   113
        default:
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   114
			NSLog(@"Warning: unset case value in section!");
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   115
			break;
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
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   118
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   119
-(void) tableView:(UITableView *)aTableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   120
    [aTableView deselectRowAtIndexPath: indexPath animated:YES];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   121
}
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   122
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   123
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   124
	if ([actionSheet cancelButtonIndex] != buttonIndex) {
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   125
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover"  object:nil];
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   126
        HW_terminate(NO);
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   127
    }
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   128
	else
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   129
        if (!isPaused) 
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   130
            HW_pause();		
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
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   133
97dc65a47b15 branch ipad/iphone files to keep compatibility between versions
koda
parents:
diff changeset
   134
@end