project_files/HedgewarsMobile/Classes/GravesViewController.m
branchios-develop
changeset 12877 00215a7ec5f5
parent 11148 064a53861759
equal deleted inserted replaced
12876:2c06b1120749 12877:00215a7ec5f5
    21 
    21 
    22 
    22 
    23 @implementation GravesViewController
    23 @implementation GravesViewController
    24 @synthesize teamDictionary, graveArray, lastIndexPath;
    24 @synthesize teamDictionary, graveArray, lastIndexPath;
    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 #pragma mark -
    30 #pragma mark -
    31 #pragma mark View lifecycle
    31 #pragma mark View lifecycle
    32 -(void) viewDidLoad {
    32 - (void)viewDidLoad {
    33     [super viewDidLoad];
    33     [super viewDidLoad];
    34 
    34 
    35     // load all the grave names and store them into graveArray
    35     // load all the grave names and store them into graveArray
    36     self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
    36     self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
    37 
    37 
    38     self.title = NSLocalizedString(@"Choose hedgehog graves",@"");
    38     self.title = NSLocalizedString(@"Choose hedgehog graves",@"");
    39 }
    39 }
    40 
    40 
    41 -(void) viewWillAppear:(BOOL)animated {
    41 - (void)viewWillAppear:(BOOL)animated {
    42     [super viewWillAppear:animated];
    42     [super viewWillAppear:animated];
    43     [self.tableView reloadData];
    43     [self.tableView reloadData];
    44     // this moves the tableview to the top
    44     // this moves the tableview to the top
    45     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    45     [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    46 }
    46 }
    47 
    47 
    48 
    48 
    49 #pragma mark -
    49 #pragma mark -
    50 #pragma mark Table view data source
    50 #pragma mark Table view data source
    51 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    51 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    52     return 1;
    52     return 1;
    53 }
    53 }
    54 
    54 
    55 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    55 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    56     return [self.graveArray count];
    56     return [self.graveArray count];
    57 }
    57 }
    58 
    58 
    59 // Customize the appearance of table view cells.
    59 // Customize the appearance of table view cells.
    60 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    60 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    61     static NSString *CellIdentifier = @"Cell";
    61     static NSString *CellIdentifier = @"Cell";
    62 
    62 
    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];
    66 
    66 
    67     NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
    67     NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
    68     cell.textLabel.text = [grave stringByDeletingPathExtension];
    68     cell.textLabel.text = [grave stringByDeletingPathExtension];
    69 
    69 
    70     if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
    70     if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
    75     }
    75     }
    76 
    76 
    77     NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
    77     NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
    78     // because we also have multi frame graves, let's take the first one only
    78     // because we also have multi frame graves, let's take the first one only
    79     UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
    79     UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
    80     [graveFilePath release];
       
    81     cell.imageView.image = graveSprite;
    80     cell.imageView.image = graveSprite;
    82     [graveSprite release];
       
    83 
    81 
    84     return cell;
    82     return cell;
    85 }
    83 }
    86 
    84 
    87 
    85 
    88 #pragma mark -
    86 #pragma mark -
    89 #pragma mark Table view delegate
    87 #pragma mark Table view delegate
    90 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    88 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    91     NSInteger newRow = [indexPath row];
    89     NSInteger newRow = [indexPath row];
    92     NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
    90     NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
    93 
    91 
    94     if (newRow != oldRow) {
    92     if (newRow != oldRow) {
    95         [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
    93         [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
   109 }
   107 }
   110 
   108 
   111 
   109 
   112 #pragma mark -
   110 #pragma mark -
   113 #pragma mark Memory management
   111 #pragma mark Memory management
   114 -(void) didReceiveMemoryWarning {
   112 
       
   113 - (void)didReceiveMemoryWarning {
   115     self.lastIndexPath = nil;
   114     self.lastIndexPath = nil;
   116     MSG_MEMCLEAN();
   115     MSG_MEMCLEAN();
   117     [super didReceiveMemoryWarning];
   116     [super didReceiveMemoryWarning];
   118 }
   117 }
   119 
   118 
   120 -(void) viewDidUnload {
       
   121     self.lastIndexPath = nil;
       
   122     self.teamDictionary = nil;
       
   123     self.graveArray = nil;
       
   124     MSG_DIDUNLOAD();
       
   125     [super viewDidUnload];
       
   126 }
       
   127 
       
   128 -(void) dealloc {
       
   129     releaseAndNil(graveArray);
       
   130     releaseAndNil(teamDictionary);
       
   131     releaseAndNil(lastIndexPath);
       
   132     [super dealloc];
       
   133 }
       
   134 
       
   135 
       
   136 @end
   119 @end
   137 
   120