project_files/HedgewarsMobile/Classes/SupportViewController.m
author koda
Sun, 17 Apr 2011 20:52:56 +0200
changeset 5154 851f36579ed4
parent 4976 088d40d8aba2
child 5208 878e551f0b4a
permissions -rw-r--r--
initial refactoring for interfacing the game engine from the ios frontend (game doesn't run yet)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     1
/*
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4341
diff changeset
     3
 * Copyright (c) 2009-2011 Vittorio Giovara <vittorio.giovara@gmail.com>
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     4
 *
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     8
 *
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    13
 *
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    17
 *
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    18
 * File created on 19/09/2010.
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    19
 */
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    20
3891
f8f0d0ceb19c initial support for savegames
koda
parents: 3884
diff changeset
    21
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    22
#import "SupportViewController.h"
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    23
#import "CommodityFunctions.h"
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    24
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    25
@implementation SupportViewController
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    26
@synthesize waysToSupport;
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    27
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    28
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    29
    return rotationManager(interfaceOrientation);
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    30
}
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
    31
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    32
#pragma mark -
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    33
#pragma mark View lifecycle
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    34
-(void) viewDidLoad {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    35
    [super viewDidLoad];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    36
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    37
    NSArray *array = [[NSArray alloc] initWithObjects:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    38
                      NSLocalizedString(@"Leave a positive review on iTunes!",@""),
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    39
                      NSLocalizedString(@"Join us on Facebook",@""),
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    40
                      NSLocalizedString(@"Follow on Twitter",@""),
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    41
                      NSLocalizedString(@"Visit website",@""),
4341
46b8791e577f minor things
koda
parents: 4115
diff changeset
    42
                      NSLocalizedString(@"Chat with us in IRC",@""),
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    43
                      nil];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    44
    self.waysToSupport = array;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    45
    [array release];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    46
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    47
    self.tableView.rowHeight = 50;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    48
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    49
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    50
#pragma mark -
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    51
#pragma mark Table view data source
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    52
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    53
    return 2;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    54
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    55
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    56
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    57
    if (section == 0)
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    58
        return 1;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    59
    else
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    60
        return [self.waysToSupport count] - 1;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    61
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    62
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    63
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    64
    static NSString *CellIdentifier = @"Cell";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    65
    NSInteger row = [indexPath row];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    66
    NSInteger section = [indexPath section];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    67
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    68
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    69
    if (cell == nil)
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    70
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    71
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    72
    NSString *rowString = [self.waysToSupport objectAtIndex:(row + section)];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    73
    cell.textLabel.text = rowString;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    74
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    75
    if (section == 0) {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    76
        cell.textLabel.textAlignment = UITextAlignmentCenter;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    77
        cell.imageView.image = nil;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    78
    } else {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    79
        cell.textLabel.textAlignment = UITextAlignmentLeft;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    80
        NSString *imgString = nil;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    81
        switch (row) {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    82
            case 0:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    83
                imgString = @"fb.png";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    84
                break;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    85
            case 1:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    86
                imgString = @"tw.png";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    87
                break;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    88
            case 2:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    89
                imgString = @"Icon-Small.png";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    90
                break;
4341
46b8791e577f minor things
koda
parents: 4115
diff changeset
    91
            case 3:
46b8791e577f minor things
koda
parents: 4115
diff changeset
    92
                imgString = @"irc.png";
46b8791e577f minor things
koda
parents: 4115
diff changeset
    93
                break;
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    94
            default:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    95
                DLog(@"No way");
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    96
                break;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    97
        }
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    98
        
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
    99
        UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   100
        cell.imageView.image = img;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   101
        [img release];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   102
    }
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   103
    
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   104
    return cell;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   105
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   106
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   107
#pragma mark -
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   108
#pragma mark Table view delegate
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   109
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   110
    NSString *urlString = nil;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   111
    if ([indexPath section] == 0)
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   112
        urlString = @"http://itunes.apple.com/us/app/hedgewars/id391234866?affC=QQABAAAAHgAFasEiWjVwUGZOc3k1VGctQkRJazlacXhUclpBTVpiU2xteVdfUQ%3D%3D#&mt=8";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   113
    else
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   114
        switch ([indexPath row]) {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   115
            case 0:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   116
                urlString = @"http://www.facebook.com/Hedgewars";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   117
                break;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   118
            case 1:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   119
                urlString = @"http://twitter.com/hedgewars";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   120
                break;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   121
            case 2:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   122
                urlString = @"http://www.hedgewars.org";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   123
                break;
4341
46b8791e577f minor things
koda
parents: 4115
diff changeset
   124
            case 3:
46b8791e577f minor things
koda
parents: 4115
diff changeset
   125
                urlString = @"http://webchat.freenode.net/?channels=hedgewars";
46b8791e577f minor things
koda
parents: 4115
diff changeset
   126
                break;
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   127
            default:
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   128
                DLog(@"No way");
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   129
                break;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   130
        }
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   131
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   132
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   133
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   134
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger) section {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   135
    if (section == 1) {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   136
        UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 240)];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   137
        UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"surprise.png"];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   138
        UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   139
        [img release];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   140
        imgView.center = CGPointMake(self.tableView.frame.size.width/2, 120);
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   141
        [footer addSubview:imgView];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   142
        [imgView release];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   143
        
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   144
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 20)];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   145
        label.textAlignment = UITextAlignmentCenter;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   146
        label.text = @" ♥ THANK YOU ♥ ";
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   147
        label.backgroundColor = [UIColor clearColor];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   148
        label.center = CGPointMake(self.tableView.frame.size.width/2, 250);
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   149
        [footer addSubview:label];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   150
        [label release];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   151
        
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   152
        return [footer autorelease];
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   153
    } else
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   154
        return nil;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   155
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   156
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   157
-(CGFloat) tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   158
    // image height + label height
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   159
    return 265;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   160
}
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   161
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   162
#pragma mark -
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   163
#pragma mark Memory management
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   164
-(void)didReceiveMemoryWarning {
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   165
    [super didReceiveMemoryWarning];
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   166
}
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   167
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   168
-(void) viewDidUnload {
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   169
    self.waysToSupport = nil;
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   170
    MSG_DIDUNLOAD();
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   171
    [super viewDidUnload];
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   172
}
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   173
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   174
-(void) dealloc {
4115
222b8016c773 make the support page more portable
koda
parents: 3891
diff changeset
   175
    [self.waysToSupport release];
3884
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   176
    [super dealloc];
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   177
}
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   178
d7479079a8a8 various fixes around, plus new 'ask for review' page
koda
parents:
diff changeset
   179
@end