project_files/HedgewarsMobile/Classes/PopoverMenuViewController.m
author koda
Wed, 23 Jun 2010 01:00:52 +0200
changeset 3535 9e78c1f3d8d8
parent 3514 59dbd31e9953
child 3546 ccf4854df294
permissions -rw-r--r--
update the project to ios4 by removing pre-3.2 references add missing lowres image other smaller fixes
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"
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    13
#import "SDL_sysvideo.h"
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
@implementation PopoverMenuViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
@synthesize menuList;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3308
diff changeset
    19
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3308
diff changeset
    20
	return rotationManager(interfaceOrientation);
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3308
diff changeset
    23
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
-(void) didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
    [super didReceiveMemoryWarning];
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;
3357
3836a31879e7 draw a hedgehog when presenting hats
koda
parents: 3340
diff changeset
    31
3535
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    32
    NSArray *array = [[NSArray alloc] initWithObjects:
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    33
                      NSLocalizedString(@"Pause Game", @""),
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    34
                      NSLocalizedString(@"Chat", @""),
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    35
                      NSLocalizedString(@"End Game", @""),
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    36
                      nil];
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    37
    self.menuList = array;
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    38
    [array release];
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    39
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
    [super viewDidLoad];
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
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3463
diff changeset
    43
-(void) viewDidUnload {
3535
9e78c1f3d8d8 update the project to ios4 by removing pre-3.2 references
koda
parents: 3514
diff changeset
    44
    self.menuList = nil;
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3463
diff changeset
    45
    [super viewDidUnload];
016b3172b645 a bunch of minor stuff
koda
parents: 3463
diff changeset
    46
    MSG_DIDUNLOAD();
016b3172b645 a bunch of minor stuff
koda
parents: 3463
diff changeset
    47
}
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
-(void) dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
    [menuList release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
    [super dealloc];
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
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
#pragma mark tableView methods
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
	return 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
	return 3;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
	static NSString *cellIdentifier = @"CellIdentifier";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
	
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
	UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
    if (nil == cell) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
                                       reuseIdentifier:cellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
	}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
    cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
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
	return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
    UIActionSheet *actionSheet;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
    switch ([indexPath row]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
		case 0:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
            HW_pause();
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
            isPaused = !isPaused;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
        case 1:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
			HW_chat();
3463
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    87
            /*
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    88
            SDL_VideoDevice *_this = SDL_GetVideoDevice();
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    89
            SDL_VideoDisplay *display = &_this->displays[0];
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    90
            SDL_Window *window = display->windows;
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    91
            SDL_iPhoneKeyboardShow(window);
23c50be687a9 update sdl functions to latest revision
koda
parents: 3357
diff changeset
    92
            */
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
        case 2:
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    95
            // 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
    96
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    97
                [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    98
                [UIView beginAnimations:@"table width more" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
    99
                [UIView setAnimationDuration:0.2];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   100
                self.view.frame = CGRectMake(0, 0, 480, 320);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   101
                [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   102
            }
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
			actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
                                                      delegate:self
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
                                             otherButtonTitles:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
            [actionSheet showInView:self.view];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
            [actionSheet release];
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
            if (!isPaused) 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
                HW_pause();
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
            break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
        default:
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
			NSLog(@"Warning: unset case value in section!");
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
			break;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
#pragma mark actionSheet methods
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
3308
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   125
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   126
        [UIView beginAnimations:@"table width less" context:NULL];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   127
        [UIView setAnimationDuration:0.2];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   128
        self.view.frame = CGRectMake(280, 0, 200, 170);
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   129
        [UIView commitAnimations];
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   130
    }
b6dcae4b6d2c make the tables work also on iphone
koda
parents: 3305
diff changeset
   131
    
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
	if ([actionSheet cancelButtonIndex] != buttonIndex) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
        [[NSNotificationCenter defaultCenter] postNotificationName:@"dismissPopover" object:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
        HW_terminate(NO);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
	else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
        if (!isPaused) 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
            HW_pause();		
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
@end