project_files/HedgewarsMobile/Classes/StatsPageViewController.m
author koda
Wed, 05 Jan 2011 03:53:46 +0100
changeset 4819 63011cbaa438
parent 4766 255e6c76c7e9
child 4856 dbc256913b35
permissions -rw-r--r--
ctf_blizzard ios fix
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     1
/*
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     3
 * Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com>
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     4
 *
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     8
 *
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    12
 * GNU General Public License for more details.
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    13
 *
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    17
 *
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    18
 * File created on 30/12/2010.
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    19
 */
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    20
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    21
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    22
#import "StatsPageViewController.h"
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    23
#import "CommodityFunctions.h"
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    24
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    25
@implementation StatsPageViewController
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    26
@synthesize statsArray;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    27
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    28
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    29
    return rotationManager(interfaceOrientation);
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    30
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    31
4766
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    32
-(void) viewDidLoad {
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    33
    if ([self.tableView respondsToSelector:@selector(setBackgroundView:)])
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    34
        self.tableView.backgroundView = nil;
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    35
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    36
    NSString *imgName;
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    37
    if (IS_IPAD())
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    38
        imgName = @"mediumBackground~ipad.png";
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    39
    else
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    40
        imgName = @"smallerBackground~iphone.png";
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    41
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    42
    if ([self.tableView respondsToSelector:@selector(setBackgroundView:)]) {
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    43
        UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:imgName];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    44
        UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    45
        [backgroundImage release];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    46
        [self.tableView setBackgroundView:background];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    47
        [background release];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    48
    } else
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    49
        self.view.backgroundColor = [UIColor blackColor];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    50
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    51
    self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    52
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    53
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    54
    [super viewDidLoad];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    55
}
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    56
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    57
#pragma mark -
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    58
#pragma mark Table view data source
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    59
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    60
    return 3;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    61
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    62
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    63
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    64
    if (section == 0 || section == 2)
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    65
        return 1;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    66
    else
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    67
        return [self.statsArray count] - 1;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    68
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    69
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    70
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    71
    static NSString *CellIdentifier0 = @"Cell0";
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    72
    NSInteger section = [indexPath section];
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    73
    NSInteger row = [indexPath row];
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    74
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    75
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    76
    if (cell == nil)
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    77
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    78
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    79
    cell.textLabel.textAlignment = UITextAlignmentCenter;
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    80
    if (section == 0) {
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    81
        cell.textLabel.text = [self.statsArray objectAtIndex:row];
4766
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    82
        cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    83
    } else if (section == 1) {
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    84
        cell.textLabel.text = [self.statsArray objectAtIndex:row + 1];
4766
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    85
        cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    86
    } else {
4763
c228a4841e3f unify stats display on ipad and non-ipad and on saved and normal games
koda
parents: 4760
diff changeset
    87
        cell.textLabel.text = NSLocalizedString(@"Done",@"");
4766
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    88
        cell.textLabel.textColor = [UIColor whiteColor];
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    89
    }
4819
63011cbaa438 ctf_blizzard ios fix
koda
parents: 4766
diff changeset
    90
    cell.textLabel.adjustsFontSizeToFitWidth = YES;
4766
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    91
    cell.backgroundColor = [UIColor blackColor];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    92
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    93
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    94
    return cell;
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    95
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    96
4766
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    97
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    98
    return 160;
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
    99
}
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   100
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   101
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   102
    if (section == 0) {
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   103
        UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 160)];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   104
        UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   105
        UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   106
        [img release];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   107
        imgView.center = CGPointMake(self.tableView.frame.size.height/2, 160/2);
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   108
        [header addSubview:imgView];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   109
        [imgView release];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   110
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   111
        return [header autorelease];
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   112
    } else
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   113
        return nil;
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   114
}
255e6c76c7e9 beautify stat page
koda
parents: 4763
diff changeset
   115
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   116
#pragma mark -
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   117
#pragma mark Table view delegate
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   118
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   119
    if ([indexPath section] == 2)
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   120
        [self dismissModalViewControllerAnimated:YES];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   121
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   122
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   123
#pragma mark -
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   124
#pragma mark Memory management
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   125
-(void) didReceiveMemoryWarning {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   126
    // Releases the view if it doesn't have a superview.
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   127
    [super didReceiveMemoryWarning];
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
   128
    self.statsArray = nil;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   129
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   130
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   131
-(void) dealloc {
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
   132
    [statsArray release];
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   133
    [super dealloc];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   134
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   135
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   136
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   137
@end
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
   138