project_files/HedgewarsMobile/Classes/CampaignViewController.m
author alfadur
Sun, 12 Apr 2020 00:26:37 +0300
changeset 15554 36687bc9d5c1
parent 12872 00215a7ec5f5
permissions -rw-r--r--
send team colors on round end
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     1
/*
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     2
 * Hedgewars-iOS, a Hedgewars port for iOS devices
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     3
 * Copyright (c) 2015-2016 Anton Malmygin <antonc27@mail.ru>
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     4
 *
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     8
 *
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    12
 * GNU General Public License for more details.
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    13
 *
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    17
 */
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    18
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    19
#import "CampaignViewController.h"
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    20
#import "IniParser.h"
11572
28afdaa159cb - Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents: 11570
diff changeset
    21
#import "GameInterfaceBridge.h"
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    22
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    23
@interface CampaignViewController ()
12872
00215a7ec5f5 - BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents: 11572
diff changeset
    24
@property (nonatomic, strong) NSArray *campaignMissions;
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    25
@end
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    26
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    27
@implementation CampaignViewController
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    28
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    29
#pragma mark - Lazy instantiation
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    30
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    31
- (NSArray *)campaignMissions {
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    32
    if (!_campaignMissions) {
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    33
        _campaignMissions = [self newParsedMissionsForCurrentCampaign];
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    34
    }
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    35
    return _campaignMissions;
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    36
}
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    37
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    38
- (NSArray *)newParsedMissionsForCurrentCampaign {
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    39
    NSString *campaignIniPath = [CAMPAIGNS_DIRECTORY() stringByAppendingFormat:@"%@/campaign.ini", self.campaignName];
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    40
    
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    41
    IniParser *iniParser = [[IniParser alloc] initWithIniFilePath:campaignIniPath];
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    42
    NSArray *parsedMissions = [iniParser newParsedSections];
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    43
    
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    44
    return parsedMissions;
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    45
}
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    46
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    47
#pragma mark - View lifecycle
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    48
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    49
- (void)viewDidLoad {
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    50
    [super viewDidLoad];
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    51
    
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    52
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismiss)];
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    53
    self.navigationItem.rightBarButtonItem = doneButton;
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    54
    
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    55
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignMissionCell"];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    56
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    57
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    58
- (void)dismiss {
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    59
    [self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil];
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    60
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    61
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    62
- (void)didReceiveMemoryWarning {
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    63
    [super didReceiveMemoryWarning];
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    64
    // Dispose of any resources that can be recreated.
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    65
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    66
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    67
#pragma mark - Table view data source
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    68
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    69
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    70
    return 1;
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    71
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    72
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    73
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    74
    return [self.campaignMissions count];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    75
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    76
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    77
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    78
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignMissionCell" forIndexPath:indexPath];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    79
    
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    80
    cell.textLabel.text = self.campaignMissions[indexPath.row][@"Name"];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    81
    
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    82
    return cell;
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    83
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    84
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    85
#pragma mark - Table view delegate
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    86
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    87
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
11572
28afdaa159cb - Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents: 11570
diff changeset
    88
    NSString *campaignMissionScript = self.campaignMissions[indexPath.row][@"Script"];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    89
    
11572
28afdaa159cb - Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents: 11570
diff changeset
    90
    [GameInterfaceBridge registerCallingController:self];
28afdaa159cb - Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents: 11570
diff changeset
    91
    [GameInterfaceBridge startCampaignMissionGameWithScript:campaignMissionScript forCampaign:self.campaignName];
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    92
}
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    93
11570
fba0c7a5aaf4 - Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents: 11562
diff changeset
    94
#pragma mark - Dealloc
11562
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    95
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    96
32bbf1f6bb2b - Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff changeset
    97
@end