project_files/HedgewarsMobile/Classes/CampaignsViewController.m
author alfadur
Tue, 30 Jun 2020 22:36:53 +0300
changeset 15661 255422cd8a44
parent 12872 00215a7ec5f5
permissions -rw-r--r--
increase sentry vision angle
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 ()
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11570
diff changeset
    23
@property (nonatomic, strong) 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
    return campaigns;
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    52
}
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
#pragma mark - View lifecycle
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    55
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    56
- (void)viewDidLoad {
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    57
    [super viewDidLoad];
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    58
    
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    59
    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
    60
    self.navigationItem.rightBarButtonItem = doneButton;
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    61
    
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    62
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignCell"];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    63
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    64
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    65
- (void)dismiss {
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    66
    [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    67
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    68
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    69
- (void)didReceiveMemoryWarning {
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    70
    [super didReceiveMemoryWarning];
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    71
    // Dispose of any resources that can be recreated.
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    72
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    73
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    74
#pragma mark - Table view data source
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
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    77
    return 1;
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    78
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    79
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    80
- (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
    81
    return [self.campaigns count];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    82
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    83
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    84
- (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
    85
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignCell" forIndexPath:indexPath];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    86
    
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
    87
    cell.textLabel.text = self.campaigns[indexPath.row];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    88
    
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    89
    return cell;
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
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    92
#pragma mark - Table view delegate
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
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    95
    NSString *xib = IS_IPAD() ? @"CampaignViewController-iPad" : @"CampaignViewController-iPhone";
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    96
    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
    97
    
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents: 11560
diff changeset
    98
    campaign.campaignName = self.campaigns[indexPath.row];
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
    [self.navigationController pushViewController:campaign animated:YES];
11559
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   101
}
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   102
11560
664d3592a66b - Campaign for iOS: Simply retrieve list of campaigns
antonc27 <antonc27@mail.ru>
parents: 11559
diff changeset
   103
#pragma mark - Dealloc
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
2b9e189df3d6 - Campaign for iOS: Stub for list of campaigns
antonc27 <antonc27@mail.ru>
parents:
diff changeset
   106
@end