cocoaTouch/MapConfigViewController.m
changeset 3373 c1ff724a5c34
parent 3369 c7289e42f0ee
child 3374 0d522416d97f
equal deleted inserted replaced
3372:5d3daec0d0b5 3373:c1ff724a5c34
    12 #import "UIImageExtra.h"
    12 #import "UIImageExtra.h"
    13 #import "SDL_net.h"
    13 #import "SDL_net.h"
    14 #import <pthread.h>
    14 #import <pthread.h>
    15 
    15 
    16 #define INDICATOR_TAG 7654
    16 #define INDICATOR_TAG 7654
    17 #define RANDOMSTR_LEN 36
    17 
    18 @implementation MapConfigViewController
    18 @implementation MapConfigViewController
    19 @synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand,
    19 @synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand,
    20             tableView, maxLabel, sizeLabel, segmentedControl, slider;
    20             tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, themeArray, mapArray;
    21 
    21 
    22 
    22 
    23 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    23 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    24     return rotationManager(interfaceOrientation);
    24     return rotationManager(interfaceOrientation);
    25 }
    25 }
    42 	if (SDLNet_Init() < 0) {
    42 	if (SDLNet_Init() < 0) {
    43 		NSLog(@"SDLNet_Init: %s", SDLNet_GetError());
    43 		NSLog(@"SDLNet_Init: %s", SDLNet_GetError());
    44         serverQuit = YES;
    44         serverQuit = YES;
    45 	}
    45 	}
    46 	
    46 	
    47 	/* Resolving the host using NULL make network interface to listen */
    47 	// Resolving the host using NULL make network interface to listen
    48 	if (SDLNet_ResolveHost(&ip, NULL, port) < 0) {
    48 	if (SDLNet_ResolveHost(&ip, NULL, port) < 0) {
    49 		NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError());
    49 		NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError());
    50         serverQuit = YES;
    50         serverQuit = YES;
    51 	}
    51 	}
    52 	
    52 	
    53 	/* Open a connection with the IP provided (listen on the host's port) */
    53 	// Open a connection with the IP provided (listen on the host's port)
    54 	if (!(sd = SDLNet_TCP_Open(&ip))) {
    54 	if (!(sd = SDLNet_TCP_Open(&ip))) {
    55 		NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), port);
    55 		NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), port);
    56         serverQuit = YES;
    56         serverQuit = YES;
    57 	}
    57 	}
    58 	
    58 	
    99     CGContextRef context = UIGraphicsGetCurrentContext();       
    99     CGContextRef context = UIGraphicsGetCurrentContext();       
   100     UIGraphicsPushContext(context);  
   100     UIGraphicsPushContext(context);  
   101     for (int i = 0; i < 32*128; i++) {
   101     for (int i = 0; i < 32*128; i++) {
   102         unsigned char byte = map[i];
   102         unsigned char byte = map[i];
   103         for (int j = 0; j < 8; j++) {
   103         for (int j = 0; j < 8; j++) {
   104             // select the color based on the rightmost bit
   104             // select the color based on the leftmost bit
   105             if ((byte & 0x00000001) != 0)
   105             if ((byte & 0x80) != 0)
   106                 CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0);
   106                 CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0);
   107             else
   107             else
   108                 CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
   108                 CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 0.0);
   109             
       
   110             // draw pixel
   109             // draw pixel
   111             CGContextFillRect(context,CGRectMake(xc,yc,1,1));
   110             CGContextFillRect(context,CGRectMake(xc,yc,1,1));
   112             // move coordinates
   111             // move coordinates
   113             xc = (xc + 1) % 256;
   112             xc = (xc + 1) % 256;
   114             if (xc == 0) yc++;
   113             if (xc == 0) yc++;
   115             
       
   116             // shift to next bit
   114             // shift to next bit
   117             byte = byte >> 1;
   115             byte <<= 1;
   118         }
   116         }
   119     }
   117     }
   120     UIGraphicsPopContext();
   118     UIGraphicsPopContext();
   121     UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
   119     UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
   122     UIGraphicsEndImageContext();
   120     UIGraphicsEndImageContext();
   123     
       
   124 
   121 
   125     // set the preview image (autoreleased) in the button and the maxhog label
   122     // set the preview image (autoreleased) in the button and the maxhog label
   126     [self.previewButton setBackgroundImage:previewImage forState:UIControlStateNormal];
   123     [self.previewButton setBackgroundImage:previewImage forState:UIControlStateNormal];
   127     self.maxLabel.text = [NSString stringWithFormat:@"%d", maxHogs];
   124     self.maxLabel.text = [NSString stringWithFormat:@"%d", maxHogs];
   128     
   125     
   145     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
   142     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
   146     CGImageRelease(previewCGImage);
   143     CGImageRelease(previewCGImage);
   147     */
   144     */
   148 }
   145 }
   149 
   146 
       
   147 -(IBAction) updatePreview {
       
   148     // don't generate a new preview while it's already generating one
       
   149     if (busy)
       
   150         return;
       
   151     
       
   152     // generate a seed
       
   153     CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
       
   154     NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
       
   155     CFRelease(uuid);
       
   156     NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
       
   157     [seed release];
       
   158     self.seedCommand = seedCmd;
       
   159     [seedCmd release];
       
   160     
       
   161     NSIndexPath *theIndex;
       
   162     if (segmentedControl.selectedSegmentIndex != 1) {
       
   163         // prevent other events and add an activity while the preview is beign generated
       
   164         [self turnOffWidgets];
       
   165         
       
   166         // remove the current preview
       
   167         [self.previewButton setImage:nil forState:UIControlStateNormal];
       
   168         
       
   169         // add a very nice spinning wheel
       
   170         UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
       
   171                                               initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
   172         indicator.center = CGPointMake(previewButton.bounds.size.width / 2, previewButton.bounds.size.height / 2);
       
   173         indicator.tag = INDICATOR_TAG;
       
   174         [indicator startAnimating];
       
   175         [self.previewButton addSubview:indicator];
       
   176         [indicator release];
       
   177         
       
   178         // let's draw in a separate thread so the gui can work; at the end it restore other widgets
       
   179         [NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil];
       
   180     
       
   181         theIndex = [NSIndexPath indexPathForRow:(random()%[self.themeArray count]) inSection:0];
       
   182     } else {
       
   183         theIndex = [NSIndexPath indexPathForRow:(random()%[self.mapArray count]) inSection:0];
       
   184     }
       
   185     [self.tableView reloadData];
       
   186     [self tableView:self.tableView didSelectRowAtIndexPath:theIndex];
       
   187     [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES];
       
   188 }
       
   189 
       
   190 -(void) updatePreviewWithMap:(NSInteger) index {
       
   191     // change the preview button
       
   192     NSString *fileImage = [[NSString alloc] initWithFormat:@"%@/%@/preview.png", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]];
       
   193     UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileImage];
       
   194     [fileImage release];
       
   195     [self.previewButton setBackgroundImage:image forState:UIControlStateNormal];
       
   196     [image release];
       
   197     
       
   198     // update label
       
   199     maxHogs = 18;
       
   200     NSString *fileCfg = [[NSString alloc] initWithFormat:@"%@/%@/map.cfg", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]];
       
   201     NSString *contents = [[NSString alloc] initWithContentsOfFile:fileCfg encoding:NSUTF8StringEncoding error:NULL];
       
   202     [fileCfg release];
       
   203     NSArray *split = [contents componentsSeparatedByString:@"\n"];
       
   204 
       
   205     // if the number is not set we keep 18 standard; 
       
   206     // sometimes it's not set but there are trailing characters, we get around them with the second equation
       
   207     if ([split count] > 1 && [[split objectAtIndex:1] intValue] > 0)
       
   208         maxHogs = [[split objectAtIndex:1] intValue];
       
   209     [contents release];
       
   210     NSString *max = [[NSString alloc] initWithFormat:@"%d",maxHogs];
       
   211     self.maxLabel.text = max;
       
   212     [max release];
       
   213 }
       
   214 
   150 -(void) turnOffWidgets {
   215 -(void) turnOffWidgets {
       
   216     busy = YES;
   151     self.previewButton.alpha = 0.5f;
   217     self.previewButton.alpha = 0.5f;
   152     self.previewButton.enabled = NO;
   218     self.previewButton.enabled = NO;
   153     self.maxLabel.text = @"...";
   219     self.maxLabel.text = @"...";
   154     self.segmentedControl.enabled = NO;
   220     self.segmentedControl.enabled = NO;
   155     self.tableView.allowsSelection = NO;
   221     self.tableView.allowsSelection = NO;
   160     self.previewButton.alpha = 1.0f;
   226     self.previewButton.alpha = 1.0f;
   161     self.previewButton.enabled = YES;
   227     self.previewButton.enabled = YES;
   162     self.segmentedControl.enabled = YES;
   228     self.segmentedControl.enabled = YES;
   163     self.tableView.allowsSelection = YES;
   229     self.tableView.allowsSelection = YES;
   164     self.slider.enabled = YES;
   230     self.slider.enabled = YES;
   165 }
   231     busy = NO;
   166 
   232 }
   167 -(IBAction) updatePreview {
   233     
   168     // prevent other events and add an activity while the preview is beign generated
       
   169     [self turnOffWidgets];
       
   170     
       
   171     // remove the current preview
       
   172     [self.previewButton setImage:nil forState:UIControlStateNormal];
       
   173     
       
   174     // add a very nice spinning wheel
       
   175     UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
       
   176                                           initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
   177     indicator.center = CGPointMake(previewButton.bounds.size.width / 2, previewButton.bounds.size.height / 2);
       
   178     indicator.tag = INDICATOR_TAG;
       
   179     [indicator startAnimating];
       
   180     [self.previewButton addSubview:indicator];
       
   181     [indicator release];
       
   182 
       
   183     // generate a seed
       
   184     char randomStr[RANDOMSTR_LEN+1];
       
   185     for (int i = 0; i < RANDOMSTR_LEN; ) {
       
   186         randomStr[i] = random() % 255;
       
   187         if (randomStr[i] >= '0' && randomStr[i] <= '9' || randomStr[i] >= 'a' && randomStr[i] <= 'z') 
       
   188             i++;
       
   189     }
       
   190     randomStr[ 8] = '-';
       
   191     randomStr[13] = '-';
       
   192     randomStr[18] = '-';
       
   193     randomStr[23] = '-';
       
   194     randomStr[RANDOMSTR_LEN] = '\0';
       
   195     NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%s}", randomStr];
       
   196     self.seedCommand = seedCmd;
       
   197     [seedCmd release];
       
   198     
       
   199     // let's draw in a separate thread so the gui can work; also it restores the preview button
       
   200     [NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil];
       
   201 }
       
   202 
       
   203 #pragma mark -
   234 #pragma mark -
   204 #pragma mark Table view data source
   235 #pragma mark Table view data source
   205 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
   236 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
   206     return 1;
   237     return 1;
   207 }
   238 }
   208 
   239 
   209 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   240 -(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger) section {
   210     return 1;
   241     if (self.segmentedControl.selectedSegmentIndex != 1)
       
   242         return [themeArray count];
       
   243     else
       
   244         return [mapArray count];
   211 }
   245 }
   212 
   246 
   213 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   247 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   214     static NSString *CellIdentifier = @"Cell";
   248     static NSString *CellIdentifier = @"Cell";
       
   249     NSInteger row = [indexPath row];
   215     
   250     
   216     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
   251     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
   217     if (cell == nil) 
   252     if (cell == nil) 
   218         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   253         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
   219     
   254     
       
   255     if (self.segmentedControl.selectedSegmentIndex != 1) {
       
   256         // the % prevents a strange bug that occurs sporadically
       
   257         NSString *themeName = [self.themeArray objectAtIndex:row % [self.themeArray count]];
       
   258         cell.textLabel.text = themeName;
       
   259         UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/Icon.png",THEMES_DIRECTORY(),themeName]];
       
   260         cell.imageView.image = [image scaleToSize:CGSizeMake(40, 40)];
       
   261     } else {
       
   262         cell.textLabel.text = [self.mapArray objectAtIndex:row];
       
   263         cell.imageView.image = nil;
       
   264     }
       
   265     
       
   266     if (row == [self.lastIndexPath row]) 
       
   267         cell.accessoryType = UITableViewCellAccessoryCheckmark;
       
   268     else
       
   269         cell.accessoryType = UITableViewCellAccessoryNone;
       
   270 
   220     return cell;
   271     return cell;
       
   272 }
       
   273 
       
   274 
       
   275 #pragma mark -
       
   276 #pragma mark Table view delegate
       
   277 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
   278     int newRow = [indexPath row];
       
   279     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
       
   280     
       
   281     if (newRow != oldRow) {
       
   282         if (self.segmentedControl.selectedSegmentIndex != 1) {
       
   283             NSString *theme = [self.themeArray objectAtIndex:newRow];
       
   284             self.themeCommand =  [NSString stringWithFormat:@"etheme %@", theme];
       
   285         } else
       
   286             [self updatePreviewWithMap:newRow];
       
   287 
       
   288         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; 
       
   289         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
       
   290         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:self.lastIndexPath];
       
   291         oldCell.accessoryType = UITableViewCellAccessoryNone;
       
   292 
       
   293         self.lastIndexPath = indexPath;
       
   294         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
       
   295     }
       
   296     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   221 }
   297 }
   222 
   298 
   223 #pragma mark -
   299 #pragma mark -
   224 #pragma mark slider & segmentedControl
   300 #pragma mark slider & segmentedControl
       
   301 // this updates the label and the command keys when the slider is moved, depending of the selection in segmentedControl
       
   302 // no methods are called by this routine and you can pass nil to it
   225 -(IBAction) sliderChanged:(id) sender {
   303 -(IBAction) sliderChanged:(id) sender {
   226     NSString *labelText;
   304     NSString *labelText;
   227     NSString *templateCommand;
   305     NSString *templateCommand;
   228     NSString *mazeCommand;
   306     NSString *mazeCommand;
   229     
   307     
   230     switch ((int)(slider.value*100)) {
   308     switch ((int)(self.slider.value*100)) {
   231         case 0:
   309         case 0:
   232             if (self.segmentedControl.selectedSegmentIndex == 0) {
   310             if (self.segmentedControl.selectedSegmentIndex == 0) {
   233                 labelText = NSLocalizedString(@"Wacky",@"");
   311                 labelText = NSLocalizedString(@"Wacky",@"");
   234             } else {
   312             } else {
   235                 labelText = NSLocalizedString(@"Large Floating Islands",@"");
   313                 labelText = NSLocalizedString(@"Large Floating Islands",@"");
   283             mazeCommand = @"e$maze_size 0";
   361             mazeCommand = @"e$maze_size 0";
   284             break;
   362             break;
   285         default:
   363         default:
   286             break;
   364             break;
   287     }
   365     }
       
   366     
   288     self.sizeLabel.text = labelText;
   367     self.sizeLabel.text = labelText;
   289     self.templateFilterCommand = templateCommand;
   368     self.templateFilterCommand = templateCommand;
   290     self.mazeSizeCommand = mazeCommand;
   369     self.mazeSizeCommand = mazeCommand;
   291 }
   370 }
   292 
   371 
   293 // update preview as soon as the user lifts its finger
   372 // update preview (if not busy and if its value really changed) as soon as the user lifts its finger up
   294 -(IBAction) sliderEndedChanging:(id) sender {
   373 -(IBAction) sliderEndedChanging:(id) sender {
   295     if (self.previewButton.enabled == YES)
   374     int num = (int) (self.slider.value * 100);
       
   375     if (oldValue != num) {
   296         [self updatePreview];
   376         [self updatePreview];
   297 }
   377         oldValue = num;
   298 
   378     }
       
   379 }
       
   380 
       
   381 // perform actions based on the activated section, then call updatePreview to visually update the selection 
       
   382 // updatePreview will call didSelectRowAtIndexPath which will call the right update routine)
       
   383 // and if necessary update the table with a slide animation
   299 -(IBAction) segmentedControlChanged:(id) sender {
   384 -(IBAction) segmentedControlChanged:(id) sender {
   300     NSString *mapgen;
   385     NSString *mapgen;
   301     
   386     NSInteger newPage = self.segmentedControl.selectedSegmentIndex;
   302     switch (segmentedControl.selectedSegmentIndex) {
   387     
       
   388     switch (newPage) {
   303         case 0: // Random
   389         case 0: // Random
   304             mapgen = @"e$mapgen 0";
   390             mapgen = @"e$mapgen 0";
   305             [self sliderChanged:nil];
   391             [self sliderChanged:nil];
   306             if (self.previewButton.enabled == YES)
   392             self.slider.enabled = YES;
   307                 [self updatePreview];
   393             break;
   308             break;
   394             
   309         case 1: // Map
   395         case 1: // Map
   310             mapgen = @"e$mapgen 0";
   396             mapgen = @"e$mapgen 0";
   311             // other stuff
   397             self.slider.enabled = NO;
   312             break;
   398             self.sizeLabel.text = @".";
       
   399             break;
       
   400             
   313         case 2: // Maze
   401         case 2: // Maze
   314             mapgen = @"e$mapgen 1";
   402             mapgen = @"e$mapgen 1";
   315             [self sliderChanged:nil];
   403             [self sliderChanged:nil];
   316             if (self.previewButton.enabled == YES)
   404             self.slider.enabled = YES;
   317                 [self updatePreview];
       
   318 
       
   319             break;
   405             break;
   320     }
   406     }
   321     self.mapGenCommand = mapgen;
   407     self.mapGenCommand = mapgen;
       
   408     [self updatePreview];
       
   409     
       
   410     // nice animation for updating the table when needed
       
   411     if (((oldPage == 0 || oldPage == 2) && newPage == 1) ||
       
   412         (oldPage == 1 && (newPage == 0 || newPage == 2))) {
       
   413         [UIView beginAnimations:@"moving out table" context:NULL];
       
   414         self.tableView.frame = CGRectMake(480, 0, 185, 276);
       
   415         [UIView commitAnimations];
       
   416         [self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2];
       
   417     }
       
   418     oldPage = newPage;
       
   419 }
       
   420 
       
   421 // update data when table is not visible and then show it
       
   422 -(void) moveTable {
       
   423     [self.tableView reloadData];
       
   424     
       
   425     [UIView beginAnimations:@"moving in table" context:NULL];
       
   426     self.tableView.frame = CGRectMake(295, 0, 185, 276);
       
   427     [UIView commitAnimations];
   322 }
   428 }
   323 
   429 
   324 #pragma mark -
   430 #pragma mark -
   325 #pragma mark view management
   431 #pragma mark view management
   326 -(void) viewDidLoad {
   432 -(void) viewDidLoad {
   327     srandom(time(NULL));
       
   328     [super viewDidLoad];
   433     [super viewDidLoad];
   329 
   434 
   330     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
   435     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
   331     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
   436     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
   332 
   437 
       
   438     // themes.cfg contains all the user-selectable themes
       
   439     NSString *string = [[NSString alloc] initWithContentsOfFile:[THEMES_DIRECTORY() stringByAppendingString:@"/themes.cfg"]
       
   440                                                        encoding:NSUTF8StringEncoding 
       
   441                                                           error:NULL];
       
   442     NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"\n"]];
       
   443     [string release];
       
   444     // remove a trailing "" element
       
   445     [array removeLastObject];
       
   446     self.themeArray = array;
       
   447     [array release];
       
   448     self.mapArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
       
   449 
       
   450     self.tableView.rowHeight = 42;
       
   451     busy = NO;
       
   452     // initialize some "default" values
   333     self.sizeLabel.text = NSLocalizedString(@"All",@"");
   453     self.sizeLabel.text = NSLocalizedString(@"All",@"");
       
   454     self.slider.value = 0.05f;
       
   455     self.segmentedControl.selectedSegmentIndex = 0;
       
   456 
   334     self.templateFilterCommand = @"e$template_filter 0";
   457     self.templateFilterCommand = @"e$template_filter 0";
   335     self.segmentedControl.selectedSegmentIndex == 0;
       
   336     self.mazeSizeCommand = @"e$maze_size 0";
   458     self.mazeSizeCommand = @"e$maze_size 0";
   337     self.mapGenCommand = @"e$mapgen 0";
   459     self.mapGenCommand = @"e$mapgen 0";
   338 }
   460     
   339 
   461     oldValue = 5;
   340 -(void) viewWillAppear:(BOOL)animated {
   462     oldPage = 0;
   341     [super viewWillAppear:animated];
   463 }
       
   464 
       
   465 -(void) viewDidAppear:(BOOL) animated {
       
   466     [super viewDidAppear:animated];
   342     [self updatePreview];
   467     [self updatePreview];
   343 }
       
   344 
       
   345 -(void) didReceiveMemoryWarning {
       
   346     // Releases the view if it doesn't have a superview.
       
   347     [super didReceiveMemoryWarning];
       
   348     // Release any cached data, images, etc that aren't in use.
       
   349 }
   468 }
   350 
   469 
   351 #pragma mark -
   470 #pragma mark -
   352 #pragma mark memory
   471 #pragma mark memory
       
   472 -(void) didReceiveMemoryWarning {
       
   473     [super didReceiveMemoryWarning];
       
   474 }
       
   475 
   353 -(void) viewDidUnload {
   476 -(void) viewDidUnload {
   354     self.previewButton = nil;
   477     self.previewButton = nil;
   355     self.seedCommand = nil;
       
   356     self.seedCommand = nil;
   478     self.seedCommand = nil;
   357     self.templateFilterCommand = nil;
   479     self.templateFilterCommand = nil;
   358     self.mapGenCommand = nil;
   480     self.mapGenCommand = nil;
   359     self.mazeSizeCommand = nil;
   481     self.mazeSizeCommand = nil;
       
   482     self.themeCommand = nil;
       
   483     
   360     self.previewButton = nil;
   484     self.previewButton = nil;
   361     self.tableView = nil;
   485     self.tableView = nil;
   362     self.maxLabel = nil;
   486     self.maxLabel = nil;
   363     self.sizeLabel = nil;
   487     self.sizeLabel = nil;
   364     self.segmentedControl = nil;
   488     self.segmentedControl = nil;
   365     self.slider = nil;
   489     self.slider = nil;
       
   490     
       
   491     self.lastIndexPath = nil;
       
   492     self.themeArray = nil;
       
   493     self.mapArray = nil;
       
   494     
   366     [super viewDidUnload];
   495     [super viewDidUnload];
   367 }
   496 }
   368 
   497 
   369 -(void) dealloc {
   498 -(void) dealloc {
   370     [seedCommand release];
   499     [seedCommand release];
   371     [templateFilterCommand release];
   500     [templateFilterCommand release];
   372     [mapGenCommand release];
   501     [mapGenCommand release];
   373     [mazeSizeCommand release];
   502     [mazeSizeCommand release];
       
   503     [themeCommand release];
       
   504     
   374     [previewButton release];
   505     [previewButton release];
   375     [tableView release];
   506     [tableView release];
   376     [maxLabel release];
   507     [maxLabel release];
   377     [sizeLabel release];
   508     [sizeLabel release];
   378     [segmentedControl release];
   509     [segmentedControl release];
   379     [slider release];
   510     [slider release];
       
   511     
       
   512     [lastIndexPath release];
       
   513     [themeArray release];
       
   514     [mapArray release];
       
   515     
   380     [super dealloc];
   516     [super dealloc];
   381 }
   517 }
   382 
   518 
   383 
   519 
   384 @end
   520 @end