cocoaTouch/GravesViewController.m
changeset 3340 96dd168b080b
parent 3339 d558bc5a73c5
child 3352 ac5d14a35482
equal deleted inserted replaced
3339:d558bc5a73c5 3340:96dd168b080b
     4 //
     4 //
     5 //  Created by Vittorio on 02/04/10.
     5 //  Created by Vittorio on 02/04/10.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
     7 //
     7 //
     8 
     8 
     9 #import "HogHatViewController.h"
     9 #import "GravesViewController.h"
    10 #import "CommodityFunctions.h"
    10 #import "CommodityFunctions.h"
    11 
    11 
    12 
    12 
    13 @implementation GravesViewController
    13 @implementation GravesViewController
    14 @synthesize teamDictionary, graveArray, graveSprites, lastIndexPath;
    14 @synthesize teamDictionary, graveArray, graveSprites, lastIndexPath;
    25     [super viewDidLoad];
    25     [super viewDidLoad];
    26 
    26 
    27     // load all the voices names and store them into voiceArray
    27     // load all the voices names and store them into voiceArray
    28     NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
    28     NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
    29     self.graveArray = array;
    29     self.graveArray = array;
    30     [array release];
    30     
    31 
    31     NSMutableArray *sprites = [[NSMutableArray alloc] initWithCapacity:[graveArray count]];
    32     NSMutableArray *sprites = [[NSMutableArray alloc] initWithCapacity:[graveArray count];
       
    33     for (NSString *graveName in graveArray) {
    32     for (NSString *graveName in graveArray) {
    34 	NSString *gravePath = [[NSString alloc] initWithFormat@"%@/%@",GRAVES_DIRECTORY(),graveName];
    33         NSString *gravePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),graveName];
    35 	UIImage *image = [[UIImage alloc] initWithContentsOfFile:gravePath];
    34         UIImage *image = [[UIImage alloc] initWithContentsOfFile:gravePath];
    36 	[gravePath release];
    35         [gravePath release];
    37 	[sprites addObject:image];
    36         
    38 	[image release];
    37         // because we also have multi frame graves, let's take the first one only
       
    38         if (image.size.height > 32) {
       
    39             CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
       
    40             CGImageRef cgImage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
       
    41             [image release];
       
    42             image = [[UIImage alloc] initWithCGImage:cgImage];
       
    43             CGImageRelease(cgImage);
       
    44         }
       
    45         [sprites addObject:image];
       
    46         [image release];
    39     }
    47     }
    40     self.graveSprites = sprites;
    48     self.graveSprites = sprites;
    41     [sprites release];
    49     [sprites release];
    42 }
    50 }
    43 
    51 
    86     }
    94     }
    87     
    95     
    88     NSString *grave = [[graveArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
    96     NSString *grave = [[graveArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
    89     cell.textLabel.text = grave;
    97     cell.textLabel.text = grave;
    90     
    98     
    91     if ([grave isEqualToString:[hog objectForKey:@"grave"]]) {
    99     if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) {
    92         cell.accessoryType = UITableViewCellAccessoryCheckmark;
   100         cell.accessoryType = UITableViewCellAccessoryCheckmark;
    93         self.lastIndexPath = indexPath;
   101         self.lastIndexPath = indexPath;
    94     } else {
   102     } else {
    95         cell.accessoryType = UITableViewCellAccessoryNone;
   103         cell.accessoryType = UITableViewCellAccessoryNone;
    96     }
   104     }
    97     
   105     
    98     cell.imageView.image = [spriteArray objectAtIndex:[indexPath row]]:
   106     cell.imageView.image = [graveSprites objectAtIndex:[indexPath row]];
    99     return cell;
   107     return cell;
   100 }
   108 }
   101 
   109 
   102 
   110 
   103 /*
   111 /*
   145 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   153 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   146     int newRow = [indexPath row];
   154     int newRow = [indexPath row];
   147     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   155     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   148     
   156     
   149     if (newRow != oldRow) {
   157     if (newRow != oldRow) {
   150 	[teamDictionary setObject:[graveArray objectAtIndex:newRow] forKey:@"grave"];
   158         [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
   151         
   159         
   152         // tell our boss to write this new stuff on disk
   160         // tell our boss to write this new stuff on disk
   153         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
   161         [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
   154         [self.tableView reloadData];
   162         [self.tableView reloadData];
   155         
   163         
   156         self.lastIndexPath = indexPath;
   164         self.lastIndexPath = indexPath;
   157         [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   165         [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   158      
   166     }
   159     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   167     [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
   160     [self.navigationController popViewControllerAnimated:YES];
   168     [self.navigationController popViewControllerAnimated:YES];
   161 }
   169 }
   162 
   170 
   163 
   171 
   172 - (void)viewDidUnload {
   180 - (void)viewDidUnload {
   173     [super viewDidUnload];
   181     [super viewDidUnload];
   174     self.lastIndexPath = nil;
   182     self.lastIndexPath = nil;
   175     self.teamDictionary = nil;
   183     self.teamDictionary = nil;
   176     self.graveArray = nil;
   184     self.graveArray = nil;
   177     self.spriteArray = nil;
   185     self.graveSprites = nil;
   178 }
   186 }
   179 
   187 
   180 - (void)dealloc {
   188 - (void)dealloc {
   181     [spriteArray release];
   189     [graveSprites release];
   182     [graveArray release];
   190     [graveArray release];
   183     [teamDictionary release];
   191     [teamDictionary release];
   184     [lastIndexPath release];
   192     [lastIndexPath release];
   185     [super dealloc];
   193     [super dealloc];
   186 }
   194 }