project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
changeset 3697 d5b30d6373fc
parent 3662 a44406f4369b
child 3703 12d17c6e8855
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    20 
    20 
    21 #pragma mark -
    21 #pragma mark -
    22 #pragma mark View lifecycle
    22 #pragma mark View lifecycle
    23 -(void) viewDidLoad {
    23 -(void) viewDidLoad {
    24     [super viewDidLoad];
    24     [super viewDidLoad];
    25     
    25 
    26     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    26     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    27     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
    27     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
    28     isFirstLoad = YES;
    28     isFirstLoad = YES;
    29 }
    29 }
    30 
    30 
    45             [array addObject:dict];
    45             [array addObject:dict];
    46             [dict release];
    46             [dict release];
    47         }
    47         }
    48         self.listOfTeams = array;
    48         self.listOfTeams = array;
    49         [array release];
    49         [array release];
    50         
    50 
    51         NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil];
    51         NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil];
    52         self.listOfSelectedTeams = emptyArray;
    52         self.listOfSelectedTeams = emptyArray;
    53         [emptyArray release];
    53         [emptyArray release];
    54         isFirstLoad = NO;
    54         isFirstLoad = NO;
    55     }
    55     }
    85 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    85 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    86     static NSString *CellIdentifier0 = @"Cell0";
    86     static NSString *CellIdentifier0 = @"Cell0";
    87     static NSString *CellIdentifier1 = @"Cell1";
    87     static NSString *CellIdentifier1 = @"Cell1";
    88     NSInteger section = [indexPath section];
    88     NSInteger section = [indexPath section];
    89     UITableViewCell *cell;
    89     UITableViewCell *cell;
    90     
    90 
    91     if (section == 0) {
    91     if (section == 0) {
    92         cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    92         cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0];
    93         if (cell == nil) {
    93         if (cell == nil) {
    94             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
    94             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
    95 
    95 
    96             UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)];
    96             UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)];
    97             numberButton.tag = NUMBERBUTTON_TAG;
    97             numberButton.tag = NUMBERBUTTON_TAG;
    98             [cell addSubview:numberButton];
    98             [cell addSubview:numberButton];
    99             [numberButton release];
    99             [numberButton release];
   100             
   100 
   101             SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)];
   101             SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)];
   102             squareButton.tag = SQUAREBUTTON_TAG;
   102             squareButton.tag = SQUAREBUTTON_TAG;
   103             [cell addSubview:squareButton];
   103             [cell addSubview:squareButton];
   104             [squareButton release];
   104             [squareButton release];
   105             
   105 
   106             UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)];
   106             UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)];
   107             label.textAlignment = UITextAlignmentLeft;
   107             label.textAlignment = UITextAlignmentLeft;
   108             label.backgroundColor = [UIColor clearColor];
   108             label.backgroundColor = [UIColor clearColor];
   109             label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize] + 2];
   109             label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize] + 2];
   110             label.tag = LABEL_TAG;
   110             label.tag = LABEL_TAG;
   111             [cell.contentView addSubview:label];
   111             [cell.contentView addSubview:label];
   112             [label release];
   112             [label release];
   113         }
   113         }
   114         
   114 
   115         NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]];
   115         NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]];
   116         
   116 
   117         UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG];
   117         UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG];
   118         cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension];
   118         cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension];
   119         
   119 
   120         HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG];
   120         HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG];
   121         [numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]];
   121         [numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]];
   122         numberButton.ownerDictionary = selectedRow;
   122         numberButton.ownerDictionary = selectedRow;
   123         
   123 
   124         SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG];
   124         SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG];
   125         [squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]];
   125         [squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]];
   126         squareButton.ownerDictionary = selectedRow;
   126         squareButton.ownerDictionary = selectedRow;
   127         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   127         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   128             cellLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1];
   128             cellLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1];
   129         }
   129         }
   130     } else {
   130     } else {
   131         cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
   131         cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1];
   132         if (cell == nil) 
   132         if (cell == nil)
   133             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
   133             cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease];
   134         
   134 
   135         cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension];
   135         cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension];
   136         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   136         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   137             cell.textLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1 ];
   137             cell.textLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1 ];
   138         }
   138         }
   139     }
   139     }
   140     
   140 
   141     return cell;
   141     return cell;
   142 }
   142 }
   143 
   143 
   144 
   144 
   145 #pragma mark -
   145 #pragma mark -
   151     if (section == 0) {
   151     if (section == 0) {
   152         [self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]];
   152         [self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]];
   153         [self.listOfSelectedTeams removeObjectAtIndex:row];
   153         [self.listOfSelectedTeams removeObjectAtIndex:row];
   154     } else {
   154     } else {
   155         [self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]];
   155         [self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]];
   156         [self.listOfTeams removeObjectAtIndex:row];      
   156         [self.listOfTeams removeObjectAtIndex:row];
   157     }
   157     }
   158     [aTableView reloadData];
   158     [aTableView reloadData];
   159 }
   159 }
   160 
   160 
   161 
   161