project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
changeset 3703 12d17c6e8855
parent 3697 d5b30d6373fc
child 3780 7c704e69242e
equal deleted inserted replaced
3701:8c449776ebe6 3703:12d17c6e8855
    28     self.selectedWeapon = @"";
    28     self.selectedWeapon = @"";
    29 
    29 
    30     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    30     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    31         [self.tableView setBackgroundView:nil];
    31         [self.tableView setBackgroundView:nil];
    32         self.view.backgroundColor = [UIColor clearColor];
    32         self.view.backgroundColor = [UIColor clearColor];
    33         self.tableView.separatorColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1];
    33         self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
    34     }
    34     }
    35     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    35     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    36 }
    36 }
    37 
    37 
    38 -(void) viewWillAppear:(BOOL) animated {
    38 -(void) viewWillAppear:(BOOL) animated {
    75     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    75     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    76     if (cell == nil) {
    76     if (cell == nil) {
    77         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    77         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    78     }
    78     }
    79 
    79 
    80     cell.accessoryType = UITableViewCellAccessoryNone;
    80     cell.accessoryView = nil;
    81     if ([indexPath section] == 0) {
    81     if ([indexPath section] == 0) {
    82         cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension];
    82         cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension];
    83         if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) {
    83         if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) {
    84             cell.accessoryType = UITableViewCellAccessoryCheckmark;
    84             UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]];
       
    85             cell.accessoryView = checkbox;
       
    86             [checkbox release];
    85             self.lastIndexPath_sc = indexPath;
    87             self.lastIndexPath_sc = indexPath;
    86         }
    88         }
    87     } else {
    89     } else {
    88         cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension];
    90         cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension];
    89         if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) {
    91         if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) {
    90             cell.accessoryType = UITableViewCellAccessoryCheckmark;
    92             UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]];
       
    93             cell.accessoryView = checkbox;
       
    94             [checkbox release];
    91             self.lastIndexPath_we = indexPath;
    95             self.lastIndexPath_we = indexPath;
    92         }
    96         }
    93     }
    97     }
       
    98     
       
    99     cell.backgroundColor = [UIColor blackColor];
       
   100     cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT;
    94     return cell;
   101     return cell;
    95 }
   102 }
    96 
   103 
       
   104 -(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
       
   105     return 40.0;
       
   106 }
       
   107 
       
   108 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
       
   109     NSString *fileToLoad;
       
   110     if (section == 0) 
       
   111         fileToLoad = @"SchemesLabel.png";
       
   112     else
       
   113         fileToLoad = @"WeaponsLabel.png";
       
   114     
       
   115     UIImage *img = [[UIImage alloc] initWithContentsOfFile:fileToLoad];
       
   116     UIImageView *imgView = [[[UIImageView alloc] initWithImage:img] autorelease];
       
   117     [img release];
       
   118 
       
   119     return imgView;
       
   120 }
       
   121 
       
   122 /*
       
   123 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger) section {
       
   124     if (section == 0) {
       
   125         return NSLocalizedString(@"Schemes",@"");
       
   126     } else {
       
   127         return NSLocalizedString(@"Weapons",@"");;
       
   128     }
       
   129 }
       
   130 */
    97 
   131 
    98 #pragma mark -
   132 #pragma mark -
    99 #pragma mark Table view delegate
   133 #pragma mark Table view delegate
   100 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   134 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   101     NSIndexPath *lastIndexPath;
   135     NSIndexPath *lastIndexPath;
   108     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   142     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   109 
   143 
   110     if (newRow != oldRow) {
   144     if (newRow != oldRow) {
   111         //TODO: this code works only for a single section table
   145         //TODO: this code works only for a single section table
   112         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
   146         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
   113         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
   147         UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]];
       
   148         newCell.accessoryView = checkbox;
       
   149         [checkbox release];
   114         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
   150         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
   115         oldCell.accessoryType = UITableViewCellAccessoryNone;
   151         oldCell.accessoryView = nil;
   116 
   152 
   117         if ([indexPath section] == 0) {
   153         if ([indexPath section] == 0) {
   118             self.lastIndexPath_sc = indexPath;
   154             self.lastIndexPath_sc = indexPath;
   119             self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
   155             self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
   120         } else {
   156         } else {
   123         }
   159         }
   124 
   160 
   125         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   161         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   126     }
   162     }
   127     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   163     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   128 }
       
   129 
       
   130 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger) section {
       
   131     if (section == 0) {
       
   132         return NSLocalizedString(@"Schemes",@"");
       
   133     } else {
       
   134         return NSLocalizedString(@"Weapons",@"");;
       
   135     }
       
   136 }
   164 }
   137 
   165 
   138 #pragma mark -
   166 #pragma mark -
   139 #pragma mark Memory management
   167 #pragma mark Memory management
   140 -(void) didReceiveMemoryWarning {
   168 -(void) didReceiveMemoryWarning {