project_files/HedgewarsMobile/Classes/CampaignsViewController.m
author Wuzzy <almikes@aol.com>
Wed, 13 Apr 2016 00:17:07 +0200
changeset 11716 c7cdd98bb1ec
parent 11570 fba0c7a5aaf4
child 12872 00215a7ec5f5
permissions -rw-r--r--
Construction Mode: Fix mine timer message being shown at start
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     1
/*
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2015-2016 Anton Malmygin <antonc27@mail.ru>
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     4
 *
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     8
 *
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    13
 *
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    17
 */
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    18
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    19
#import "CampaignsViewController.h"
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    20
#import "CampaignViewController.h"
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    21
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    22
@interface CampaignsViewController ()
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    23
@property (nonatomic, retain) NSArray *campaigns;
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    24
@end
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    25
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    26
@implementation CampaignsViewController
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    27
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    28
#pragma mark - Lazy instantiation
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    29
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    30
- (NSArray *)campaigns {
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    31
    if (!_campaigns) {
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    32
        _campaigns = [self newListOfCampaigns];
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    33
    }
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    34
    return _campaigns;
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    35
}
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    36
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    37
- (NSArray *)newListOfCampaigns {
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    38
    NSFileManager *fileManager = [NSFileManager defaultManager];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    39
    NSArray *contents = [fileManager contentsOfDirectoryAtPath:CAMPAIGNS_DIRECTORY() error:nil];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    40
    
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    41
    NSMutableArray *tempCampaigns = [[NSMutableArray alloc] init];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    42
    for (NSString *item in contents) {
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    43
        NSString *fullItemPath = [CAMPAIGNS_DIRECTORY() stringByAppendingString:item];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    44
        BOOL isDirectory;
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    45
        if ([fileManager fileExistsAtPath:fullItemPath isDirectory:&isDirectory] && isDirectory) {
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    46
            [tempCampaigns addObject:item];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    47
        }
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    48
    }
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    49
    
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    50
    NSArray *campaigns = [tempCampaigns copy];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    51
    [tempCampaigns release];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    52
    return campaigns;
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    53
}
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    54
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    55
#pragma mark - View lifecycle
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    56
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    57
- (void)viewDidLoad {
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    58
    [super viewDidLoad];
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    59
    
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    60
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    61
    self.navigationItem.rightBarButtonItem = doneButton;
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    62
    [doneButton release];
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    63
    
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    64
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignCell"];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    65
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    66
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    67
- (void)dismiss {
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    68
    [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    69
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    70
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    71
- (void)didReceiveMemoryWarning {
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    72
    [super didReceiveMemoryWarning];
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    73
    // Dispose of any resources that can be recreated.
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    74
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    75
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    76
#pragma mark - Table view data source
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    77
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    78
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    79
    return 1;
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    80
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    81
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    82
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    83
    return [self.campaigns count];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    84
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    85
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    86
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    87
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignCell" forIndexPath:indexPath];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    88
    
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    89
    cell.textLabel.text = self.campaigns[indexPath.row];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    90
    
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    91
    return cell;
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    92
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    93
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    94
#pragma mark - Table view delegate
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    95
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    96
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    97
    NSString *xib = IS_IPAD() ? @"CampaignViewController-iPad" : @"CampaignViewController-iPhone";
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    98
    CampaignViewController *campaign = [[CampaignViewController alloc] initWithNibName:xib bundle:nil];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    99
    
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
   100
    campaign.campaignName = self.campaigns[indexPath.row];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   101
    
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
   102
    [self.navigationController pushViewController:campaign animated:YES];
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
   103
    [campaign release];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   104
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   105
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
   106
#pragma mark - Dealloc
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   107
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
   108
- (void)dealloc {
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
   109
    [_campaigns release];
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
   110
    [super dealloc];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   111
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   112
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   113
@end