cocoaTouch/SingleTeamViewController.m
changeset 3374 0d522416d97f
parent 3365 37ac593e9027
child 3479 972ae3ec178a
equal deleted inserted replaced
3373:c1ff724a5c34 3374:0d522416d97f
    17 #import "UIImageExtra.h"
    17 #import "UIImageExtra.h"
    18 
    18 
    19 #define TEAMNAME_TAG 1234
    19 #define TEAMNAME_TAG 1234
    20 
    20 
    21 @implementation SingleTeamViewController
    21 @implementation SingleTeamViewController
    22 @synthesize teamDictionary, hatArray, secondaryItems, textFieldBeingEdited, teamName;
    22 @synthesize teamDictionary, normalHogSprite, secondaryItems, textFieldBeingEdited, teamName;
    23 
    23 
    24 
    24 
    25 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    25 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    26 	return rotationManager(interfaceOrientation);
    26 	return rotationManager(interfaceOrientation);
    27 }
    27 }
   104                       NSLocalizedString(@"Flag",@""),
   104                       NSLocalizedString(@"Flag",@""),
   105                       NSLocalizedString(@"Level",@""),nil];
   105                       NSLocalizedString(@"Level",@""),nil];
   106     self.secondaryItems = array;
   106     self.secondaryItems = array;
   107     [array release];
   107     [array release];
   108 
   108 
       
   109     // load the base hog image, drawing will occure in cellForRow...
       
   110     NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
       
   111     UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
       
   112     [normalHogFile release];
       
   113     self.normalHogSprite = hogSprite;
       
   114     [hogSprite release];
       
   115     
   109     // listen if any childController modifies the plist and write it if needed
   116     // listen if any childController modifies the plist and write it if needed
   110     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setWriteNeeded) name:@"setWriteNeedTeams" object:nil];
   117     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setWriteNeeded) name:@"setWriteNeedTeams" object:nil];
   111     isWriteNeeded = NO;
   118     isWriteNeeded = NO;
   112 }
   119 }
   113 
   120 
   123     self.teamDictionary = teamDict;
   130     self.teamDictionary = teamDict;
   124     [teamDict release];
   131     [teamDict release];
   125 	[teamFile release];
   132 	[teamFile release];
   126     
   133     
   127     self.teamName = self.title;
   134     self.teamName = self.title;
   128     
       
   129     // load the images of the hat for aach hog
       
   130     NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
       
   131     UIImage *normalHogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
       
   132     [normalHogFile release];
       
   133     
       
   134     NSArray *hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
       
   135     NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[hogArray count]];
       
   136     for (NSDictionary *hog in hogArray) {
       
   137         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png",HATS_DIRECTORY(),[hog objectForKey:@"hat"]];
       
   138 
       
   139         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
       
   140         [hatFile release];        
       
   141         
       
   142         [array addObject:[normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, -5)]];
       
   143         [hatSprite release];
       
   144     }
       
   145     [normalHogSprite release];
       
   146     self.hatArray = array;
       
   147     [array release];
       
   148     
   135     
   149     [self.tableView reloadData];
   136     [self.tableView reloadData];
   150 }
   137 }
   151 
   138 
   152 // write on file if there has been a change
   139 // write on file if there has been a change
   274                 [aTextField release];
   261                 [aTextField release];
   275             }
   262             }
   276             
   263             
   277             hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
   264             hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
   278             
   265             
   279             cell.imageView.image = [self.hatArray objectAtIndex:row];
   266             NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [[hogArray objectAtIndex:row] objectForKey:@"hat"]];
   280             
   267             UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
       
   268             [hatFile release];
       
   269             cell.imageView.image = [self.normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, -5)];
       
   270             [hatSprite release];
       
   271                         
   281             for (UIView *oneView in cell.contentView.subviews) {
   272             for (UIView *oneView in cell.contentView.subviews) {
   282                 if ([oneView isMemberOfClass:[UITextField class]]) {
   273                 if ([oneView isMemberOfClass:[UITextField class]]) {
   283                     // we find the uitextfied and we'll use its tag to understand which one is being edited
   274                     // we find the uitextfied and we'll use its tag to understand which one is being edited
   284                     UITextField *textFieldFound = (UITextField *)oneView;
   275                     UITextField *textFieldFound = (UITextField *)oneView;
   285                     textFieldFound.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
   276                     textFieldFound.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
   419 
   410 
   420 -(void) viewDidUnload {
   411 -(void) viewDidUnload {
   421     self.teamDictionary = nil;
   412     self.teamDictionary = nil;
   422     self.textFieldBeingEdited = nil;
   413     self.textFieldBeingEdited = nil;
   423     self.teamName = nil;
   414     self.teamName = nil;
   424     self.hatArray = nil;
   415     self.normalHogSprite = nil;
   425     self.secondaryItems = nil;
   416     self.secondaryItems = nil;
   426     hogHatViewController = nil;
   417     hogHatViewController = nil;
   427     flagsViewController = nil;
   418     flagsViewController = nil;
   428     fortsViewController = nil;
   419     fortsViewController = nil;
   429     gravesViewController = nil;
   420     gravesViewController = nil;
   433 
   424 
   434 -(void) dealloc {
   425 -(void) dealloc {
   435     [teamDictionary release];
   426     [teamDictionary release];
   436     [textFieldBeingEdited release];
   427     [textFieldBeingEdited release];
   437     [teamName release];
   428     [teamName release];
   438     [hatArray release];
   429     [normalHogSprite release];
   439     [secondaryItems release];
   430     [secondaryItems release];
   440     [hogHatViewController release];
   431     [hogHatViewController release];
   441     [fortsViewController release];
   432     [fortsViewController release];
   442     [gravesViewController release];
   433     [gravesViewController release];
   443     [flagsViewController release];
   434     [flagsViewController release];