project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
changeset 3523 6592fbb969da
parent 3514 59dbd31e9953
child 3546 ccf4854df294
equal deleted inserted replaced
3522:156c04c6a3d8 3523:6592fbb969da
     8 
     8 
     9 #import "SchemeWeaponConfigViewController.h"
     9 #import "SchemeWeaponConfigViewController.h"
    10 #import "CommodityFunctions.h"
    10 #import "CommodityFunctions.h"
    11 
    11 
    12 @implementation SchemeWeaponConfigViewController
    12 @implementation SchemeWeaponConfigViewController
    13 @synthesize listOfSchemes, listOfWeapons, lastIndexPath, selectedScheme, selectedWeapon;
    13 @synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon;
    14 
    14 
    15 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    15 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    16     return rotationManager(interfaceOrientation);
    16     return rotationManager(interfaceOrientation);
    17 }
    17 }
    18 
    18 
    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 
       
    27     self.selectedScheme = @"Default.plist";
       
    28     self.selectedWeapon = @"Default.plist";
       
    29 }
    26 }
    30 
    27 
    31 -(void) viewWillAppear:(BOOL) animated {
    28 -(void) viewWillAppear:(BOOL) animated {
    32     [super viewWillAppear:animated];
    29     [super viewWillAppear:animated];
    33 
    30 
    34     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL];
    31     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL];
    35     self.listOfSchemes = contentsOfDir;
    32     self.listOfSchemes = contentsOfDir;
    36     
    33     
       
    34     contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL];
       
    35     self.listOfWeapons = contentsOfDir;
       
    36     
       
    37     self.selectedScheme = @"Default.plist";
       
    38     self.selectedWeapon = @"Default.plist";
       
    39     
    37     [self.tableView reloadData];
    40     [self.tableView reloadData];
    38 }
    41 }
    39 
    42 
    40 /*
       
    41 - (void)viewDidAppear:(BOOL)animated {
       
    42     [super viewDidAppear:animated];
       
    43 }
       
    44 */
       
    45 /*
       
    46 - (void)viewWillDisappear:(BOOL)animated {
       
    47     [super viewWillDisappear:animated];
       
    48 }
       
    49 */
       
    50 /*
       
    51 - (void)viewDidDisappear:(BOOL)animated {
       
    52     [super viewDidDisappear:animated];
       
    53 }
       
    54 */
       
    55 
    43 
    56 
    44 
    57 #pragma mark -
    45 #pragma mark -
    58 #pragma mark Table view data source
    46 #pragma mark Table view data source
    59 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    47 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    82     cell.accessoryType = UITableViewCellAccessoryNone;
    70     cell.accessoryType = UITableViewCellAccessoryNone;
    83     if ([indexPath section] == 0) {
    71     if ([indexPath section] == 0) {
    84         cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension];
    72         cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension];
    85         if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) {
    73         if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) {
    86             cell.accessoryType = UITableViewCellAccessoryCheckmark;
    74             cell.accessoryType = UITableViewCellAccessoryCheckmark;
    87             self.lastIndexPath = indexPath;
    75             self.lastIndexPath_sc = indexPath;
    88         }
    76         }
    89     } else {
    77     } else {
    90         cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension];
    78         cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension];
    91         if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) {
    79         if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) {
    92             cell.accessoryType = UITableViewCellAccessoryCheckmark;
    80             cell.accessoryType = UITableViewCellAccessoryCheckmark;
    93             self.lastIndexPath = indexPath;
    81             self.lastIndexPath_we = indexPath;
    94         }
    82         }
    95     }
    83     }
    96 
    84 
    97     return cell;
    85     return cell;
    98 }
    86 }
    99 
    87 
   100 
    88 
   101 #pragma mark -
    89 #pragma mark -
   102 #pragma mark Table view delegate
    90 #pragma mark Table view delegate
   103 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    91 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
    92     NSIndexPath *lastIndexPath;
       
    93     if ([indexPath section] == 0)
       
    94         lastIndexPath = self.lastIndexPath_sc;
       
    95     else
       
    96         lastIndexPath = self.lastIndexPath_we;
       
    97     
   104     int newRow = [indexPath row];
    98     int newRow = [indexPath row];
   105     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
    99     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   106     
   100     
   107     if (newRow != oldRow) {
   101     if (newRow != oldRow) {
   108         //TODO: this code works only for a single section table
   102         //TODO: this code works only for a single section table
   109         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
   103         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
   110         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
   104         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
   111         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
   105         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
   112         oldCell.accessoryType = UITableViewCellAccessoryNone;
   106         oldCell.accessoryType = UITableViewCellAccessoryNone;
   113         self.lastIndexPath = indexPath;
   107         
   114         self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
   108         if ([indexPath section] == 0) {
       
   109             self.lastIndexPath_sc = indexPath;
       
   110             self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow];
       
   111         } else {
       
   112             self.lastIndexPath_we = indexPath;
       
   113             self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow];
       
   114         }        
       
   115         
   115         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   116         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   116     }
   117     }
   117     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   118     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   118 }
   119 }
   119 
   120 
   134 }
   135 }
   135 
   136 
   136 -(void) viewDidUnload {
   137 -(void) viewDidUnload {
   137     self.listOfSchemes = nil;
   138     self.listOfSchemes = nil;
   138     self.listOfWeapons = nil;
   139     self.listOfWeapons = nil;
   139     self.lastIndexPath = nil;
   140     self.lastIndexPath_sc = nil;
       
   141     self.lastIndexPath_we = nil;
   140     self.selectedScheme = nil;
   142     self.selectedScheme = nil;
   141     self.selectedWeapon = nil;
   143     self.selectedWeapon = nil;
   142     MSG_DIDUNLOAD();
   144     MSG_DIDUNLOAD();
   143 }
   145 }
   144 
   146 
   145 
   147 
   146 -(void) dealloc {
   148 -(void) dealloc {
   147     [listOfSchemes release];
   149     [listOfSchemes release];
   148     [listOfWeapons release];
   150     [listOfWeapons release];
   149     [lastIndexPath release];
   151     [lastIndexPath_sc release];
       
   152     [lastIndexPath_we release];
   150     [selectedScheme release];
   153     [selectedScheme release];
   151     [selectedWeapon release];
   154     [selectedWeapon release];
   152     [super dealloc];
   155     [super dealloc];
   153 }
   156 }
   154 
   157