project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
changeset 3697 d5b30d6373fc
parent 3670 4c673e57f0d7
child 3703 12d17c6e8855
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    21 -(void) viewDidLoad {
    21 -(void) viewDidLoad {
    22     [super viewDidLoad];
    22     [super viewDidLoad];
    23 
    23 
    24     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    24     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    25     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
    25     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
    26     
    26 
    27     self.selectedScheme = @"";
    27     self.selectedScheme = @"";
    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 colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1];
    34     }
    34     }
    35     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    35     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    36 }
    36 }
    38 -(void) viewWillAppear:(BOOL) animated {
    38 -(void) viewWillAppear:(BOOL) animated {
    39     [super viewWillAppear:animated];
    39     [super viewWillAppear:animated];
    40 
    40 
    41     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL];
    41     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL];
    42     self.listOfSchemes = contentsOfDir;
    42     self.listOfSchemes = contentsOfDir;
    43     
    43 
    44     if ([listOfSchemes containsObject:@"Default.plist"])
    44     if ([listOfSchemes containsObject:@"Default.plist"])
    45          self.selectedScheme = @"Default.plist";
    45          self.selectedScheme = @"Default.plist";
    46     
    46 
    47     contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL];
    47     contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL];
    48     self.listOfWeapons = contentsOfDir;
    48     self.listOfWeapons = contentsOfDir;
    49          
    49 
    50     if ([listOfWeapons containsObject:@"Default.plist"])
    50     if ([listOfWeapons containsObject:@"Default.plist"])
    51          self.selectedWeapon = @"Default.plist";
    51          self.selectedWeapon = @"Default.plist";
    52 
    52 
    53     [self.tableView reloadData];
    53     [self.tableView reloadData];
    54 }
    54 }
    59 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    59 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    60     return 2;
    60     return 2;
    61 }
    61 }
    62 
    62 
    63 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    63 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    64     if (section == 0) 
    64     if (section == 0)
    65         return [self.listOfSchemes count];
    65         return [self.listOfSchemes count];
    66     else
    66     else
    67         return [self.listOfWeapons count];
    67         return [self.listOfWeapons count];
    68 }
    68 }
    69 
    69 
    70 // Customize the appearance of table view cells.
    70 // Customize the appearance of table view cells.
    71 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    71 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    72     static NSString *CellIdentifier = @"Cell";
    72     static NSString *CellIdentifier = @"Cell";
    73     NSInteger row = [indexPath row];
    73     NSInteger row = [indexPath row];
    74     
    74 
    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.accessoryType = UITableViewCellAccessoryNone;
    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             cell.accessoryType = UITableViewCellAccessoryCheckmark;
   101     NSIndexPath *lastIndexPath;
   101     NSIndexPath *lastIndexPath;
   102     if ([indexPath section] == 0)
   102     if ([indexPath section] == 0)
   103         lastIndexPath = self.lastIndexPath_sc;
   103         lastIndexPath = self.lastIndexPath_sc;
   104     else
   104     else
   105         lastIndexPath = self.lastIndexPath_we;
   105         lastIndexPath = self.lastIndexPath_we;
   106     
   106 
   107     int newRow = [indexPath row];
   107     int newRow = [indexPath row];
   108     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   108     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   109     
   109 
   110     if (newRow != oldRow) {
   110     if (newRow != oldRow) {
   111         //TODO: this code works only for a single section table
   111         //TODO: this code works only for a single section table
   112         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
   112         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
   113         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
   113         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
   114         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
   114         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
   115         oldCell.accessoryType = UITableViewCellAccessoryNone;
   115         oldCell.accessoryType = UITableViewCellAccessoryNone;
   116         
   116 
   117         if ([indexPath section] == 0) {
   117         if ([indexPath section] == 0) {
   118             self.lastIndexPath_sc = indexPath;
   118             self.lastIndexPath_sc = indexPath;
   119             self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
   119             self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
   120         } else {
   120         } else {
   121             self.lastIndexPath_we = indexPath;
   121             self.lastIndexPath_we = indexPath;
   122             self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow];
   122             self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow];
   123         }        
   123         }
   124         
   124 
   125         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   125         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   126     }
   126     }
   127     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   127     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   128 }
   128 }
   129 
   129