author | Wuzzy <almikes@aol.com> |
Sat, 19 Nov 2016 23:04:44 +0100 | |
changeset 11951 | 65e61f495129 |
parent 11577 | 28afdaa159cb |
child 12877 | 00215a7ec5f5 |
permissions | -rw-r--r-- |
11567
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" |
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
20 |
#import "IniParser.h" |
11577
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11575
diff
changeset
|
21 |
#import "GameInterfaceBridge.h" |
11567
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 () |
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
24 |
@property (nonatomic, retain) NSArray *campaignMissions; |
11567
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 |
|
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
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:
11567
diff
changeset
|
30 |
|
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
31 |
- (NSArray *)campaignMissions { |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
32 |
if (!_campaignMissions) { |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
33 |
_campaignMissions = [self newParsedMissionsForCurrentCampaign]; |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
34 |
} |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
35 |
return _campaignMissions; |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
36 |
} |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
37 |
|
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
38 |
- (NSArray *)newParsedMissionsForCurrentCampaign { |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
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:
11567
diff
changeset
|
40 |
|
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
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:
11567
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:
11567
diff
changeset
|
43 |
[iniParser release]; |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
44 |
|
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
45 |
return parsedMissions; |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
46 |
} |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
47 |
|
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
48 |
#pragma mark - View lifecycle |
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
49 |
|
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
50 |
- (void)viewDidLoad { |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
51 |
[super viewDidLoad]; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
52 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
53 |
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
|
54 |
self.navigationItem.rightBarButtonItem = doneButton; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
55 |
[doneButton release]; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
56 |
|
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
57 |
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"campaignMissionCell"]; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
58 |
} |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
59 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
60 |
- (void)dismiss { |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
61 |
[self.navigationController.presentingViewController dismissViewControllerAnimated:YES completion:nil]; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
62 |
} |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
63 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
64 |
- (void)didReceiveMemoryWarning { |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
65 |
[super didReceiveMemoryWarning]; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
66 |
// Dispose of any resources that can be recreated. |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
67 |
} |
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 |
#pragma mark - Table view data source |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
70 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
71 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
72 |
return 1; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
73 |
} |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
74 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
75 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
76 |
return [self.campaignMissions count]; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
77 |
} |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
78 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
79 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
80 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignMissionCell" forIndexPath:indexPath]; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
81 |
|
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
82 |
cell.textLabel.text = self.campaignMissions[indexPath.row][@"Name"]; |
11567
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 |
return cell; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
85 |
} |
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 |
#pragma mark - Table view delegate |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
88 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
89 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
11577
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11575
diff
changeset
|
90 |
NSString *campaignMissionScript = self.campaignMissions[indexPath.row][@"Script"]; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
91 |
|
11577
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11575
diff
changeset
|
92 |
[GameInterfaceBridge registerCallingController:self]; |
28afdaa159cb
- Campaign for iOS: Finally can launch campaign's mission game from list!
antonc27 <antonc27@mail.ru>
parents:
11575
diff
changeset
|
93 |
[GameInterfaceBridge startCampaignMissionGameWithScript:campaignMissionScript forCampaign:self.campaignName]; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
94 |
} |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
95 |
|
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
96 |
#pragma mark - Dealloc |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
97 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
98 |
- (void)dealloc { |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
99 |
[_campaignName release]; |
11575
fba0c7a5aaf4
- Campaign for iOS: Fill campaign page with parsed missions from campaign.ini
antonc27 <antonc27@mail.ru>
parents:
11567
diff
changeset
|
100 |
[_campaignMissions release]; |
11567
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
101 |
[super dealloc]; |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
102 |
} |
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
103 |
|
32bbf1f6bb2b
- Campaign for iOS: Stub for CampaignViewController
antonc27 <antonc27@mail.ru>
parents:
diff
changeset
|
104 |
@end |