project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
author koda
Thu, 12 May 2011 23:00:26 +0200
changeset 5207 4c9ae0f484da
parent 5166 d1eb1560b4d5
child 5208 878e551f0b4a
permissions -rw-r--r--
some general tweaks (more intelligent use of macros and more caching)
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
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4939
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
3829
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
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    22
#import "InGameMenuViewController.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
#import "PascalImports.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
#import "SDL_sysvideo.h"
3922
44804043b691 iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents: 3829
diff changeset
    26
#import "SDL_uikitkeyboard.h"
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    27
#import "OpenGLES/ES1/gl.h"
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    28
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    29
#define VIEW_HEIGHT 200
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    31
@implementation InGameMenuViewController
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
@synthesize menuList;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
-(void) didReceiveMemoryWarning {
3971
5c82ee165ed5 minor stuff
koda
parents: 3926
diff changeset
    40
    self.menuList = nil;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    43
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    44
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
    NSArray *array = [[NSArray alloc] initWithObjects:
3701
8c449776ebe6 rewrite portions of some uiviewcontrollers
koda
parents: 3697
diff changeset
    46
                      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
    47
                      NSLocalizedString(@"Tag", @""),
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    48
                      NSLocalizedString(@"Snapshot",@""),
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    49
                      NSLocalizedString(@"End Game", @""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    50
                      nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
    self.menuList = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
    [array release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    53
3926
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    54
    [super viewDidLoad];
668b71f31e51 use dynamic data from engine instead of using hardcoded values
koda
parents: 3924
diff changeset
    55
}
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    56
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
    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
    59
    MSG_DIDUNLOAD();
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
    [menuList release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
    [super dealloc];
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
#pragma mark -
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    69
#pragma mark animating
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    70
-(void) present {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    71
    CGRect screen = [[UIScreen mainScreen] bounds];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    72
    self.view.backgroundColor = [UIColor clearColor];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    73
    self.view.frame = CGRectMake(screen.size.height, 0, 200, VIEW_HEIGHT);
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    74
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    75
    [UIView beginAnimations:@"showing popover" context:NULL];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    76
    [UIView setAnimationDuration:0.35];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    77
    self.view.frame = CGRectMake(screen.size.height-200, 0, 200, VIEW_HEIGHT);
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    78
    [UIView commitAnimations];
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
-(void) dismiss {
4912
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    82
    if (IS_IPAD() == NO) {
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    83
        CGRect screen = [[UIScreen mainScreen] bounds];
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    84
        [UIView beginAnimations:@"hiding popover" context:NULL];
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    85
        [UIView setAnimationDuration:0.35];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    86
        self.view.frame = CGRectMake(screen.size.height, 0, 200, VIEW_HEIGHT);
4912
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    87
        [UIView commitAnimations];
4924
616b618814b5 show dual head mode some love
koda
parents: 4920
diff changeset
    88
        [self.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:0.35];
4912
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    89
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    90
5166
d1eb1560b4d5 and now for something completely different, overlay refactoring!
koda
parents: 5156
diff changeset
    91
    SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    92
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    93
    if (shouldTakeScreenshot) {
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    94
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Please wait"
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    95
                                                        message:nil
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    96
                                                       delegate:nil
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    97
                                              cancelButtonTitle:nil
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    98
                                              otherButtonTitles:nil];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    99
        [alert show];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   100
        UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   101
                                              initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   102
        indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 45);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   103
        [indicator startAnimating];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   104
        [alert addSubview:indicator];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   105
        [indicator release];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   106
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   107
        // all these hacks because of the PAUSE caption on top of everything...
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   108
        [self performSelector:@selector(saveCurrentScreenToPhotoAlbum:) withObject:alert afterDelay:0.3];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   109
    }
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   110
    shouldTakeScreenshot = NO;
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   111
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   112
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   113
#pragma mark -
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
#pragma mark tableView methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
    return 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   120
    return 4;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
    static NSString *cellIdentifier = @"CellIdentifier";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   125
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
    if (nil == cell) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
                                       reuseIdentifier:cellIdentifier] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
    }
4920
bc3c077e15a2 cleaning up how chat is handled on idevices
koda
parents: 4912
diff changeset
   131
    cell.textLabel.text = [self.menuList objectAtIndex:[indexPath row]];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   132
3996
eb549fd864a5 the ios port is also iphone compatible
koda
parents: 3971
diff changeset
   133
    if (IS_IPAD())
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
   134
        cell.textLabel.textAlignment = UITextAlignmentCenter;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   135
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
    UIActionSheet *actionSheet;
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   141
    UIAlertView *alert;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   142
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
    switch ([indexPath row]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
        case 0:
3791
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3737
diff changeset
   145
            [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   146
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
        case 1:
4920
bc3c077e15a2 cleaning up how chat is handled on idevices
koda
parents: 4912
diff changeset
   149
            HW_chat();
bc3c077e15a2 cleaning up how chat is handled on idevices
koda
parents: 4912
diff changeset
   150
            SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow());
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   151
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   152
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   153
        case 2:
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   154
            alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Going to take a screenshot",@"")
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   155
                                               message:NSLocalizedString(@"The game snapshot will be placed in your Photo Album and it will be taken as soon as the pause menu is dismissed",@"")
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   156
                                              delegate:nil
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   157
                                     cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   158
                                     otherButtonTitles:nil];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   159
            [alert show];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   160
            [alert release];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   161
            shouldTakeScreenshot = YES;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   162
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   163
            break;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   164
        case 3:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   165
            // expand the view (and table) so that the actionsheet can be selected on the iPhone
4008
d87619de120d fix an annoying bug that didn't allow returning to the ifrontend
koda
parents: 3996
diff changeset
   166
            if (IS_IPAD() == NO) {
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   167
                CGRect screen = [[UIScreen mainScreen] bounds];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   168
                [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
                [UIView beginAnimations:@"table width more" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
                [UIView setAnimationDuration:0.2];
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
   171
                self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
                [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   173
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
                                                      delegate:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   176
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   177
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   178
                                             otherButtonTitles:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
            [actionSheet showInView:self.view];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   180
            [actionSheet release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   181
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   182
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
        default:
3660
bc125bea5849 complete settings page rework
koda
parents: 3649
diff changeset
   184
            DLog(@"Warning: unset case value in section!");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   186
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   187
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   188
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   190
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   191
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
#pragma mark actionSheet methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   193
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
4912
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
   194
    if (IS_IPAD() == NO) {
3649
bc35f8fee587 aim now starts slow and then moves faster
koda
parents: 3648
diff changeset
   195
        CGRect screen = [[UIScreen mainScreen] bounds];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   196
        [UIView beginAnimations:@"table width less" context:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
        [UIView setAnimationDuration:0.2];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   198
        self.view.frame = CGRectMake(screen.size.height-200, 0, 200, VIEW_HEIGHT);
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
        [UIView commitAnimations];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   200
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   201
4924
616b618814b5 show dual head mode some love
koda
parents: 4920
diff changeset
   202
    if ([actionSheet cancelButtonIndex] != buttonIndex) {
5166
d1eb1560b4d5 and now for something completely different, overlay refactoring!
koda
parents: 5156
diff changeset
   203
        SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
4861
91f889289a47 (ios) perform a small change about how to close the game window, should hopefully save memory and avoid crashes (who am i kidding? that's the usual PR talk...)
koda
parents: 4358
diff changeset
   204
        HW_terminate(NO);
4924
616b618814b5 show dual head mode some love
koda
parents: 4920
diff changeset
   205
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   206
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
5166
d1eb1560b4d5 and now for something completely different, overlay refactoring!
koda
parents: 5156
diff changeset
   208
#pragma mark -
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   209
#pragma mark save screenshot
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   210
//by http://www.bit-101.com/blog/?p=1861
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   211
// callback for CGDataProviderCreateWithData
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   212
void releaseData(void *info, const void *data, size_t dataSize) {
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   213
    DLog(@"freeing raw data\n");
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   214
    free((void *)data);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   215
}
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   216
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   217
// callback for UIImageWriteToSavedPhotosAlbum
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   218
-(void) image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   219
    DLog(@"Save finished\n");
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   220
    [image release];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   221
    UIAlertView *alert = (UIAlertView *)contextInfo;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   222
    [alert dismissWithClickedButtonIndex:0 animated:YES];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   223
    [alert release];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   224
}
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   225
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   226
// the resolution of the buffer is always equal to the hardware device even if scaled
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   227
-(void) saveCurrentScreenToPhotoAlbum:(UIAlertView *)alert {
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   228
    CGRect screenRect = [[UIScreen mainScreen] bounds];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   229
    int width = screenRect.size.width;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   230
    int height = screenRect.size.height;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   231
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   232
    NSInteger size = width * height * 4;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   233
    GLubyte *buffer = (GLubyte *) malloc(size * sizeof(GLubyte));
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   234
    GLubyte *buffer_flipped = (GLubyte *) malloc(size * sizeof(GLubyte));
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   235
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   236
    glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
4939
6d512ba87f72 screenshot binding for library (on ios it just plays the sound)
koda
parents: 4935
diff changeset
   237
    HW_screenshot();
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   238
    // flip the data as glReadPixels here reads upside down
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   239
    for(int y = 0; y <height; y++)
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   240
        for(int x = 0; x <width * 4; x++)
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   241
            buffer_flipped[(int)((height - 1 - y) * width * 4 + x)] = buffer[(int)(y * 4 * width + x)];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   242
    free(buffer);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   243
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   244
    CGDataProviderRef provider = CGDataProviderCreateWithData(NULL, buffer_flipped, size, releaseData);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   245
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   246
    CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   247
    CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   248
    CGImageRef imageRef = CGImageCreate(width, height, 8, 32, 4 * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   249
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   250
    CGColorSpaceRelease(colorSpaceRef);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   251
    CGDataProviderRelease(provider);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   252
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   253
    UIImage *image;
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   254
    if ([UIImage respondsToSelector:@selector(imageWithCGImage:scale:orientation:)])
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   255
        image = [[UIImage alloc] initWithCGImage:imageRef scale:1 orientation:UIImageOrientationRight];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   256
    else
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   257
        image = [[UIImage alloc] initWithCGImage:imageRef];
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   258
    CGImageRelease(imageRef);
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   259
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   260
    UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), (void *)alert); // add callback for finish saving
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   261
}
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   262
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   263
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   264
@end