support for static map added to iFrontend
authorkoda
Thu, 15 Jul 2010 01:18:51 +0200
changeset 3642 fb39fecca350
parent 3641 98319a621dc8
child 3643 858b20bafb6e
support for static map added to iFrontend
project_files/HedgewarsMobile/Classes/GameConfigViewController.m
project_files/HedgewarsMobile/Classes/GameSetup.m
project_files/HedgewarsMobile/Classes/MapConfigViewController.h
project_files/HedgewarsMobile/Classes/MapConfigViewController.m
--- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Wed Jul 14 00:43:36 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m	Thu Jul 15 01:18:51 2010 +0200
@@ -149,6 +149,7 @@
                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
                                                                       mapConfigViewController.themeCommand,@"theme_command",
+                                                                      mapConfigViewController.staticMapCommand,@"staticmap_command",
                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
@@ -157,7 +158,7 @@
     // finally launch game and remove this controller
     DLog(@"sending config %@", gameDictionary);
     
-    if ([[gameDictionary allKeys] count] == 8) {
+    if ([[gameDictionary allKeys] count] == 9) {
         [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary];
     } else {
         DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n",
--- a/project_files/HedgewarsMobile/Classes/GameSetup.m	Wed Jul 14 00:43:36 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/GameSetup.m	Thu Jul 15 01:18:51 2010 +0200
@@ -290,6 +290,11 @@
                 [self sendToEngine:[self.gameConfig objectForKey:@"mapgen_command"]];
                 [self sendToEngine:[self.gameConfig objectForKey:@"mazesize_command"]];
                 
+                // static land (if set)
+                NSString *staticMap = [self.gameConfig objectForKey:@"staticmap_command"];
+                if ([staticMap length] != 0)
+                    [self sendToEngine:staticMap];
+                
                 // theme info
                 [self sendToEngine:[self.gameConfig objectForKey:@"theme_command"]];
                 
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.h	Wed Jul 14 00:43:36 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.h	Thu Jul 15 01:18:51 2010 +0200
@@ -22,6 +22,7 @@
     NSString *mapGenCommand;
     NSString *mazeSizeCommand;
     NSString *themeCommand;
+    NSString *staticMapCommand;
    
     // various widgets in the view
     UIButton *previewButton;
@@ -44,6 +45,7 @@
 @property (nonatomic,retain) NSString *mapGenCommand;
 @property (nonatomic,retain) NSString *mazeSizeCommand;
 @property (nonatomic,retain) NSString *themeCommand;
+@property (nonatomic,retain) NSString *staticMapCommand;
 
 @property (nonatomic,retain) IBOutlet UIButton *previewButton;
 @property (nonatomic,retain) IBOutlet UITableView *tableView;
--- a/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Wed Jul 14 00:43:36 2010 +0200
+++ b/project_files/HedgewarsMobile/Classes/MapConfigViewController.m	Thu Jul 15 01:18:51 2010 +0200
@@ -16,7 +16,7 @@
 #define INDICATOR_TAG 7654
 
 @implementation MapConfigViewController
-@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand,
+@synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand, staticMapCommand,
             tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, themeArray, mapArray, busy;
 
 
@@ -191,6 +191,7 @@
     [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES];
 }
 
+// instead of drawing a random map we load an image; this function is called by didSelectRowAtIndexPath only
 -(void) updatePreviewWithMap:(NSInteger) index {
     // change the preview button
     NSString *fileImage = [[NSString alloc] initWithFormat:@"%@/%@/preview.png", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]];
@@ -205,12 +206,16 @@
     NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL];
     [fileCfg release];
     NSArray *split = [contents componentsSeparatedByString:@"\n"];
+    [contents release];
 
+    // set the theme and map here
+    self.themeCommand = [NSString stringWithFormat:@"etheme %@", [split objectAtIndex:0]];
+    self.staticMapCommand = [NSString stringWithFormat:@"emap %@", [self.mapArray objectAtIndex:index]];
+    
     // if the number is not set we keep 18 standard; 
     // sometimes it's not set but there are trailing characters, we get around them with the second equation
     if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0)
         maxHogs = [[split objectAtIndex:1] intValue];
-    [contents release];
     NSString *max = [[NSString alloc] initWithFormat:@"%d",maxHogs];
     self.maxLabel.text = max;
     [max release];
@@ -316,11 +321,13 @@
     
     if (newRow != oldRow) {
         if (self.segmentedControl.selectedSegmentIndex != 1) {
-            NSString *theme = [self.themeArray objectAtIndex:newRow];
-            self.themeCommand =  [NSString stringWithFormat:@"etheme %@", theme];
-        } else
+            NSString *theme = [self.themeArray objectAtIndex:newRow];                
+            self.themeCommand = [NSString stringWithFormat:@"etheme %@", theme];
+        } else {
+            // theme and map are set in the function below
             [self updatePreviewWithMap:newRow];
-
+        }
+        
         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; 
         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:self.lastIndexPath];
@@ -421,18 +428,21 @@
 // updatePreview will call didSelectRowAtIndexPath which will call the right update routine)
 // and if necessary update the table with a slide animation
 -(IBAction) segmentedControlChanged:(id) sender {
-    NSString *mapgen;
+    NSString *mapgen, *staticmap;
     NSInteger newPage = self.segmentedControl.selectedSegmentIndex;
     
     switch (newPage) {
         case 0: // Random
             mapgen = @"e$mapgen 0";
+            staticmap = @"";
             [self sliderChanged:nil];
             self.slider.enabled = YES;
             break;
             
         case 1: // Map
             mapgen = @"e$mapgen 0";
+            // dummy value, everything is set by -updatePreview -> -didSelectRowAtIndexPath -> -updatePreviewWithMap
+            staticmap = @"map Bamboo";
             self.slider.enabled = NO;
             self.sizeLabel.text = @".";
             [self restoreBackgroundImage];
@@ -440,15 +450,18 @@
             
         case 2: // Maze
             mapgen = @"e$mapgen 1";
+            staticmap = @"";
             [self sliderChanged:nil];
             self.slider.enabled = YES;
             break;
         
         default:
             mapgen = nil;
+            staticmap = nil;
             break;
     }
     self.mapGenCommand = mapgen;
+    self.staticMapCommand = staticmap;
     [self updatePreview];
     
     // nice animation for updating the table when appropriate (on iphone)
@@ -508,6 +521,8 @@
     self.templateFilterCommand = @"e$template_filter 0";
     self.mazeSizeCommand = @"e$maze_size 0";
     self.mapGenCommand = @"e$mapgen 0";
+    self.staticMapCommand = @"";
+    
     self.lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
     
     oldValue = 5;
@@ -532,6 +547,7 @@
     self.mapGenCommand = nil;
     self.mazeSizeCommand = nil;
     self.themeCommand = nil;
+    self.staticMapCommand = nil;
     
     self.previewButton = nil;
     self.tableView = nil;
@@ -554,6 +570,7 @@
     [mapGenCommand release];
     [mazeSizeCommand release];
     [themeCommand release];
+    [staticMapCommand release];
     
     [previewButton release];
     [tableView release];