project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
author koda
Sun, 25 Jul 2010 01:59:41 +0200
changeset 3668 3f7a95234d8a
parent 3667 9359a70df013
child 3697 d5b30d6373fc
permissions -rw-r--r--
tap to play piano notes, fix for audio and pause glitch
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
    NSArray *array = [[NSArray alloc] initWithObjects:
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
    30
                      NSLocalizedString(@"Return to Game", @""),
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
                      NSLocalizedString(@"Chat", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
                      NSLocalizedString(@"End Game", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
                      nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
    self.menuList = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
    [array release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
    
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    37
    // 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
    38
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    39
    SDL_VideoDisplay *display = &_this->displays[0];
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    40
    sdlwindow = display->windows;
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    41
        
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
    self.menuList = nil;
3662
a44406f4369b polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents: 3660
diff changeset
    47
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
    [menuList release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
#pragma mark -
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    57
#pragma mark animating
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    58
-(void) present {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    59
    CGRect screen = [[UIScreen mainScreen] bounds];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    60
    self.view.backgroundColor = [UIColor clearColor];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    61
    self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    62
    
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    63
    [UIView beginAnimations:@"showing popover" context:NULL];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    64
    [UIView setAnimationDuration:0.35];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    65
    self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    66
    [UIView commitAnimations];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    67
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    68
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    69
-(void) dismiss {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    70
    CGRect screen = [[UIScreen mainScreen] bounds];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    71
    [UIView beginAnimations:@"hiding popover" context:NULL];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    72
    [UIView setAnimationDuration:0.35];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    73
    self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    74
    [UIView commitAnimations];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    75
        
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    76
    [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    77
    
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    78
    [self removeChat];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    79
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    80
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    81
#pragma mark -
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
#pragma mark tableView methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
    static NSString *cellIdentifier = @"CellIdentifier";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
    if (nil == cell) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
                                       reuseIdentifier:cellIdentifier] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
    cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
    
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   101
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   102
        cell.textLabel.textAlignment = UITextAlignmentCenter;
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   103
    
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
    UIActionSheet *actionSheet;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
    switch ([indexPath row]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
        case 0:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
            HW_pause();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
        case 1:
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   115
            if (SDL_iPhoneKeyboardIsShown(sdlwindow))
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   116
                [self removeChat];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   117
            else {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   118
                HW_chat();
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   119
                SDL_iPhoneKeyboardShow(sdlwindow);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   120
            }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
            // expand the view (and table) so that the actionsheet can be selected on the iPhone
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   125
                CGRect screen = [[UIScreen mainScreen] bounds];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
                [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
                [UIView beginAnimations:@"table width more" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
                [UIView setAnimationDuration:0.2];
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   129
                self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
                [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
                                                      delegate:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
                                             otherButtonTitles:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
            [actionSheet showInView:self.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
            [actionSheet release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
        default:
3660
bc125bea5849 complete settings page rework
koda
parents: 3649
diff changeset
   142
            DLog(@"Warning: unset case value in section!");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   146
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   149
-(void) removeChat {
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
   150
    if (SDL_iPhoneKeyboardIsShown(sdlwindow)) {
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   151
        SDL_iPhoneKeyboardHide(sdlwindow);
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
   152
        HW_chatEnd();
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
   153
    }
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   154
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   155
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   156
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   157
#pragma mark actionSheet methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   159
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
3649
bc35f8fee587 aim now starts slow and then moves faster
koda
parents: 3648
diff changeset
   160
        CGRect screen = [[UIScreen mainScreen] bounds];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   161
        [UIView beginAnimations:@"table width less" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   162
        [UIView setAnimationDuration:0.2];
3649
bc35f8fee587 aim now starts slow and then moves faster
koda
parents: 3648
diff changeset
   163
        self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   164
        [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   165
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   166
    
3598
a8aa06bae895 tiy new overlay graphics
koda
parents: 3547
diff changeset
   167
    if ([actionSheet cancelButtonIndex] != buttonIndex)
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   168
        HW_terminate(NO);     
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
@end