project_files/HedgewarsMobile/Classes/StatsPageViewController.m
branchqmlfrontend
changeset 11408 b894922d58cc
parent 11235 bb3e57426a07
child 11554 893722a2a1f9
equal deleted inserted replaced
11076:fcbdee9cdd74 11408:b894922d58cc
    27     return rotationManager(interfaceOrientation);
    27     return rotationManager(interfaceOrientation);
    28 }
    28 }
    29 
    29 
    30 -(void) viewDidLoad {
    30 -(void) viewDidLoad {
    31     UITableView *aTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
    31     UITableView *aTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
       
    32     aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    32     [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]];
    33     [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]];
    33 
    34 
    34     NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
    35     NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
    35     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
    36     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
    36     UIImageView *background = [[UIImageView alloc] initWithImage:img];
    37     UIImageView *background = [[UIImageView alloc] initWithImage:img];
    42 
    43 
    43     aTableView.separatorColor = [UIColor darkYellowColor];
    44     aTableView.separatorColor = [UIColor darkYellowColor];
    44     aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    45     aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    45     aTableView.delegate = self;
    46     aTableView.delegate = self;
    46     aTableView.dataSource = self;
    47     aTableView.dataSource = self;
    47 
    48     
       
    49     aTableView.rowHeight = 44;
       
    50     
    48     [self.view addSubview:aTableView];
    51     [self.view addSubview:aTableView];
    49     [aTableView release];
    52     [aTableView release];
    50 
    53 
    51     [super viewDidLoad];
    54     [super viewDidLoad];
       
    55 }
       
    56 
       
    57 #pragma mark - Helpers
       
    58 
       
    59 - (NSString *)teamNameFromInfo: (NSArray *)info
       
    60 {
       
    61     NSString *teamName = [NSString stringWithString:[info objectAtIndex:2]];
       
    62     
       
    63     for (int i=3; i < [info count]; i++)
       
    64     {
       
    65         teamName = [teamName stringByAppendingFormat:@" %@", [info objectAtIndex:i]];
       
    66     }
       
    67     
       
    68     return teamName;
    52 }
    69 }
    53 
    70 
    54 #pragma mark -
    71 #pragma mark -
    55 #pragma mark Table view data source
    72 #pragma mark Table view data source
    56 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    73 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    88         NSUInteger color = [[info objectAtIndex:0] intValue];
   105         NSUInteger color = [[info objectAtIndex:0] intValue];
    89         cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f
   106         cell.textLabel.textColor = [UIColor colorWithRed:((color >> 16) & 0xFF)/255.0f
    90                                                    green:((color >> 8) & 0xFF)/255.0f
   107                                                    green:((color >> 8) & 0xFF)/255.0f
    91                                                     blue:(color & 0xFF)/255.0f
   108                                                     blue:(color & 0xFF)/255.0f
    92                                                    alpha:1.0f];
   109                                                    alpha:1.0f];
    93         cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ (%@ kills)", row+1, [info objectAtIndex:2], [info objectAtIndex:1]];
   110         cell.textLabel.text = [NSString stringWithFormat:@"%d. %@ (%@ %@)", row+1, [self teamNameFromInfo:info], [info objectAtIndex:1], NSLocalizedString(@"kills", nil)];
    94         imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1];
   111         imgName = [NSString stringWithFormat:@"StatsMedal%d",row+1];
    95     } else if (section == 2) {  // general info
   112     } else if (section == 2) {  // general info
    96         imgName = @"iconDamage";
   113         imgName = @"iconDamage";
    97         cell.textLabel.text = [self.statsArray objectAtIndex:row + 2];
   114         cell.textLabel.text = [self.statsArray objectAtIndex:row + 2];
    98         cell.textLabel.textColor = [UIColor lightYellowColor];
   115         cell.textLabel.textColor = [UIColor lightYellowColor];
   114 
   131 
   115     return cell;
   132     return cell;
   116 }
   133 }
   117 
   134 
   118 -(CGFloat) tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section {
   135 -(CGFloat) tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section {
   119     return 160;
   136     return (section == 0) ? 160 : 40;
   120 }
   137 }
   121 
   138 
   122 -(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section {
   139 -(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section {
   123     if (section == 0) {
   140     if (section == 0) {
   124         UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)];
   141         UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)];
   160 
   177 
   161 #pragma mark -
   178 #pragma mark -
   162 #pragma mark button delegate
   179 #pragma mark button delegate
   163 -(void) dismissView {
   180 -(void) dismissView {
   164     [[AudioManagerController mainManager] playClickSound];
   181     [[AudioManagerController mainManager] playClickSound];
   165     [self dismissModalViewControllerAnimated:YES];
   182     [self dismissViewControllerAnimated:YES completion:nil];
   166 }
   183 }
   167 
   184 
   168 #pragma mark -
   185 #pragma mark -
   169 #pragma mark Memory management
   186 #pragma mark Memory management
   170 -(void) didReceiveMemoryWarning {
   187 -(void) didReceiveMemoryWarning {