project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
author koda
Sat, 17 Jul 2010 03:59:10 +0200
changeset 3647 0d0df215fb52
parent 3598 project_files/HedgewarsMobile/Classes/PopoverMenuViewController.m@a8aa06bae895
child 3648 2477029463ed
permissions -rw-r--r--
making chat work... (keyboard support is heavily broken in sdl upstream)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     1
    //
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     2
//  popupMenuViewController.m
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     3
//  HedgewarsMobile
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     4
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     5
//  Created by Vittorio on 25/03/10.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     7
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     8
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     9
#import "SDL_uikitappdelegate.h"
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    10
#import "InGameMenuViewController.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    11
#import "PascalImports.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    12
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
#import "SDL_sysvideo.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    14
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    15
@implementation InGameMenuViewController
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
@synthesize menuList;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    17
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    18
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
    // Releases the view if it doesn't have a superview.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
    isPaused = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
    NSArray *array = [[NSArray alloc] initWithObjects:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
                      NSLocalizedString(@"Pause Game", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
                      NSLocalizedString(@"Chat", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
                      NSLocalizedString(@"End Game", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
                      nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
    self.menuList = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
    [array release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
    
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    39
    // save the sdl window (!= uikit window) for future reference
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    40
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    41
    SDL_VideoDisplay *display = &_this->displays[0];
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    42
    sdlwindow = display->windows;
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    43
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
    self.menuList = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
    MSG_DIDUNLOAD();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
    [menuList release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
#pragma mark tableView methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
    static NSString *cellIdentifier = @"CellIdentifier";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
    if (nil == cell) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
                                       reuseIdentifier:cellIdentifier] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
    cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
    UIActionSheet *actionSheet;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
    switch ([indexPath row]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
        case 0:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
            HW_pause();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
            isPaused = !isPaused;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
        case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
            HW_chat();
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    91
            SDL_iPhoneKeyboardShow(sdlwindow);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
            // expand the view (and table) so that the actionsheet can be selected on the iPhone
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
                [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
                [UIView beginAnimations:@"table width more" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
                [UIView setAnimationDuration:0.2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
                self.view.frame = CGRectMake(0, 0, 480, 320);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
                [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
                                                      delegate:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
                                             otherButtonTitles:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
            [actionSheet showInView:self.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
            [actionSheet release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
            if (!isPaused) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
                HW_pause();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
            NSLog(@"Warning: unset case value in section!");
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
#pragma mark actionSheet methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
        [UIView beginAnimations:@"table width less" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
        [UIView setAnimationDuration:0.2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
        self.view.frame = CGRectMake(280, 0, 200, 170);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
        [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
    
3598
a8aa06bae895 tiy new overlay graphics
koda
parents: 3547
diff changeset
   131
    if ([actionSheet cancelButtonIndex] != buttonIndex)
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
        HW_terminate(NO);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
    else
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
        if (!isPaused) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
            HW_pause();     
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
@end