- Campaign for iOS: Finally can launch campaign's mission game from list!
authorantonc27 <antonc27@mail.ru>
Wed, 24 Feb 2016 00:33:10 +0100
changeset 11572 28afdaa159cb
parent 11571 b709768e720c
child 11573 8fd1808b12ed
- Campaign for iOS: Finally can launch campaign's mission game from list! TODO: Customize UI TODO: Track user progress TODO: Localization TODO: Refactoring TODO: Get some sleep ^_
project_files/HedgewarsMobile/Classes/CampaignViewController.m
project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h
project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m
project_files/HedgewarsMobile/Classes/HWUtils.h
--- a/project_files/HedgewarsMobile/Classes/CampaignViewController.m	Wed Feb 24 00:10:12 2016 +0100
+++ b/project_files/HedgewarsMobile/Classes/CampaignViewController.m	Wed Feb 24 00:33:10 2016 +0100
@@ -18,6 +18,7 @@
 
 #import "CampaignViewController.h"
 #import "IniParser.h"
+#import "GameInterfaceBridge.h"
 
 @interface CampaignViewController ()
 @property (nonatomic, retain) NSArray *campaignMissions;
@@ -78,27 +79,19 @@
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"campaignMissionCell" forIndexPath:indexPath];
     
-    // Configure the cell...
     cell.textLabel.text = self.campaignMissions[indexPath.row][@"Name"];
     
     return cell;
 }
 
-/*
 #pragma mark - Table view delegate
 
-// In a xib-based application, navigation from a table can be handled in -tableView:didSelectRowAtIndexPath:
 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-    // Navigation logic may go here, for example:
-    // Create the next view controller.
-    <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:<#@"Nib name"#> bundle:nil];
+    NSString *campaignMissionScript = self.campaignMissions[indexPath.row][@"Script"];
     
-    // Pass the selected object to the new view controller.
-    
-    // Push the view controller.
-    [self.navigationController pushViewController:detailViewController animated:YES];
+    [GameInterfaceBridge registerCallingController:self];
+    [GameInterfaceBridge startCampaignMissionGameWithScript:campaignMissionScript forCampaign:self.campaignName];
 }
-*/
 
 #pragma mark - Dealloc
 
--- a/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m	Wed Feb 24 00:10:12 2016 +0100
+++ b/project_files/HedgewarsMobile/Classes/EngineProtocolNetwork.m	Wed Feb 24 00:33:10 2016 +0100
@@ -277,8 +277,9 @@
                 // seed info
                 [self sendToEngine:[gameConfig objectForKey:@"seed_command"]];
 
-                // missions/tranings only need the script configuration set and seed
-                if ([HWUtils gameType] == gtMission)
+                // missions/tranings/campaign only need the script configuration set and seed
+                TGameType currentGameType = [HWUtils gameType];
+                if (currentGameType == gtMission || currentGameType == gtCampaign)
                     break;
                 
                 // dimension of the map
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h	Wed Feb 24 00:10:12 2016 +0100
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.h	Wed Feb 24 00:33:10 2016 +0100
@@ -34,6 +34,7 @@
 +(void) startLocalGame:(NSDictionary *)withOptions;
 +(void) startSaveGame:(NSString *)atPath;
 +(void) startMissionGame:(NSString *)withScript;
++(void) startCampaignMissionGameWithScript:(NSString *)missionScriptName forCampaign:(NSString *)campaignName;
 +(void) startSimpleGame;
 
 +(void) registerCallingController:(UIViewController *)controller;
--- a/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Wed Feb 24 00:10:12 2016 +0100
+++ b/project_files/HedgewarsMobile/Classes/GameInterfaceBridge.m	Wed Feb 24 00:33:10 2016 +0100
@@ -259,6 +259,17 @@
     return seedCmd;
 }
 
++(void) startCampaignMissionGameWithScript:(NSString *)missionScriptName forCampaign:(NSString *)campaignName {
+    NSString *seedCmd = [self seedCommand];
+    NSString *campaignMissionPath = [[NSString alloc] initWithFormat:@"escript Missions/Campaign/%@/%@", campaignName, missionScriptName];
+    NSDictionary *campaignMissionDict = [[NSDictionary alloc] initWithObjectsAndKeys:campaignMissionPath, @"mission_command", seedCmd, @"seed_command", nil];
+    [campaignMissionPath release];
+    [seedCmd release];
+    
+    [self startGame:gtCampaign atPath:nil withOptions:campaignMissionDict];
+    [campaignMissionDict release];
+}
+
 +(void) startSimpleGame {
     NSString *seedCmd = [self seedCommand];
 
--- a/project_files/HedgewarsMobile/Classes/HWUtils.h	Wed Feb 24 00:10:12 2016 +0100
+++ b/project_files/HedgewarsMobile/Classes/HWUtils.h	Wed Feb 24 00:33:10 2016 +0100
@@ -20,7 +20,7 @@
 #import <Foundation/Foundation.h>
 
 
-typedef enum {gtNone, gtLocal, gtSave, gtMission, gtNet} TGameType;
+typedef enum {gtNone, gtLocal, gtSave, gtMission, gtCampaign, gtNet} TGameType;
 typedef enum {gsNone, gsLoading, gsInGame, gsInterrupted, gsEnded} TGameStatus;
 
 @interface HWUtils : NSObject {