project_files/HedgewarsMobile/Classes/InGameMenuViewController.m
author koda
Mon, 09 Apr 2012 02:02:14 +0200
changeset 6868 f31b5213b163
parent 6832 fae8fd118da9
permissions -rw-r--r--
i don't understand this, but without this change audio doesn't fade on ios
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
6700
e04da46ee43c the most important commit of the year
koda
parents: 6409
diff changeset
     3
 * Copyright (c) 2009-2012 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
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    20
#import "InGameMenuViewController.h"
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
#import "SDL_sysvideo.h"
3922
44804043b691 iPad Video Out support (+less warnings +code update for latest SDL)
koda
parents: 3829
diff changeset
    22
#import "SDL_uikitkeyboard.h"
6078
8c0cc07731e5 headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents: 6076
diff changeset
    23
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    24
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    25
#define VIEW_HEIGHT 200
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
3647
0d0df215fb52 making chat work... (keyboard support is heavily broken in sdl upstream)
koda
parents: 3598
diff changeset
    27
@implementation InGameMenuViewController
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
    return rotationManager(interfaceOrientation);
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
#pragma mark -
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    34
#pragma mark animating
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    35
-(void) present {
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    36
    CGRect screen = [[UIScreen mainScreen] bounds];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    37
    self.view.backgroundColor = [UIColor clearColor];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    38
    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
    39
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    40
    [UIView beginAnimations:@"showing popover" context:NULL];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    41
    [UIView setAnimationDuration:0.35];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    42
    self.view.frame = CGRectMake(screen.size.height-200, 0, 200, VIEW_HEIGHT);
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    43
    [UIView commitAnimations];
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    44
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    45
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    46
-(void) dismiss {
4912
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    47
    if (IS_IPAD() == NO) {
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    48
        CGRect screen = [[UIScreen mainScreen] bounds];
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    49
        [UIView beginAnimations:@"hiding popover" context:NULL];
862b134284b2 change order of statspage/gamerun when running in dual screen
koda
parents: 4861
diff changeset
    50
        [UIView setAnimationDuration:0.35];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
    51
        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
    52
        [UIView commitAnimations];
4924
616b618814b5 show dual head mode some love
koda
parents: 4920
diff changeset
    53
        [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
    54
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    55
5166
d1eb1560b4d5 and now for something completely different, overlay refactoring!
koda
parents: 5156
diff changeset
    56
    SDL_iPhoneKeyboardHide((SDL_Window *)HW_getSDLWindow());
3648
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    57
}
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    58
2477029463ed some further chat polishing
koda
parents: 3647
diff changeset
    59
#pragma mark -
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
#pragma mark tableView methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
    return 1;
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
5711
cba92708277b disable ios screenshooting for now
koda
parents: 5662
diff changeset
    66
    return 3;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
    static NSString *cellIdentifier = @"CellIdentifier";
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    71
6269
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    72
    NSInteger row = [indexPath row];
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    73
    NSString *cellTitle;
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    74
    if (row == 0)
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    75
        cellTitle = NSLocalizedString(@"Show Help", @"");
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    76
    else if (row == 1)
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    77
        cellTitle = NSLocalizedString(@"Tag", @"");
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    78
    else
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    79
        cellTitle = NSLocalizedString(@"End Game", @"");
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    80
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:cellIdentifier];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
    if (nil == cell) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
                                       reuseIdentifier:cellIdentifier] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
    }
6269
57523ab57218 small tweak to ingamemenu class
koda
parents: 6268
diff changeset
    86
    cell.textLabel.text = cellTitle;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    87
3996
eb549fd864a5 the ios port is also iphone compatible
koda
parents: 3971
diff changeset
    88
    if (IS_IPAD())
3668
3f7a95234d8a tap to play piano notes, fix for audio and pause glitch
koda
parents: 3667
diff changeset
    89
        cell.textLabel.textAlignment = UITextAlignmentCenter;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    90
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
    UIActionSheet *actionSheet;
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
    96
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
    switch ([indexPath row]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
        case 0:
3791
98072b3871c1 help page for ingame, some other fixes here and there
koda
parents: 3737
diff changeset
    99
            [[NSNotificationCenter defaultCenter] postNotificationName:@"show help ingame" object:nil];
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   100
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
        case 1:
4920
bc3c077e15a2 cleaning up how chat is handled on idevices
koda
parents: 4912
diff changeset
   103
            HW_chat();
bc3c077e15a2 cleaning up how chat is handled on idevices
koda
parents: 4912
diff changeset
   104
            SDL_iPhoneKeyboardShow((SDL_Window *)HW_getSDLWindow());
4935
27fb500dd6b1 screenshots 4 ios
koda
parents: 4924
diff changeset
   105
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
            actionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"Are you reeeeeally sure?", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
                                                      delegate:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
                                             cancelButtonTitle:NSLocalizedString(@"Well, maybe not...", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
                                        destructiveButtonTitle:NSLocalizedString(@"Of course!", @"")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
                                             otherButtonTitles:nil];
6409
ca93f38a1aab SDL included some of our patches mainstream
koda
parents: 6269
diff changeset
   113
            [actionSheet showInView:(IS_IPAD() ? self.view : [HWUtils mainSDLViewInstance])];
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
            [actionSheet release];
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   115
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
        default:
3660
bc125bea5849 complete settings page rework
koda
parents: 3649
diff changeset
   118
            DLog(@"Warning: unset case value in section!");
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
    }
3697
d5b30d6373fc remove trailing spaces from end of line
koda
parents: 3668
diff changeset
   121
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
#pragma mark actionSheet methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
-(void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex {
4924
616b618814b5 show dual head mode some love
koda
parents: 4920
diff changeset
   128
    if ([actionSheet cancelButtonIndex] != buttonIndex) {
5166
d1eb1560b4d5 and now for something completely different, overlay refactoring!
koda
parents: 5156
diff changeset
   129
        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
   130
        HW_terminate(NO);
4924
616b618814b5 show dual head mode some love
koda
parents: 4920
diff changeset
   131
    }
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
@end