project_files/HedgewarsMobile/Classes/LevelViewController.m
changeset 3697 d5b30d6373fc
parent 3662 a44406f4369b
child 3829 81db3c85784b
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    32                       NSLocalizedString(@"Average",@""),
    32                       NSLocalizedString(@"Average",@""),
    33                       NSLocalizedString(@"Weaky",@""),
    33                       NSLocalizedString(@"Weaky",@""),
    34                       nil];
    34                       nil];
    35     self.levelArray = array;
    35     self.levelArray = array;
    36     [array release];
    36     [array release];
    37     
    37 
    38     self.title = NSLocalizedString(@"Set difficulty level",@"");
    38     self.title = NSLocalizedString(@"Set difficulty level",@"");
    39 }
    39 }
    40 
    40 
    41 - (void)viewWillAppear:(BOOL)animated {
    41 - (void)viewWillAppear:(BOOL)animated {
    42     [super viewWillAppear:animated];
    42     [super viewWillAppear:animated];
    56 }
    56 }
    57 
    57 
    58 // Customize the appearance of table view cells.
    58 // Customize the appearance of table view cells.
    59 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    59 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    60     static NSString *CellIdentifier = @"Cell";
    60     static NSString *CellIdentifier = @"Cell";
    61     
    61 
    62     NSInteger row = [indexPath row];
    62     NSInteger row = [indexPath row];
    63     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    63     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    64     if (cell == nil) {
    64     if (cell == nil) {
    65         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    65         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    66     }
    66     }
    67     
    67 
    68     cell.textLabel.text = [levelArray objectAtIndex:row];
    68     cell.textLabel.text = [levelArray objectAtIndex:row];
    69     NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0];
    69     NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0];
    70     if ([[hog objectForKey:@"level"] intValue] == row) {
    70     if ([[hog objectForKey:@"level"] intValue] == row) {
    71         cell.accessoryType = UITableViewCellAccessoryCheckmark;
    71         cell.accessoryType = UITableViewCellAccessoryCheckmark;
    72         self.lastIndexPath = indexPath;
    72         self.lastIndexPath = indexPath;
    73     } else {
    73     } else {
    74         cell.accessoryType = UITableViewCellAccessoryNone;
    74         cell.accessoryType = UITableViewCellAccessoryNone;
    75     }
    75     }
    76     
    76 
    77     NSString *botlevelPath = [[NSString alloc] initWithFormat:@"%@/%d.png",BOTLEVELS_DIRECTORY(),row];
    77     NSString *botlevelPath = [[NSString alloc] initWithFormat:@"%@/%d.png",BOTLEVELS_DIRECTORY(),row];
    78     UIImage *levelImage = [[UIImage alloc] initWithContentsOfFile:botlevelPath];
    78     UIImage *levelImage = [[UIImage alloc] initWithContentsOfFile:botlevelPath];
    79     [botlevelPath release];
    79     [botlevelPath release];
    80     cell.imageView.image = levelImage;
    80     cell.imageView.image = levelImage;
    81     [levelImage release];
    81     [levelImage release];
    94 
    94 
    95 
    95 
    96 /*
    96 /*
    97 // Override to support editing the table view.
    97 // Override to support editing the table view.
    98 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    98 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    99     
    99 
   100     if (editingStyle == UITableViewCellEditingStyleDelete) {
   100     if (editingStyle == UITableViewCellEditingStyleDelete) {
   101         // Delete the row from the data source
   101         // Delete the row from the data source
   102         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
   102         [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
   103     }   
   103     }
   104     else if (editingStyle == UITableViewCellEditingStyleInsert) {
   104     else if (editingStyle == UITableViewCellEditingStyleInsert) {
   105         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
   105         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
   106     }   
   106     }
   107 }
   107 }
   108 */
   108 */
   109 
   109 
   110 
   110 
   111 /*
   111 /*
   127 #pragma mark -
   127 #pragma mark -
   128 #pragma mark Table view delegate
   128 #pragma mark Table view delegate
   129 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   129 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   130     int newRow = [indexPath row];
   130     int newRow = [indexPath row];
   131     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   131     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   132     
   132 
   133     if (newRow != oldRow) {
   133     if (newRow != oldRow) {
   134         NSMutableArray *hogs = [teamDictionary objectForKey:@"hedgehogs"];
   134         NSMutableArray *hogs = [teamDictionary objectForKey:@"hedgehogs"];
   135         
   135 
   136         for (NSMutableDictionary *hog in hogs) {
   136         for (NSMutableDictionary *hog in hogs) {
   137             [hog setObject:[NSNumber numberWithInt:newRow] forKey:@"level"];
   137             [hog setObject:[NSNumber numberWithInt:newRow] forKey:@"level"];
   138         }
   138         }
   139         
   139 
   140         // tell our boss to write this new stuff on disk
   140         // tell our boss to write this new stuff on disk
   141         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
   141         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
   142         [self.tableView reloadData];
   142         [self.tableView reloadData];
   143         
   143 
   144         self.lastIndexPath = indexPath;
   144         self.lastIndexPath = indexPath;
   145         [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   145         [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   146     }
   146     }
   147     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   147     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   148     [self.navigationController popViewControllerAnimated:YES];
   148     [self.navigationController popViewControllerAnimated:YES];