project_files/HedgewarsMobile/Classes/GravesViewController.m
changeset 3697 d5b30d6373fc
parent 3662 a44406f4369b
child 3829 81db3c85784b
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    24 -(void) viewDidLoad {
    24 -(void) viewDidLoad {
    25     [super viewDidLoad];
    25     [super viewDidLoad];
    26 
    26 
    27     // load all the grave names and store them into graveArray
    27     // load all the grave names and store them into graveArray
    28     self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
    28     self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
    29     
    29 
    30     self.title = NSLocalizedString(@"Choose hedgehog graves",@"");
    30     self.title = NSLocalizedString(@"Choose hedgehog graves",@"");
    31 }
    31 }
    32 
    32 
    33 -(void) viewWillAppear:(BOOL)animated {
    33 -(void) viewWillAppear:(BOOL)animated {
    34     [super viewWillAppear:animated];
    34     [super viewWillAppear:animated];
    49 }
    49 }
    50 
    50 
    51 // Customize the appearance of table view cells.
    51 // Customize the appearance of table view cells.
    52 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    52 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    53     static NSString *CellIdentifier = @"Cell";
    53     static NSString *CellIdentifier = @"Cell";
    54     
    54 
    55     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    55     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    56     if (cell == nil)
    56     if (cell == nil)
    57         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    57         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    58     
    58 
    59     NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
    59     NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
    60     cell.textLabel.text = [grave stringByDeletingPathExtension];
    60     cell.textLabel.text = [grave stringByDeletingPathExtension];
    61     
    61 
    62     if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
    62     if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
    63         cell.accessoryType = UITableViewCellAccessoryCheckmark;
    63         cell.accessoryType = UITableViewCellAccessoryCheckmark;
    64         self.lastIndexPath = indexPath;
    64         self.lastIndexPath = indexPath;
    65     } else {
    65     } else {
    66         cell.accessoryType = UITableViewCellAccessoryNone;
    66         cell.accessoryType = UITableViewCellAccessoryNone;
    67     }
    67     }
    68 
    68 
    69     NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
    69     NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
    70     // because we also have multi frame graves, let's take the first one only
    70     // because we also have multi frame graves, let's take the first one only
    71     UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
    71     UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
    72     [graveFilePath release];        
    72     [graveFilePath release];
    73     cell.imageView.image = graveSprite;
    73     cell.imageView.image = graveSprite;
    74     [graveSprite release];
    74     [graveSprite release];
    75     
    75 
    76     return cell;
    76     return cell;
    77 }
    77 }
    78 
    78 
    79 
    79 
    80 #pragma mark -
    80 #pragma mark -
    81 #pragma mark Table view delegate
    81 #pragma mark Table view delegate
    82 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    82 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    83     int newRow = [indexPath row];
    83     int newRow = [indexPath row];
    84     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
    84     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
    85     
    85 
    86     if (newRow != oldRow) {
    86     if (newRow != oldRow) {
    87         [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
    87         [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
    88         
    88 
    89         // tell our boss to write this new stuff on disk
    89         // tell our boss to write this new stuff on disk
    90         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
    90         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
    91         
    91 
    92         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
    92         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
    93         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
    93         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
    94         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
    94         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
    95         oldCell.accessoryType = UITableViewCellAccessoryNone;
    95         oldCell.accessoryType = UITableViewCellAccessoryNone;
    96         self.lastIndexPath = indexPath;
    96         self.lastIndexPath = indexPath;