project_files/HedgewarsMobile/Classes/SingleTeamViewController.m
branchios-revival
changeset 11183 b2112ed988cb
parent 10108 c68cf030eded
child 11217 e68b3e392091
equal deleted inserted replaced
11182:55f20efae2e4 11183:b2112ed988cb
   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;
   330             default:
   346             default:
   331                 DLog(@"Nope");
   347                 DLog(@"Nope");
   332                 break;
   348                 break;
   333         }
   349         }
   334     } else {
   350     } else {
   335         EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   351         if (section == 1 && row == HW_getMaxNumberOfHogs()) {
   336         [cell replyKeyboard];
   352             // 'Select one hat for all hogs' selected
   337         [aTableView deselectRowAtIndexPath:indexPath animated:NO];
   353             [self showHogHatViewControllerForHogIndex:-1];
       
   354         } else {
       
   355             EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
       
   356             [cell replyKeyboard];
       
   357             [aTableView deselectRowAtIndexPath:indexPath animated:NO];
       
   358         }
   338     }
   359     }
   339 
   360 
   340 }
   361 }
   341 
   362 
   342 // action to perform when you want to change a hog hat
   363 // action to perform when you want to change a hog hat
   343 -(void) tableView:(UITableView *)aTableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
   364 -(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
   365     // if we are editing the field undo any change before proceeding
   352     EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   366     EditableCellView *cell = (EditableCellView *)[aTableView cellForRowAtIndexPath:indexPath];
   353     [cell cancel:nil];
   367     [cell cancel:nil];
   354 
   368     
       
   369     [self showHogHatViewControllerForHogIndex:[indexPath row]];
       
   370 }
       
   371 
       
   372 - (void)showHogHatViewControllerForHogIndex:(NSInteger)hogIndex
       
   373 {
       
   374     if (nil == hogHatViewController)
       
   375         hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   376     
       
   377     // cache the dictionary file of the team, so that other controllers can modify it
       
   378     hogHatViewController.teamDictionary = self.teamDictionary;
       
   379     hogHatViewController.selectedHog = hogIndex;
       
   380     
   355     [self.navigationController pushViewController:hogHatViewController animated:YES];
   381     [self.navigationController pushViewController:hogHatViewController animated:YES];
   356 }
   382 }
   357 
       
   358 
   383 
   359 #pragma mark -
   384 #pragma mark -
   360 #pragma mark Memory management
   385 #pragma mark Memory management
   361 -(void) didReceiveMemoryWarning {
   386 -(void) didReceiveMemoryWarning {
   362     [super didReceiveMemoryWarning];
   387     [super didReceiveMemoryWarning];