project_files/HedgewarsMobile/Classes/StatsPageViewController.m
branchios-develop
changeset 12872 00215a7ec5f5
parent 11549 893722a2a1f9
child 13166 ba5c794adae3
equal deleted inserted replaced
12871:2c06b1120749 12872:00215a7ec5f5
    21 
    21 
    22 
    22 
    23 @implementation StatsPageViewController
    23 @implementation StatsPageViewController
    24 @synthesize statsArray;
    24 @synthesize statsArray;
    25 
    25 
    26 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    26 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    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.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    33     [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]];
    33     [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]];
    34 
    34 
    35     NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
    35     NSString *imgName = (IS_IPAD()) ? @"mediumBackground~ipad.png" : @"smallerBackground~iphone.png";
    36     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
    36     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgName];
    37     UIImageView *background = [[UIImageView alloc] initWithImage:img];
    37     UIImageView *background = [[UIImageView alloc] initWithImage:img];
    38     [img release];
       
    39     background.frame = self.view.frame;
    38     background.frame = self.view.frame;
    40     background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    39     background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    41     [self.view insertSubview:background atIndex:0];
    40     [self.view insertSubview:background atIndex:0];
    42     [background release];
       
    43 
    41 
    44     aTableView.separatorColor = [UIColor darkYellowColor];
    42     aTableView.separatorColor = [UIColor darkYellowColor];
    45     aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    43     aTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    46     aTableView.delegate = self;
    44     aTableView.delegate = self;
    47     aTableView.dataSource = self;
    45     aTableView.dataSource = self;
    48     
    46     
    49     aTableView.rowHeight = 44;
    47     aTableView.rowHeight = 44;
    50     
    48     
    51     [self.view addSubview:aTableView];
    49     [self.view addSubview:aTableView];
    52     [aTableView release];
       
    53 
    50 
    54     [super viewDidLoad];
    51     [super viewDidLoad];
    55 }
    52 }
    56 
    53 
    57 #pragma mark - Helpers
    54 #pragma mark - Helpers
    68     return teamName;
    65     return teamName;
    69 }
    66 }
    70 
    67 
    71 #pragma mark -
    68 #pragma mark -
    72 #pragma mark Table view data source
    69 #pragma mark Table view data source
    73 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    70 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    74     return 3;
    71     return 3;
    75 }
    72 }
    76 
    73 
    77 -(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    74 - (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section {
    78     if (section == 0)
    75     if (section == 0)
    79         return 1;
    76         return 1;
    80     else if (section == 1)
    77     else if (section == 1)
    81         return [[self.statsArray objectAtIndex:0] count];
    78         return [[self.statsArray objectAtIndex:0] count];
    82     else
    79     else
    90     NSString *imgName = @"";
    87     NSString *imgName = @"";
    91     NSString *imgPath = ICONS_DIRECTORY();
    88     NSString *imgPath = ICONS_DIRECTORY();
    92 
    89 
    93     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    90     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    94     if (cell == nil)
    91     if (cell == nil)
    95         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
    92         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0];
    96 
    93 
    97     if (section == 0) {         // winning team
    94     if (section == 0) {         // winning team
    98         imgName = @"star";
    95         imgName = @"star";
    99         imgPath = [[NSBundle mainBundle] resourcePath];
    96         imgPath = [[NSBundle mainBundle] resourcePath];
   100         cell.textLabel.text = [self.statsArray objectAtIndex:1];
    97         cell.textLabel.text = [self.statsArray objectAtIndex:1];
   115         cell.textLabel.textColor = [UIColor lightYellowColor];
   112         cell.textLabel.textColor = [UIColor lightYellowColor];
   116     }
   113     }
   117 
   114 
   118     NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.png",imgPath,imgName];
   115     NSString *imgString = [[NSString alloc] initWithFormat:@"%@/%@.png",imgPath,imgName];
   119     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString];
   116     UIImage *img = [[UIImage alloc] initWithContentsOfFile:imgString];
   120     [imgString release];
       
   121     UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
   117     UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
   122     cell.imageView.image = img;
   118     cell.imageView.image = img;
   123     [img release];
       
   124     cell.accessoryView = imgView;
   119     cell.accessoryView = imgView;
   125     [imgView release];
       
   126 
   120 
   127     cell.textLabel.textAlignment = NSTextAlignmentCenter;
   121     cell.textLabel.textAlignment = NSTextAlignmentCenter;
   128     cell.textLabel.adjustsFontSizeToFitWidth = YES;
   122     cell.textLabel.adjustsFontSizeToFitWidth = YES;
   129     cell.backgroundColor = [UIColor blackColor];
   123     cell.backgroundColor = [UIColor blackColor];
   130     cell.selectionStyle = UITableViewCellSelectionStyleNone;
   124     cell.selectionStyle = UITableViewCellSelectionStyleNone;
   141         UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)];
   135         UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, aTableView.frame.size.width, 160)];
   142         header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
   136         header.autoresizingMask = UIViewAutoresizingFlexibleWidth;
   143 
   137 
   144         UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"];
   138         UIImage *img = [[UIImage alloc] initWithContentsOfFile:@"smallerTitle.png"];
   145         UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
   139         UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
   146         [img release];
       
   147         imgView.center = CGPointMake(aTableView.frame.size.width/2, 160/2);
   140         imgView.center = CGPointMake(aTableView.frame.size.width/2, 160/2);
   148         imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
   141         imgView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
   149         [header addSubview:imgView];
   142         [header addSubview:imgView];
   150         [imgView release];
       
   151 
   143 
   152         return [header autorelease];
   144         return header;
   153     } else
   145     } else
   154         return nil;
   146         return nil;
   155 }
   147 }
   156 
   148 
   157 -(CGFloat) tableView:(UITableView *)aTableView heightForFooterInSection:(NSInteger)section {
   149 -(CGFloat) tableView:(UITableView *)aTableView heightForFooterInSection:(NSInteger)section {
   166         UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width * 70 / 100, aTableView.rowHeight)
   158         UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 17, self.view.frame.size.width * 70 / 100, aTableView.rowHeight)
   167                                                   andTitle:NSLocalizedString(@"Done",@"")];
   159                                                   andTitle:NSLocalizedString(@"Done",@"")];
   168         button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
   160         button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
   169         [button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
   161         [button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
   170         [footer addSubview:button];
   162         [footer addSubview:button];
   171         [button release];
       
   172 
   163 
   173         return [footer autorelease];
   164         return footer;
   174     } else
   165     } else
   175         return nil;
   166         return nil;
   176 }
   167 }
   177 
   168 
   178 #pragma mark -
   169 #pragma mark -
   179 #pragma mark button delegate
   170 #pragma mark button delegate
   180 -(void) dismissView {
   171 - (void)dismissView {
   181     [[AudioManagerController mainManager] playClickSound];
   172     [[AudioManagerController mainManager] playClickSound];
   182     [self dismissViewControllerAnimated:YES completion:nil];
   173     [self dismissViewControllerAnimated:YES completion:nil];
   183 }
   174 }
   184 
   175 
   185 #pragma mark -
   176 #pragma mark -
   186 #pragma mark Memory management
   177 #pragma mark Memory management
   187 -(void) didReceiveMemoryWarning {
   178 - (void)didReceiveMemoryWarning {
   188     // Releases the view if it doesn't have a superview.
   179     // Releases the view if it doesn't have a superview.
   189     [super didReceiveMemoryWarning];
   180     [super didReceiveMemoryWarning];
   190     self.statsArray = nil;
   181     self.statsArray = nil;
   191 }
   182 }
   192 
   183 
   193 -(void) dealloc {
       
   194     releaseAndNil(statsArray);
       
   195     [super dealloc];
       
   196 }
       
   197 
   184 
   198 
   185 
   199 @end
   186 @end
   200 
   187