project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
author koda
Mon, 04 Oct 2010 00:00:42 +0200
changeset 3924 2a9ace189288
parent 3922 44804043b691
child 3926 668b71f31e51
permissions -rw-r--r--
WIP for an objc ammomenu implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3829
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     1
/*
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     4
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     8
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    12
 * GNU General Public License for more details.
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    13
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    14
 * You should have received a copy of the GNU General Public License
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    15
 * along with this program; if not, write to the Free Software
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    17
 *
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    18
 * File created on 25/03/2010.
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    19
 */
81db3c85784b headers ftw, also right project file
koda
parents: 3791
diff changeset
    20
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
#import "SDL_uikitappdelegate.h"
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    23
#import "InGameMenuViewController.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
#import "PascalImports.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
#import "SDL_sysvideo.h"
3922
44804043b691 iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents: 3829
diff changeset
    27
#import "SDL_uikitkeyboard.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    29
@implementation InGameMenuViewController
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
@synthesize menuList;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
    // Releases the view if it doesn't have a superview.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
    NSArray *array = [[NSArray alloc] initWithObjects:
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    44
                      NSLocalizedString(@"Show Help", @""),
3737
2ba6ac8a114b reworked the initialization functions, now it should be safe to update and no more need of spinning wheel at first launch
koda
parents: 3701
diff changeset
    45
                      NSLocalizedString(@"Tag", @""),
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    46
                      NSLocalizedString(@"End Game", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
                      nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    48
    self.menuList = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
    [array release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    50
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    51
    // 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
    52
    SDL_VideoDevice *_this = SDL_GetVideoDevice();
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    53
    SDL_VideoDisplay *display = &_this->displays[0];
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    54
    sdlwindow = display->windows;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    55
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    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
    61
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
    [menuList release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
#pragma mark -
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    71
#pragma mark animating
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    72
-(void) present {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    73
    CGRect screen = [[UIScreen mainScreen] bounds];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    74
    self.view.backgroundColor = [UIColor clearColor];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    75
    self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    76
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    77
    [UIView beginAnimations:@"showing popover" context:NULL];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    78
    [UIView setAnimationDuration:0.35];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    79
    self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    80
    [UIView commitAnimations];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    81
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    82
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    83
-(void) dismiss {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    84
    CGRect screen = [[UIScreen mainScreen] bounds];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    85
    [UIView beginAnimations:@"hiding popover" context:NULL];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    86
    [UIView setAnimationDuration:0.35];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    87
    self.view.frame = CGRectMake(screen.size.height, 0, 200, 170);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    88
    [UIView commitAnimations];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    89
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    90
    [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    91
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    92
    [self removeChat];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    93
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    94
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    95
#pragma mark -
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
#pragma mark tableView methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
    static NSString *cellIdentifier = @"CellIdentifier";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   107
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
    if (nil == cell) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
                                       reuseIdentifier:cellIdentifier] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
    cell.textLabel.text = [menuList objectAtIndex:[indexPath row]];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   114
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   115
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   116
        cell.textLabel.textAlignment = UITextAlignmentCenter;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   117
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
    return cell;
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
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
    UIActionSheet *actionSheet;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   123
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
    switch ([indexPath row]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
        case 0:
3791
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3737
diff changeset
   126
            [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
        case 1:
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   129
            if (SDL_iPhoneKeyboardIsShown(sdlwindow))
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   130
                [self removeChat];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   131
            else {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   132
                HW_chat();
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   133
                SDL_iPhoneKeyboardShow(sdlwindow);
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   134
            }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
            // expand the view (and table) so that the actionsheet can be selected on the iPhone
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   139
                CGRect screen = [[UIScreen mainScreen] bounds];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
                [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
                [UIView beginAnimations:@"table width more" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
                [UIView setAnimationDuration:0.2];
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   143
                self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
                [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   146
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
                                                      delegate:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   149
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   150
                                             otherButtonTitles:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   151
            [actionSheet showInView:self.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   152
            [actionSheet release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   153
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   154
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   155
        default:
3660
bc125bea5849 complete settings page rework
koda
parents: 3649
diff changeset
   156
            DLog(@"Warning: unset case value in section!");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   157
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   159
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   160
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   161
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   162
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   163
-(void) removeChat {
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
   164
    if (SDL_iPhoneKeyboardIsShown(sdlwindow)) {
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   165
        SDL_iPhoneKeyboardHide(sdlwindow);
3667
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
   166
        HW_chatEnd();
9359a70df013 use external libs more consistently
koda
parents: 3662
diff changeset
   167
    }
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   168
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   169
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
#pragma mark actionSheet methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   173
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
3649
bc35f8fee587 aim now starts slow and then moves faster
koda
parents: 3648
diff changeset
   174
        CGRect screen = [[UIScreen mainScreen] bounds];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
        [UIView beginAnimations:@"table width less" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   176
        [UIView setAnimationDuration:0.2];
3649
bc35f8fee587 aim now starts slow and then moves faster
koda
parents: 3648
diff changeset
   177
        self.view.frame = CGRectMake(screen.size.height-200, 0, 200, 170);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   178
        [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   180
3924
2a9ace189288 WIP for an objc ammomenu implementation
koda
parents: 3922
diff changeset
   181
    if ([actionSheet cancelButtonIndex] != buttonIndex)
3922
44804043b691 iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents: 3829
diff changeset
   182
        [[NSNotificationCenter defaultCenter] postNotificationName:@"remove overlay" object:nil];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
@end