project_files/HedgewarsMobile/Classes/SingleTeamViewController.m
branchqmlfrontend
changeset 11408 b894922d58cc
parent 11278 68a0df07382b
child 12877 00215a7ec5f5
equal deleted inserted replaced
11076:fcbdee9cdd74 11408:b894922d58cc
   144     switch (section) {
   144     switch (section) {
   145         case 0: // team name
   145         case 0: // team name
   146             rows = 1;
   146             rows = 1;
   147             break;
   147             break;
   148         case 1: // team members
   148         case 1: // team members
   149             rows = HW_getMaxNumberOfHogs();
   149             rows = HW_getMaxNumberOfHogs() + 1; // one for 'Select one hat for all hogs' cell
   150             break;
   150             break;
   151         case 2: // team details
   151         case 2: // team details
   152             rows = [self.secondaryItems count];
   152             rows = [self.secondaryItems count];
   153             break;
   153             break;
   154         default:
   154         default:
   178 
   178 
   179 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   179 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   180     static NSString *CellIdentifier0 = @"Cell0";
   180     static NSString *CellIdentifier0 = @"Cell0";
   181     static NSString *CellIdentifier1 = @"Cell1";
   181     static NSString *CellIdentifier1 = @"Cell1";
   182     static NSString *CellIdentifier2 = @"Cell2";
   182     static NSString *CellIdentifier2 = @"Cell2";
       
   183     static NSString *CellIdentifierDefault = @"CellDefault";
   183 
   184 
   184     NSArray *hogArray;
   185     NSArray *hogArray;
   185     UITableViewCell *cell = nil;
   186     UITableViewCell *cell = nil;
   186     EditableCellView *editableCell = nil;
   187     EditableCellView *editableCell = nil;
   187     NSInteger row = [indexPath row];
   188     NSInteger row = [indexPath row];
   202             editableCell.textField.text = self.teamName;
   203             editableCell.textField.text = self.teamName;
   203 
   204 
   204             cell = editableCell;
   205             cell = editableCell;
   205             break;
   206             break;
   206         case 1:
   207         case 1:
       
   208             if ([indexPath row] == HW_getMaxNumberOfHogs())
       
   209             {
       
   210                 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifierDefault];
       
   211                 if (cell == nil)
       
   212                 {
       
   213                     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
       
   214                                                    reuseIdentifier:CellIdentifierDefault] autorelease];
       
   215                     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
       
   216                 }
       
   217                 
       
   218                 cell.textLabel.text = NSLocalizedString(@"Select one hat for all hogs", nil);
       
   219                 
       
   220                 break;
       
   221             }
       
   222             
   207             editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
   223             editableCell = (EditableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
   208             if (editableCell == nil) {
   224             if (editableCell == nil) {
   209                 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
   225                 editableCell = [[[EditableCellView alloc] initWithStyle:UITableViewCellStyleDefault
   210                                                reuseIdentifier:CellIdentifier1] autorelease];
   226                                                reuseIdentifier:CellIdentifier1] autorelease];
   211                 editableCell.delegate = self;
   227                 editableCell.delegate = self;
   212                 editableCell.tag = [indexPath row];
   228             }
   213             }
   229             editableCell.tag = [indexPath row];
   214 
   230 
   215             hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
   231             hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
   216 
   232 
   217             // draw the hat on top of the hog
   233             // draw the hat on top of the hog
   218             NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [[hogArray objectAtIndex:row] objectForKey:@"hat"]];
   234             NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [[hogArray objectAtIndex:row] objectForKey:@"hat"]];
   288 #pragma mark Table view delegate
   304 #pragma mark Table view delegate
   289 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   305 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   290     NSInteger row = [indexPath row];
   306     NSInteger row = [indexPath row];
   291     NSInteger section = [indexPath section];
   307     NSInteger section = [indexPath section];
   292 
   308 
   293     if (2 == section) {
   309     if (2 == section)
   294         switch (row) {
   310     {
       
   311         switch (row)
       
   312         {
   295             case 0: // grave
   313             case 0: // grave
   296                 if (nil == gravesViewController)
   314             {
   297                     gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped];
   315                 GravesViewController *gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped];
   298 
   316 
   299                 [gravesViewController setTeamDictionary:teamDictionary];
   317                 [gravesViewController setTeamDictionary:teamDictionary];
   300                 [self.navigationController pushViewController:gravesViewController animated:YES];
   318                 [self.navigationController pushViewController:gravesViewController animated:YES];
   301                 break;
   319                 [gravesViewController release];
       
   320                 break;
       
   321             }
   302             case 1: // voice
   322             case 1: // voice
   303                 if (nil == voicesViewController)
   323             {
   304                     voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped];
   324                 VoicesViewController *voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped];
   305 
   325 
   306                 [voicesViewController setTeamDictionary:teamDictionary];
   326                 [voicesViewController setTeamDictionary:teamDictionary];
   307                 [self.navigationController pushViewController:voicesViewController animated:YES];
   327                 [self.navigationController pushViewController:voicesViewController animated:YES];
   308                 break;
   328                 [voicesViewController release];
       
   329                 break;
       
   330             }
   309             case 2: // fort
   331             case 2: // fort
   310                 if (nil == fortsViewController)
   332             {
   311                     fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
   333                 FortsViewController *fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
   312 
   334 
   313                 [fortsViewController setTeamDictionary:teamDictionary];
   335                 [fortsViewController setTeamDictionary:teamDictionary];
   314                 [self.navigationController pushViewController:fortsViewController animated:YES];
   336                 [self.navigationController pushViewController:fortsViewController animated:YES];
   315                 break;
   337                 [fortsViewController release];
       
   338                 break;
       
   339             }
   316             case 3: // flag
   340             case 3: // flag
   317                 if (nil == flagsViewController)
   341             {
   318                     flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
   342                 FlagsViewController *flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
   319 
   343 
   320                 [flagsViewController setTeamDictionary:teamDictionary];
   344                 [flagsViewController setTeamDictionary:teamDictionary];
   321                 [self.navigationController pushViewController:flagsViewController animated:YES];
   345                 [self.navigationController pushViewController:flagsViewController animated:YES];
   322                 break;
   346                 [flagsViewController release];
       
   347                 break;
       
   348             }
   323             case 4: // level
   349             case 4: // level
   324                 if (nil == levelViewController)
   350             {
   325                     levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped];
   351                 LevelViewController *levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped];
   326 
   352 
   327                 [levelViewController setTeamDictionary:teamDictionary];
   353                 [levelViewController setTeamDictionary:teamDictionary];
   328                 [self.navigationController pushViewController:levelViewController animated:YES];
   354                 [self.navigationController pushViewController:levelViewController animated:YES];
   329                 break;
   355                 [levelViewController release];
       
   356                 break;
       
   357             }
   330             default:
   358             default:
   331                 DLog(@"Nope");
   359                 DLog(@"Nope");
   332                 break;
   360                 break;
   333         }
   361         }
   334     } else {
   362     } else {
   335         EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   363         if (section == 1 && row == HW_getMaxNumberOfHogs()) {
   336         [cell replyKeyboard];
   364             // 'Select one hat for all hogs' selected
   337         [aTableView deselectRowAtIndexPath:indexPath animated:NO];
   365             [self showHogHatViewControllerForHogIndex:-1];
       
   366         } else {
       
   367             EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
       
   368             [cell replyKeyboard];
       
   369             [aTableView deselectRowAtIndexPath:indexPath animated:NO];
       
   370         }
   338     }
   371     }
   339 
   372 
   340 }
   373 }
   341 
   374 
   342 // action to perform when you want to change a hog hat
   375 // action to perform when you want to change a hog hat
   343 -(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
   376 -(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
   344     if (nil == hogHatViewController)
       
   345         hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   346 
       
   347     // cache the dictionary file of the team, so that other controllers can modify it
       
   348     hogHatViewController.teamDictionary = self.teamDictionary;
       
   349     hogHatViewController.selectedHog = [indexPath row];
       
   350 
       
   351     // if we are editing the field undo any change before proceeding
   377     // if we are editing the field undo any change before proceeding
   352     EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   378     EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   353     [cell cancel:nil];
   379     [cell cancel:nil];
   354 
   380     
       
   381     [self showHogHatViewControllerForHogIndex:[indexPath row]];
       
   382 }
       
   383 
       
   384 - (void)showHogHatViewControllerForHogIndex:(NSInteger)hogIndex
       
   385 {
       
   386     HogHatViewController *hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   387     
       
   388     // cache the dictionary file of the team, so that other controllers can modify it
       
   389     hogHatViewController.teamDictionary = self.teamDictionary;
       
   390     hogHatViewController.selectedHog = hogIndex;
       
   391     
   355     [self.navigationController pushViewController:hogHatViewController animated:YES];
   392     [self.navigationController pushViewController:hogHatViewController animated:YES];
   356 }
   393     [hogHatViewController release];
   357 
   394 }
   358 
   395 
   359 #pragma mark -
   396 #pragma mark -
   360 #pragma mark Memory management
   397 #pragma mark Memory management
   361 -(void) didReceiveMemoryWarning {
   398 -(void) didReceiveMemoryWarning {
   362     [super didReceiveMemoryWarning];
   399     [super didReceiveMemoryWarning];
   363     if (hogHatViewController.view.superview == nil)
       
   364         hogHatViewController = nil;
       
   365     if (gravesViewController.view.superview == nil)
       
   366         gravesViewController = nil;
       
   367     if (voicesViewController.view.superview == nil)
       
   368         voicesViewController = nil;
       
   369     if (fortsViewController.view.superview == nil)
       
   370         fortsViewController = nil;
       
   371     if (flagsViewController.view.superview == nil)
       
   372         flagsViewController = nil;
       
   373     if (levelViewController.view.superview == nil)
       
   374         levelViewController = nil;
       
   375     MSG_MEMCLEAN();
   400     MSG_MEMCLEAN();
   376 }
   401 }
   377 
   402 
   378 -(void) viewDidUnload {
   403 -(void) viewDidUnload {
   379     [[NSNotificationCenter defaultCenter] removeObserver:self];
       
   380     self.teamDictionary = nil;
   404     self.teamDictionary = nil;
   381     self.teamName = nil;
   405     self.teamName = nil;
   382     self.normalHogSprite = nil;
   406     self.normalHogSprite = nil;
   383     self.secondaryItems = nil;
   407     self.secondaryItems = nil;
   384     self.moreSecondaryItems = nil;
   408     self.moreSecondaryItems = nil;
   385     hogHatViewController = nil;
       
   386     gravesViewController = nil;
       
   387     voicesViewController = nil;
       
   388     flagsViewController = nil;
       
   389     fortsViewController = nil;
       
   390     levelViewController = nil;
       
   391     MSG_DIDUNLOAD();
   409     MSG_DIDUNLOAD();
   392     [super viewDidUnload];
   410     [super viewDidUnload];
   393 }
   411 }
   394 
   412 
   395 -(void) dealloc {
   413 -(void) dealloc
       
   414 {
       
   415     [[NSNotificationCenter defaultCenter] removeObserver:self];
   396     releaseAndNil(teamDictionary);
   416     releaseAndNil(teamDictionary);
   397     releaseAndNil(teamName);
   417     releaseAndNil(teamName);
   398     releaseAndNil(normalHogSprite);
   418     releaseAndNil(normalHogSprite);
   399     releaseAndNil(secondaryItems);
   419     releaseAndNil(secondaryItems);
   400     releaseAndNil(moreSecondaryItems);
   420     releaseAndNil(moreSecondaryItems);
   401     releaseAndNil(hogHatViewController);
       
   402     releaseAndNil(gravesViewController);
       
   403     releaseAndNil(fortsViewController);
       
   404     releaseAndNil(voicesViewController);
       
   405     releaseAndNil(flagsViewController);
       
   406     releaseAndNil(levelViewController);
       
   407     [super dealloc];
   421     [super dealloc];
   408 }
   422 }
   409 
   423 
   410 
   424 
   411 @end
   425 @end