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