project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
branchios-revival
changeset 11274 9e0fe32aff59
parent 11273 68a0df07382b
child 11293 d1d66d1f6c8a
equal deleted inserted replaced
11273:68a0df07382b 11274:9e0fe32aff59
    47     return selectedWeapon;
    47     return selectedWeapon;
    48 }
    48 }
    49 
    49 
    50 -(NSString *)selectedScript {
    50 -(NSString *)selectedScript {
    51     if (selectedScript == nil)
    51     if (selectedScript == nil)
    52         self.selectedScript = @"Normal.plist";
    52         self.selectedScript = @"";
    53     return selectedScript;
    53     return selectedScript;
    54 }
    54 }
    55 
    55 
    56 -(NSString *)scriptCommand {
    56 -(NSString *)scriptCommand {
    57     if (scriptCommand == nil)
    57     if (scriptCommand == nil)
   165     if (self.topControl.selectedSegmentIndex == 0)
   165     if (self.topControl.selectedSegmentIndex == 0)
   166         return [self.listOfSchemes count];
   166         return [self.listOfSchemes count];
   167     else if (self.topControl.selectedSegmentIndex == 1)
   167     else if (self.topControl.selectedSegmentIndex == 1)
   168         return [self.listOfWeapons count];
   168         return [self.listOfWeapons count];
   169     else
   169     else
   170         return [self.listOfScripts count];
   170         return [self.listOfScripts count] + 1; // +1 for fake 'Normal'
   171 }
   171 }
   172 
   172 
   173 // Customize the appearance of table view cells.
   173 // Customize the appearance of table view cells.
   174 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   174 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   175     static NSString *CellIdentifier = @"Cell";
   175     static NSString *CellIdentifier = @"Cell";
   204             cell.accessoryView = checkbox;
   204             cell.accessoryView = checkbox;
   205             [checkbox release];
   205             [checkbox release];
   206             self.lastIndexPath_we = indexPath;
   206             self.lastIndexPath_we = indexPath;
   207         }
   207         }
   208     } else {
   208     } else {
   209         cell.textLabel.text = [[[self.listOfScripts objectAtIndex:row] stringByDeletingPathExtension]
   209         if (row == 0)
   210                                stringByReplacingOccurrencesOfString:@"_" withString:@" "];
   210         {
   211         //cell.detailTextLabel.text = ;
   211             cell.textLabel.text = @"Normal";
   212         if ([[self.listOfScripts objectAtIndex:row] isEqualToString:self.selectedScript]) {
   212             
   213             UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]];
   213             if ([self.selectedScript isEqualToString:@""])
   214             cell.accessoryView = checkbox;
   214             {
   215             [checkbox release];
   215                 UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]];
   216             self.lastIndexPath_lu = indexPath;
   216                 cell.accessoryView = checkbox;
       
   217                 [checkbox release];
       
   218                 self.lastIndexPath_lu = indexPath;
       
   219             }
       
   220         }
       
   221         else
       
   222         {
       
   223             row--;
       
   224             
       
   225             cell.textLabel.text = [[[self.listOfScripts objectAtIndex:row] stringByDeletingPathExtension]
       
   226                                    stringByReplacingOccurrencesOfString:@"_" withString:@" "];
       
   227             //cell.detailTextLabel.text = ;
       
   228             if ([[self.listOfScripts objectAtIndex:row] isEqualToString:self.selectedScript]) {
       
   229                 UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]];
       
   230                 cell.accessoryView = checkbox;
       
   231                 [checkbox release];
       
   232                 self.lastIndexPath_lu = indexPath;
       
   233             }
   217         }
   234         }
   218     }
   235     }
   219 
   236 
   220     cell.backgroundColor = [UIColor blackColorTransparent];
   237     cell.backgroundColor = [UIColor blackColorTransparent];
   221     cell.textLabel.textColor = [UIColor lightYellowColor];
   238     cell.textLabel.textColor = [UIColor lightYellowColor];
   310         } else if (index == 1) {
   327         } else if (index == 1) {
   311             self.lastIndexPath_we = indexPath;
   328             self.lastIndexPath_we = indexPath;
   312             self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow];
   329             self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow];
   313         } else {
   330         } else {
   314             self.lastIndexPath_lu = indexPath;
   331             self.lastIndexPath_lu = indexPath;
   315             self.selectedScript = [self.listOfScripts objectAtIndex:newRow];
   332             
   316 
   333             if (newRow == 0)
   317             // some styles disable or force the choice of a particular scheme/weaponset
       
   318             NSString *path = [[NSString alloc] initWithFormat:@"%@/%@.cfg",SCRIPTS_DIRECTORY(),[self.selectedScript stringByDeletingPathExtension]];
       
   319             NSString *configFile = [[NSString alloc] initWithContentsOfFile:path];
       
   320             [path release];
       
   321             NSArray *scriptOptions = [configFile componentsSeparatedByString:@"\n"];
       
   322             [configFile release];
       
   323 
       
   324             self.scriptCommand = [NSString stringWithFormat:@"escript Scripts/Multiplayer/%@",self.selectedScript];
       
   325             NSString *scheme = [scriptOptions objectAtIndex:0];
       
   326             if ([scheme isEqualToString:@"locked"])
       
   327             {
   334             {
       
   335                 self.selectedScript = nil;
       
   336                 self.scriptCommand = nil;
       
   337                 
   328                 self.selectedScheme = @"Default.plist";
   338                 self.selectedScheme = @"Default.plist";
   329                 [self.topControl setEnabled:NO forSegmentAtIndex:0];
   339                 [self.topControl setEnabled:YES forSegmentAtIndex:0];
       
   340                 
       
   341                 self.selectedWeapon = @"Default.plist";
       
   342                 [self.topControl setEnabled:YES forSegmentAtIndex:1];
   330             }
   343             }
   331             else
   344             else
   332             {
   345             {
   333                 if (scheme && ![scheme isEqualToString:@"*"])
   346                 newRow--;
       
   347                 
       
   348                 self.selectedScript = [self.listOfScripts objectAtIndex:newRow];
       
   349                 
       
   350                 // some styles disable or force the choice of a particular scheme/weaponset
       
   351                 NSString *path = [[NSString alloc] initWithFormat:@"%@/%@.cfg",SCRIPTS_DIRECTORY(),[self.selectedScript stringByDeletingPathExtension]];
       
   352                 NSString *configFile = [[NSString alloc] initWithContentsOfFile:path];
       
   353                 [path release];
       
   354                 NSArray *scriptOptions = [configFile componentsSeparatedByString:@"\n"];
       
   355                 [configFile release];
       
   356                 
       
   357                 self.scriptCommand = [NSString stringWithFormat:@"escript Scripts/Multiplayer/%@",self.selectedScript];
       
   358                 NSString *scheme = [scriptOptions objectAtIndex:0];
       
   359                 if ([scheme isEqualToString:@"locked"])
   334                 {
   360                 {
   335                     NSString *correctScheme = [scheme stringByReplacingOccurrencesOfString:@"_" withString:@" "];
   361                     self.selectedScheme = @"Default.plist";
   336                     self.selectedScheme = [NSString stringWithFormat:@"%@.plist", correctScheme];
   362                     [self.topControl setEnabled:NO forSegmentAtIndex:0];
   337                 }
   363                 }
   338                 [self.topControl setEnabled:YES forSegmentAtIndex:0];
   364                 else
   339             }
       
   340 
       
   341             NSString *weapon = [scriptOptions objectAtIndex:1];
       
   342             if ([weapon isEqualToString:@"locked"])
       
   343             {
       
   344                 self.selectedWeapon = @"Default.plist";
       
   345                 [self.topControl setEnabled:NO forSegmentAtIndex:1];
       
   346             }
       
   347             else
       
   348             {
       
   349                 if (weapon && ![weapon isEqualToString:@"*"])
       
   350                 {
   365                 {
   351                     NSString *correctWeapon = [weapon stringByReplacingOccurrencesOfString:@"_" withString:@" "];
   366                     if (scheme && ![scheme isEqualToString:@"*"])
   352                     self.selectedWeapon = [NSString stringWithFormat:@"%@.plist", correctWeapon];
   367                     {
       
   368                         NSString *correctScheme = [scheme stringByReplacingOccurrencesOfString:@"_" withString:@" "];
       
   369                         self.selectedScheme = [NSString stringWithFormat:@"%@.plist", correctScheme];
       
   370                     }
       
   371                     [self.topControl setEnabled:YES forSegmentAtIndex:0];
   353                 }
   372                 }
   354                 [self.topControl setEnabled:YES forSegmentAtIndex:1];
   373                 
       
   374                 NSString *weapon = [scriptOptions objectAtIndex:1];
       
   375                 if ([weapon isEqualToString:@"locked"])
       
   376                 {
       
   377                     self.selectedWeapon = @"Default.plist";
       
   378                     [self.topControl setEnabled:NO forSegmentAtIndex:1];
       
   379                 }
       
   380                 else
       
   381                 {
       
   382                     if (weapon && ![weapon isEqualToString:@"*"])
       
   383                     {
       
   384                         NSString *correctWeapon = [weapon stringByReplacingOccurrencesOfString:@"_" withString:@" "];
       
   385                         self.selectedWeapon = [NSString stringWithFormat:@"%@.plist", correctWeapon];
       
   386                     }
       
   387                     [self.topControl setEnabled:YES forSegmentAtIndex:1];
       
   388                 }
   355             }
   389             }
   356         }
   390         }
   357 
   391 
   358         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   392         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
   359     }
   393     }