project_files/HedgewarsMobile/Classes/WeaponSettingsViewController.m
branchhedgeroid
changeset 6224 42b256eca362
parent 6103 55ecfbf834e3
child 6700 e04da46ee43c
equal deleted inserted replaced
6055:88cfcd9161d3 6224:42b256eca362
    40                                                                   target:self
    40                                                                   target:self
    41                                                                   action:@selector(toggleEdit:)];
    41                                                                   action:@selector(toggleEdit:)];
    42     self.navigationItem.rightBarButtonItem = editButton;
    42     self.navigationItem.rightBarButtonItem = editButton;
    43     [editButton release];
    43     [editButton release];
    44 
    44 
       
    45     self.navigationItem.title = @"List of weapons";
    45 }
    46 }
    46 
    47 
    47 -(void) viewWillAppear:(BOOL) animated {
    48 -(void) viewWillAppear:(BOOL) animated {
    48     [super viewWillAppear:animated];
    49     [super viewWillAppear:animated];
    49 
    50 
    77 }
    78 }
    78 
    79 
    79 -(void) addWeapon:(id) sender {
    80 -(void) addWeapon:(id) sender {
    80     NSString *fileName = [[NSString alloc] initWithFormat:@"Weapon %u.plist", [self.listOfWeapons count]];
    81     NSString *fileName = [[NSString alloc] initWithFormat:@"Weapon %u.plist", [self.listOfWeapons count]];
    81 
    82 
    82     createWeaponNamed([fileName stringByDeletingPathExtension], 0);
    83     [CreationChamber createWeaponNamed:[fileName stringByDeletingPathExtension]];
    83 
    84 
    84     [self.listOfWeapons addObject:fileName];
    85     [self.listOfWeapons addObject:fileName];
    85 
    86 
    86     // order the array alphabetically, so schemes will keep their position
    87     // order the array alphabetically, so schemes will keep their position
    87     [self.listOfWeapons sortUsingSelector:@selector(compare:)];
    88     [self.listOfWeapons sortUsingSelector:@selector(compare:)];
   125     NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]];
   126     NSString *schemeFile = [[NSString alloc] initWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]];
   126     [[NSFileManager defaultManager] removeItemAtPath:schemeFile error:NULL];
   127     [[NSFileManager defaultManager] removeItemAtPath:schemeFile error:NULL];
   127     [schemeFile release];
   128     [schemeFile release];
   128 
   129 
   129     [self.listOfWeapons removeObjectAtIndex:row];
   130     [self.listOfWeapons removeObjectAtIndex:row];
   130     [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   131     [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
   131 }
   132 }
   132 
   133 
   133 #pragma mark -
   134 #pragma mark -
   134 #pragma mark Table view delegate
   135 #pragma mark Table view delegate
   135 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   136 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   143     // this must be set so childController can load the correct plist
   144     // this must be set so childController can load the correct plist
   144     childController.weaponName = [selectedWeaponFile stringByDeletingPathExtension];
   145     childController.weaponName = [selectedWeaponFile stringByDeletingPathExtension];
   145     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   146     [childController.tableView setContentOffset:CGPointMake(0,0) animated:NO];
   146 
   147 
   147     [self.navigationController pushViewController:childController animated:YES];
   148     [self.navigationController pushViewController:childController animated:YES];
       
   149     [tableView deselectRowAtIndexPath:indexPath animated:YES];
   148 }
   150 }
   149 
   151 
   150 
   152 
   151 #pragma mark -
   153 #pragma mark -
   152 #pragma mark Memory management
   154 #pragma mark Memory management