project_files/HedgewarsMobile/Classes/CampaignViewController.m
changeset 11575 fba0c7a5aaf4
parent 11567 32bbf1f6bb2b
child 11577 28afdaa159cb
equal deleted inserted replaced
11574:294ce0fa65d0 11575:fba0c7a5aaf4
    15  * along with this program; if not, write to the Free Software
    15  * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
    16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
    17  */
    17  */
    18 
    18 
    19 #import "CampaignViewController.h"
    19 #import "CampaignViewController.h"
       
    20 #import "IniParser.h"
    20 
    21 
    21 @interface CampaignViewController ()
    22 @interface CampaignViewController ()
    22 
    23 @property (nonatomic, retain) NSArray *campaignMissions;
    23 @end
    24 @end
    24 
    25 
    25 @implementation CampaignViewController
    26 @implementation CampaignViewController
       
    27 
       
    28 #pragma mark - Lazy instantiation
       
    29 
       
    30 - (NSArray *)campaignMissions {
       
    31     if (!_campaignMissions) {
       
    32         _campaignMissions = [self newParsedMissionsForCurrentCampaign];
       
    33     }
       
    34     return _campaignMissions;
       
    35 }
       
    36 
       
    37 - (NSArray *)newParsedMissionsForCurrentCampaign {
       
    38     NSString *campaignIniPath = [CAMPAIGNS_DIRECTORY() stringByAppendingFormat:@"%@/campaign.ini", self.campaignName];
       
    39     
       
    40     IniParser *iniParser = [[IniParser alloc] initWithIniFilePath:campaignIniPath];
       
    41     NSArray *parsedMissions = [iniParser newParsedSections];
       
    42     [iniParser release];
       
    43     
       
    44     return parsedMissions;
       
    45 }
       
    46 
       
    47 #pragma mark - View lifecycle
    26 
    48 
    27 - (void)viewDidLoad {
    49 - (void)viewDidLoad {
    28     [super viewDidLoad];
    50     [super viewDidLoad];
    29     
    51     
    30     UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
    52     UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
    31     self.navigationItem.rightBarButtonItem = doneButton;
    53     self.navigationItem.rightBarButtonItem = doneButton;
    32     [doneButton release];
    54     [doneButton release];
    33     
    55     
    34     NSString *campaignIniPath = [CAMPAIGNS_DIRECTORY() stringByAppendingFormat:@"%@/campaign.ini", self.campaignName];
    56     [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignMissionCell"];
    35     NSLog(@"%@", campaignIniPath);
       
    36 }
    57 }
    37 
    58 
    38 - (void)dismiss {
    59 - (void)dismiss {
    39     [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    60     [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
    40 }
    61 }
    45 }
    66 }
    46 
    67 
    47 #pragma mark - Table view data source
    68 #pragma mark - Table view data source
    48 
    69 
    49 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    70 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    50 #warning Incomplete implementation, return the number of sections
    71     return 1;
    51     return 0;
       
    52 }
    72 }
    53 
    73 
    54 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    74 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    55 #warning Incomplete implementation, return the number of rows
    75     return [self.campaignMissions count];
    56     return 0;
       
    57 }
    76 }
    58 
    77 
    59 /*
       
    60 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    78 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    61     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    79     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignMissionCell" forIndexPath:indexPath];
    62     
    80     
    63     // Configure the cell...
    81     // Configure the cell...
       
    82     cell.textLabel.text = self.campaignMissions[indexPath.row][@"Name"];
    64     
    83     
    65     return cell;
    84     return cell;
    66 }
    85 }
    67 */
       
    68 
       
    69 /*
       
    70 // Override to support conditional editing of the table view.
       
    71 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
       
    72     // Return NO if you do not want the specified item to be editable.
       
    73     return YES;
       
    74 }
       
    75 */
       
    76 
       
    77 /*
       
    78 // Override to support editing the table view.
       
    79 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
       
    80     if (editingStyle == UITableViewCellEditingStyleDelete) {
       
    81         // Delete the row from the data source
       
    82         [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
       
    83     } else if (editingStyle == UITableViewCellEditingStyleInsert) {
       
    84         // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
       
    85     }   
       
    86 }
       
    87 */
       
    88 
       
    89 /*
       
    90 // Override to support rearranging the table view.
       
    91 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
       
    92 }
       
    93 */
       
    94 
       
    95 /*
       
    96 // Override to support conditional rearranging of the table view.
       
    97 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
       
    98     // Return NO if you do not want the item to be re-orderable.
       
    99     return YES;
       
   100 }
       
   101 */
       
   102 
    86 
   103 /*
    87 /*
   104 #pragma mark - Table view delegate
    88 #pragma mark - Table view delegate
   105 
    89 
   106 // In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
    90 // In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
   114     // Push the view controller.
    98     // Push the view controller.
   115     [self.navigationController pushViewController:detailViewController animated:YES];
    99     [self.navigationController pushViewController:detailViewController animated:YES];
   116 }
   100 }
   117 */
   101 */
   118 
   102 
   119 /*
   103 #pragma mark - Dealloc
   120 #pragma mark - Navigation
       
   121 
       
   122 // In a storyboard-based application, you will often want to do a little preparation before navigation
       
   123 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
       
   124     // Get the new view controller using [segue destinationViewController].
       
   125     // Pass the selected object to the new view controller.
       
   126 }
       
   127 */
       
   128 
   104 
   129 - (void)dealloc {
   105 - (void)dealloc {
   130     [_campaignName release];
   106     [_campaignName release];
       
   107     [_campaignMissions release];
   131     [super dealloc];
   108     [super dealloc];
   132 }
   109 }
   133 
   110 
   134 @end
   111 @end