cocoaTouch/PopoverMenuViewController.m
author palewolf
Sat, 17 Apr 2010 23:03:52 +0000
changeset 3355 dc9e61e67484
parent 3340 96dd168b080b
child 3357 3836a31879e7
permissions -rw-r--r--
cWindSpeed recalculation assumed GetRandom returns a value between 0.0-1.0 while in fact is in the 0.0-0.5 range; Halve cMaxWindSpeed to compensate.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     1
    //
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     2
//  popupMenuViewController.m
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     3
//  HedgewarsMobile
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     4
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     5
//  Created by Vittorio on 25/03/10.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     7
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     8
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     9
#import "SDL_uikitappdelegate.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
#import "PopoverMenuViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
#import "PascalImports.h"
3340
96dd168b080b fix all of what was committed before
koda
parents: 3335
diff changeset
    12
#import "CommodityFunctions.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
@implementation PopoverMenuViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
@synthesize menuList;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3308
diff changeset
    18
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3308
diff changeset
    19
	return rotationManager(interfaceOrientation);
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3308
diff changeset
    22
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
    [super didReceiveMemoryWarning];
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    26
    self.menuList = nil;
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
-(void) viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
    isPaused = NO;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
    self.tableView.allowsSelection = YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    self.tableView.alwaysBounceVertical = YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
    self.tableView.delaysContentTouches = NO;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
    menuList = [[NSArray alloc] initWithObjects:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
                NSLocalizedString(@"Pause Game", @""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
                NSLocalizedString(@"Chat", @""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
                NSLocalizedString(@"End Game", @""),
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
                nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
-(void) dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
    [menuList release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
#pragma mark tableView methods
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
	return 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
	return 3;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
	static NSString *cellIdentifier = @"CellIdentifier";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
	
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
	UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
    if (nil == cell) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
                                       reuseIdentifier:cellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
	}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
	
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
	return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
    UIActionSheet *actionSheet;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
    switch ([indexPath row]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
		case 0:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
            HW_pause();
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
            isPaused = !isPaused;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
        case 1:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
			HW_chat();
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
            //SDL_iPhoneKeyboardShow([SDLUIKitDelegate sharedAppDelegate].window);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
        case 2:
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    84
            // expand the view (and table) so that the actionsheet can be selected on the iPhone
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    85
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    86
                [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    87
                [UIView beginAnimations:@"table width more" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    88
                [UIView setAnimationDuration:0.2];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    89
                self.view.frame = CGRectMake(0, 0, 480, 320);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    90
                [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    91
            }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
			actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
                                                      delegate:self
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
                                             otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
            [actionSheet showInView:self.view];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
            [actionSheet release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
            
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
            if (!isPaused) 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
                HW_pause();
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
			NSLog(@"Warning: unset case value in section!");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
			break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
#pragma mark actionSheet methods
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   114
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   115
        [UIView beginAnimations:@"table width less" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   116
        [UIView setAnimationDuration:0.2];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   117
        self.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   118
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   119
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   120
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
	if ([actionSheet cancelButtonIndex] != buttonIndex) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
        HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
        if (!isPaused) 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
            HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
@end