project_files/HedgewarsMobile/Classes/StatsPageViewController.m
author koda
Fri, 31 Dec 2010 01:15:43 +0100
changeset 4763 c228a4841e3f
parent 4760 224c31b3ce7d
child 4766 255e6c76c7e9
permissions -rw-r--r--
unify stats display on ipad and non-ipad and on saved and normal games
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
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    32
#pragma mark -
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    33
#pragma mark Table view data source
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    34
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    35
    return 3;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    36
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    37
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    38
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    39
    if (section == 0 || section == 2)
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    40
        return 1;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    41
    else
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    42
        return [self.statsArray count] - 1;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    43
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    44
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    45
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    46
    static NSString *CellIdentifier0 = @"Cell0";
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    47
    NSInteger section = [indexPath section];
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    48
    NSInteger row = [indexPath row];
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    49
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    50
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    51
    if (cell == nil)
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    52
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    53
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    54
    cell.textLabel.textAlignment = UITextAlignmentCenter;
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    55
    if (section == 0) {
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    56
        cell.textLabel.text = [self.statsArray objectAtIndex:row];
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    57
    } else if (section == 1) {
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    58
        cell.textLabel.text = [self.statsArray objectAtIndex:row + 1];
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    59
    } else {
4763
c228a4841e3f unify stats display on ipad and non-ipad and on saved and normal games
koda
parents: 4760
diff changeset
    60
        cell.textLabel.text = NSLocalizedString(@"Done",@"");
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
    return cell;
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    64
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    65
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    66
#pragma mark -
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    67
#pragma mark Table view delegate
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    68
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    69
    if ([indexPath section] == 2)
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    70
        [self dismissModalViewControllerAnimated:YES];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    71
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    72
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    73
#pragma mark -
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    74
#pragma mark Memory management
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    75
-(void) didReceiveMemoryWarning {
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    76
    // Releases the view if it doesn't have a superview.
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    77
    [super didReceiveMemoryWarning];
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    78
    self.statsArray = nil;
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    79
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    80
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    81
-(void) dealloc {
4760
224c31b3ce7d simplify stats handling
koda
parents: 4757
diff changeset
    82
    [statsArray release];
4757
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    83
    [super dealloc];
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    84
}
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    85
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    86
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    87
@end
7ca9ebb6895d initial stats display
koda
parents:
diff changeset
    88