project_files/HedgewarsMobile/Classes/MapConfigViewController.m
changeset 3514 59dbd31e9953
parent 3513 f589230fa21b
child 3525 1d7b056ff866
equal deleted inserted replaced
3513:f589230fa21b 3514:59dbd31e9953
       
     1 //
       
     2 //  MapConfigViewController.m
       
     3 //  HedgewarsMobile
       
     4 //
       
     5 //  Created by Vittorio on 22/04/10.
       
     6 //  Copyright 2010 __MyCompanyName__. All rights reserved.
       
     7 //
       
     8 
       
     9 #import "MapConfigViewController.h"
       
    10 #import "PascalImports.h"
       
    11 #import "CommodityFunctions.h"
       
    12 #import "UIImageExtra.h"
       
    13 #import "SDL_net.h"
       
    14 #import <pthread.h>
       
    15 
       
    16 #define INDICATOR_TAG 7654
       
    17 
       
    18 @implementation MapConfigViewController
       
    19 @synthesize previewButton, maxHogs, seedCommand, templateFilterCommand, mapGenCommand, mazeSizeCommand, themeCommand,
       
    20             tableView, maxLabel, sizeLabel, segmentedControl, slider, lastIndexPath, themeArray, mapArray, busy;
       
    21 
       
    22 
       
    23 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
       
    24     return rotationManager(interfaceOrientation);
       
    25 }
       
    26 
       
    27 #pragma mark -
       
    28 #pragma mark Preview Handling
       
    29 -(int) sendToEngine: (NSString *)string {
       
    30 	unsigned char length = [string length];
       
    31 	
       
    32 	SDLNet_TCP_Send(csd, &length , 1);
       
    33 	return SDLNet_TCP_Send(csd, [string UTF8String], length);
       
    34 }
       
    35 
       
    36 -(const uint8_t *)engineProtocol:(NSInteger) port {
       
    37 	IPaddress ip;
       
    38 	BOOL serverQuit = NO;
       
    39     static uint8_t map[128*32];
       
    40     
       
    41 	if (SDLNet_Init() < 0) {
       
    42 		NSLog(@"SDLNet_Init: %s", SDLNet_GetError());
       
    43         serverQuit = YES;
       
    44 	}
       
    45 	
       
    46 	// Resolving the host using NULL make network interface to listen
       
    47 	if (SDLNet_ResolveHost(&ip, NULL, port) < 0) {
       
    48 		NSLog(@"SDLNet_ResolveHost: %s\n", SDLNet_GetError());
       
    49         serverQuit = YES;
       
    50 	}
       
    51 	
       
    52 	// Open a connection with the IP provided (listen on the host's port)
       
    53 	if (!(sd = SDLNet_TCP_Open(&ip))) {
       
    54 		NSLog(@"SDLNet_TCP_Open: %s %\n", SDLNet_GetError(), port);
       
    55         serverQuit = YES;
       
    56 	}
       
    57 	
       
    58     // launch the preview here so that we're sure the tcp channel is open
       
    59     pthread_t thread_id;
       
    60     pthread_create(&thread_id, NULL, (void *)GenLandPreview, (void *)port);
       
    61     pthread_detach(thread_id);
       
    62     
       
    63 	DLog(@"Waiting for a client on port %d", port);
       
    64 	while (!serverQuit) {
       
    65 		/* This check the sd if there is a pending connection.
       
    66 		 * If there is one, accept that, and open a new socket for communicating */
       
    67 		csd = SDLNet_TCP_Accept(sd);
       
    68 		if (NULL != csd) {			
       
    69 			DLog(@"Client found");
       
    70             
       
    71             [self sendToEngine:self.seedCommand];
       
    72             [self sendToEngine:self.templateFilterCommand];
       
    73             [self sendToEngine:self.mapGenCommand];
       
    74             [self sendToEngine:self.mazeSizeCommand];
       
    75             [self sendToEngine:@"!"];
       
    76                 
       
    77             memset(map, 0, 128*32);
       
    78             SDLNet_TCP_Recv(csd, map, 128*32);
       
    79             SDLNet_TCP_Recv(csd, &maxHogs, sizeof(uint8_t));
       
    80 
       
    81 			SDLNet_TCP_Close(csd);
       
    82 			serverQuit = YES;
       
    83 		}
       
    84 	}
       
    85 	
       
    86 	SDLNet_TCP_Close(sd);
       
    87 	SDLNet_Quit();
       
    88     return map;
       
    89 }
       
    90 
       
    91 -(void) drawingThread {
       
    92     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
       
    93     
       
    94     // select the port for IPC and launch the preview generation through engineProtocol:
       
    95     int port = randomPort();
       
    96     const uint8_t *map = [self engineProtocol:port];
       
    97     uint8_t mapExp[128*32*8];
       
    98 
       
    99     // draw the buffer (1 pixel per component, 0= transparent 1= color)
       
   100     int k = 0;
       
   101     for (int i = 0; i < 32*128; i++) {
       
   102         unsigned char byte = map[i];
       
   103         for (int j = 0; j < 8; j++) {
       
   104             // select the color based on the leftmost bit
       
   105             if ((byte & 0x80) != 0)
       
   106                 mapExp[k] = 100;
       
   107             else
       
   108                 mapExp[k] = 255;
       
   109             // shift to next bit
       
   110             byte <<= 1;
       
   111             k++;
       
   112         }
       
   113     }
       
   114     CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceGray();
       
   115     CGContextRef bitmapImage = CGBitmapContextCreate(mapExp, 256, 128, 8, 256, colorspace, kCGImageAlphaNone);
       
   116     CGColorSpaceRelease(colorspace);
       
   117     
       
   118     CGImageRef previewCGImage = CGBitmapContextCreateImage(bitmapImage);
       
   119     UIImage *previewImage = [[UIImage alloc] initWithCGImage:previewCGImage];
       
   120     CGImageRelease(previewCGImage);
       
   121 
       
   122     // set the preview image (autoreleased) in the button and the maxhog label on the main thread to prevent a leak
       
   123     [self performSelectorOnMainThread:@selector(setButtonImage:) withObject:[[previewImage retain] makeRoundCornersOfSize:CGSizeMake(12, 12)] waitUntilDone:NO];
       
   124     [self performSelectorOnMainThread:@selector(setLabelText:) withObject:[NSString stringWithFormat:@"%d", maxHogs] waitUntilDone:NO];
       
   125     
       
   126     // restore functionality of button and remove the spinning wheel on the main thread to prevent a leak
       
   127     [self performSelectorOnMainThread:@selector(turnOnWidgets) withObject:nil waitUntilDone:NO];
       
   128     
       
   129     [pool release];
       
   130     //Invoking this method should be avoided as it does not give your thread a chance to clean up any resources it allocated during its execution.
       
   131     //[NSThread exit];
       
   132 
       
   133     /*
       
   134     // http://developer.apple.com/mac/library/qa/qa2001/qa1037.html
       
   135     UIGraphicsBeginImageContext(CGSizeMake(256,128));      
       
   136     CGContextRef context = UIGraphicsGetCurrentContext();       
       
   137     UIGraphicsPushContext(context);  
       
   138 
       
   139     CGContextSetRGBFillColor(context, 0.5, 0.5, 0.7, 1.0);
       
   140     CGContextFillRect(context,CGRectMake(xc,yc,1,1));
       
   141     
       
   142     UIGraphicsPopContext();
       
   143     UIImage *previewImage = UIGraphicsGetImageFromCurrentImageContext();
       
   144     UIGraphicsEndImageContext();
       
   145     */
       
   146 }
       
   147 
       
   148 -(IBAction) updatePreview {
       
   149     // don't generate a new preview while it's already generating one
       
   150     if (busy)
       
   151         return;
       
   152     
       
   153     // generate a seed
       
   154     CFUUIDRef uuid = CFUUIDCreate(kCFAllocatorDefault);
       
   155     NSString *seed = (NSString *)CFUUIDCreateString(kCFAllocatorDefault, uuid);
       
   156     CFRelease(uuid);
       
   157     NSString *seedCmd = [[NSString alloc] initWithFormat:@"eseed {%@}", seed];
       
   158     [seed release];
       
   159     self.seedCommand = seedCmd;
       
   160     [seedCmd release];
       
   161     
       
   162     NSIndexPath *theIndex;
       
   163     if (segmentedControl.selectedSegmentIndex != 1) {
       
   164         // prevent other events and add an activity while the preview is beign generated
       
   165         [self turnOffWidgets];
       
   166         
       
   167         // remove the current preview
       
   168         [self.previewButton setImage:nil forState:UIControlStateNormal];
       
   169         
       
   170         // add a very nice spinning wheel
       
   171         UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] 
       
   172                                               initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
       
   173         indicator.center = CGPointMake(previewButton.bounds.size.width / 2, previewButton.bounds.size.height / 2);
       
   174         indicator.tag = INDICATOR_TAG;
       
   175         [indicator startAnimating];
       
   176         [self.previewButton addSubview:indicator];
       
   177         [indicator release];
       
   178         
       
   179         // let's draw in a separate thread so the gui can work; at the end it restore other widgets
       
   180         [NSThread detachNewThreadSelector:@selector(drawingThread) toTarget:self withObject:nil];
       
   181     
       
   182         theIndex = [NSIndexPath indexPathForRow:(random()%[self.themeArray count]) inSection:0];
       
   183     } else {
       
   184         theIndex = [NSIndexPath indexPathForRow:(random()%[self.mapArray count]) inSection:0];
       
   185     }
       
   186     [self.tableView reloadData];
       
   187     [self tableView:self.tableView didSelectRowAtIndexPath:theIndex];
       
   188     [self.tableView scrollToRowAtIndexPath:theIndex atScrollPosition:UITableViewScrollPositionNone animated:YES];
       
   189 }
       
   190 
       
   191 -(void) updatePreviewWithMap:(NSInteger) index {
       
   192     // change the preview button
       
   193     NSString *fileImage = [[NSString alloc] initWithFormat:@"%@/%@/preview.png", MAPS_DIRECTORY(),[self.mapArray objectAtIndex:index]];
       
   194     UIImage *image = [[UIImage alloc] initWithContentsOfFile:fileImage];
       
   195     [fileImage release];
       
   196     [self.previewButton setImage:[image makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:UIControlStateNormal];
       
   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 
       
   215 -(void) turnOffWidgets {
       
   216     busy = YES;
       
   217     self.previewButton.alpha = 0.5f;
       
   218     self.previewButton.enabled = NO;
       
   219     self.maxLabel.text = @"...";
       
   220     self.segmentedControl.enabled = NO;
       
   221     self.slider.enabled = NO;
       
   222 }
       
   223 
       
   224 -(void) turnOnWidgets {
       
   225     self.previewButton.alpha = 1.0f;
       
   226     self.previewButton.enabled = YES;
       
   227     self.segmentedControl.enabled = YES;
       
   228     self.slider.enabled = YES;
       
   229     busy = NO;
       
   230     
       
   231     UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[self.previewButton viewWithTag:INDICATOR_TAG];
       
   232     if (indicator) {
       
   233         [indicator stopAnimating];
       
   234         [indicator removeFromSuperview];
       
   235     }
       
   236 }
       
   237  
       
   238 -(void) setLabelText:(NSString *)str {
       
   239     self.maxLabel.text = str;
       
   240 }
       
   241 
       
   242 -(void) setButtonImage:(UIImage *)img {
       
   243     [self.previewButton setBackgroundImage:img forState:UIControlStateNormal];
       
   244 }
       
   245 
       
   246 -(void) restoreBackgroundImage {
       
   247     // white rounded rectangle as background image for previewButton
       
   248     UIGraphicsBeginImageContext(CGSizeMake(256,128));      
       
   249     CGContextRef context = UIGraphicsGetCurrentContext();       
       
   250     UIGraphicsPushContext(context);  
       
   251 
       
   252     CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
       
   253     CGContextFillRect(context,CGRectMake(0,0,256,128));
       
   254     
       
   255     UIGraphicsPopContext();
       
   256     UIImage *bkgImg = UIGraphicsGetImageFromCurrentImageContext();
       
   257     UIGraphicsEndImageContext();
       
   258     [self.previewButton setBackgroundImage:[[bkgImg retain] makeRoundCornersOfSize:CGSizeMake(12, 12)] forState:UIControlStateNormal];
       
   259 }
       
   260 
       
   261 #pragma mark -
       
   262 #pragma mark Table view data source
       
   263 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
       
   264     return 1;
       
   265 }
       
   266 
       
   267 -(NSInteger) tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger) section {
       
   268     if (self.segmentedControl.selectedSegmentIndex != 1)
       
   269         return [themeArray count];
       
   270     else
       
   271         return [mapArray count];
       
   272 }
       
   273 
       
   274 -(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       
   275     static NSString *CellIdentifier = @"Cell";
       
   276     NSInteger row = [indexPath row];
       
   277     
       
   278     UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
       
   279     if (cell == nil) 
       
   280         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
       
   281     
       
   282     if (self.segmentedControl.selectedSegmentIndex != 1) {
       
   283         // the % prevents a strange bug that occurs sporadically
       
   284         NSString *themeName = [self.themeArray objectAtIndex:row % [self.themeArray count]];
       
   285         cell.textLabel.text = themeName;
       
   286         UIImage *image = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/icon.png",THEMES_DIRECTORY(),themeName]];
       
   287         cell.imageView.image = image;
       
   288         [image release];
       
   289     } else {
       
   290         cell.textLabel.text = [self.mapArray objectAtIndex:row];
       
   291         cell.imageView.image = nil;
       
   292     }
       
   293     
       
   294     if (row == [self.lastIndexPath row]) 
       
   295         cell.accessoryType = UITableViewCellAccessoryCheckmark;
       
   296     else
       
   297         cell.accessoryType = UITableViewCellAccessoryNone;
       
   298 
       
   299     return cell;
       
   300 }
       
   301 
       
   302 
       
   303 #pragma mark -
       
   304 #pragma mark Table view delegate
       
   305 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
       
   306     int newRow = [indexPath row];
       
   307     int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
       
   308     
       
   309     if (newRow != oldRow) {
       
   310         if (self.segmentedControl.selectedSegmentIndex != 1) {
       
   311             NSString *theme = [self.themeArray objectAtIndex:newRow];
       
   312             self.themeCommand =  [NSString stringWithFormat:@"etheme %@", theme];
       
   313         } else
       
   314             [self updatePreviewWithMap:newRow];
       
   315 
       
   316         UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; 
       
   317         newCell.accessoryType = UITableViewCellAccessoryCheckmark;
       
   318         UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:self.lastIndexPath];
       
   319         oldCell.accessoryType = UITableViewCellAccessoryNone;
       
   320 
       
   321         self.lastIndexPath = indexPath;
       
   322         [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
       
   323     }
       
   324     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
       
   325 }
       
   326 
       
   327 #pragma mark -
       
   328 #pragma mark slider & segmentedControl
       
   329 // this updates the label and the command keys when the slider is moved, depending of the selection in segmentedControl
       
   330 // no methods are called by this routine and you can pass nil to it
       
   331 -(IBAction) sliderChanged:(id) sender {
       
   332     NSString *labelText;
       
   333     NSString *templateCommand;
       
   334     NSString *mazeCommand;
       
   335     
       
   336     switch ((int)(self.slider.value*100)) {
       
   337         case 0:
       
   338             if (self.segmentedControl.selectedSegmentIndex == 0) {
       
   339                 labelText = NSLocalizedString(@"Wacky",@"");
       
   340             } else {
       
   341                 labelText = NSLocalizedString(@"Large Floating Islands",@"");
       
   342             }
       
   343             templateCommand = @"e$template_filter 5";
       
   344             mazeCommand = @"e$maze_size 5";
       
   345             break;
       
   346         case 1:
       
   347             if (self.segmentedControl.selectedSegmentIndex == 0) {
       
   348                 labelText = NSLocalizedString(@"Cavern",@"");
       
   349             } else {
       
   350                 labelText = NSLocalizedString(@"Medium Floating Islands",@"");
       
   351             }
       
   352             templateCommand = @"e$template_filter 4";
       
   353             mazeCommand = @"e$maze_size 4";
       
   354             break;
       
   355         case 2:
       
   356             if (self.segmentedControl.selectedSegmentIndex == 0) {
       
   357                 labelText = NSLocalizedString(@"Small",@"");
       
   358             } else {
       
   359                 labelText = NSLocalizedString(@"Small Floating Islands",@"");
       
   360             }
       
   361             templateCommand = @"e$template_filter 1";
       
   362             mazeCommand = @"e$maze_size 3";
       
   363             break;
       
   364         case 3:
       
   365             if (self.segmentedControl.selectedSegmentIndex == 0) {
       
   366                 labelText = NSLocalizedString(@"Medium",@"");
       
   367             } else {
       
   368                 labelText = NSLocalizedString(@"Large Tunnels",@"");
       
   369             }
       
   370             templateCommand = @"e$template_filter 2";
       
   371             mazeCommand = @"e$maze_size 2";
       
   372             break;
       
   373         case 4:
       
   374             if (self.segmentedControl.selectedSegmentIndex == 0) {
       
   375                 labelText = NSLocalizedString(@"Large",@"");
       
   376             } else {
       
   377                 labelText = NSLocalizedString(@"Medium Tunnels",@"");
       
   378             }
       
   379             templateCommand = @"e$template_filter 3";
       
   380             mazeCommand = @"e$maze_size 1";
       
   381             break;
       
   382         case 5:
       
   383             if (self.segmentedControl.selectedSegmentIndex == 0) {
       
   384                 labelText = NSLocalizedString(@"All",@"");
       
   385             } else {
       
   386                 labelText = NSLocalizedString(@"Small Tunnels",@"");
       
   387             }
       
   388             templateCommand = @"e$template_filter 0";
       
   389             mazeCommand = @"e$maze_size 0";
       
   390             break;
       
   391         default:
       
   392             labelText = nil;
       
   393             templateCommand = nil;
       
   394             mazeCommand = nil;
       
   395             break;
       
   396     }
       
   397     
       
   398     self.sizeLabel.text = labelText;
       
   399     self.templateFilterCommand = templateCommand;
       
   400     self.mazeSizeCommand = mazeCommand;
       
   401 }
       
   402 
       
   403 // update preview (if not busy and if its value really changed) as soon as the user lifts its finger up
       
   404 -(IBAction) sliderEndedChanging:(id) sender {
       
   405     int num = (int) (self.slider.value * 100);
       
   406     if (oldValue != num) {
       
   407         [self updatePreview];
       
   408         oldValue = num;
       
   409     }
       
   410 }
       
   411 
       
   412 // perform actions based on the activated section, then call updatePreview to visually update the selection 
       
   413 // updatePreview will call didSelectRowAtIndexPath which will call the right update routine)
       
   414 // and if necessary update the table with a slide animation
       
   415 -(IBAction) segmentedControlChanged:(id) sender {
       
   416     NSString *mapgen;
       
   417     NSInteger newPage = self.segmentedControl.selectedSegmentIndex;
       
   418     
       
   419     switch (newPage) {
       
   420         case 0: // Random
       
   421             mapgen = @"e$mapgen 0";
       
   422             [self sliderChanged:nil];
       
   423             self.slider.enabled = YES;
       
   424             break;
       
   425             
       
   426         case 1: // Map
       
   427             mapgen = @"e$mapgen 0";
       
   428             self.slider.enabled = NO;
       
   429             self.sizeLabel.text = @".";
       
   430             [self restoreBackgroundImage];
       
   431             break;
       
   432             
       
   433         case 2: // Maze
       
   434             mapgen = @"e$mapgen 1";
       
   435             [self sliderChanged:nil];
       
   436             self.slider.enabled = YES;
       
   437             break;
       
   438         
       
   439         default:
       
   440             mapgen = nil;
       
   441             break;
       
   442     }
       
   443     self.mapGenCommand = mapgen;
       
   444     [self updatePreview];
       
   445     
       
   446     // nice animation for updating the table when appropriate (on iphone)
       
   447     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
       
   448         if (((oldPage == 0 || oldPage == 2) && newPage == 1) ||
       
   449             (oldPage == 1 && (newPage == 0 || newPage == 2))) {
       
   450             [UIView beginAnimations:@"moving out table" context:NULL];
       
   451             self.tableView.frame = CGRectMake(480, 0, 185, 276);
       
   452             [UIView commitAnimations];
       
   453             [self performSelector:@selector(moveTable) withObject:nil afterDelay:0.2];
       
   454         }
       
   455     oldPage = newPage;
       
   456 }
       
   457 
       
   458 // update data when table is not visible and then show it
       
   459 -(void) moveTable {
       
   460     [self.tableView reloadData];
       
   461     
       
   462     [UIView beginAnimations:@"moving in table" context:NULL];
       
   463     self.tableView.frame = CGRectMake(295, 0, 185, 276);
       
   464     [UIView commitAnimations];
       
   465 }
       
   466 
       
   467 #pragma mark -
       
   468 #pragma mark view management
       
   469 -(void) viewDidLoad {
       
   470     [super viewDidLoad];
       
   471     
       
   472     srandom(time(NULL));
       
   473     
       
   474     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
       
   475     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
       
   476 
       
   477     // themes.cfg contains all the user-selectable themes
       
   478     NSString *string = [[NSString alloc] initWithContentsOfFile:[THEMES_DIRECTORY() stringByAppendingString:@"/themes.cfg"]
       
   479                                                        encoding:NSUTF8StringEncoding 
       
   480                                                           error:NULL];
       
   481     NSMutableArray *array = [[NSMutableArray alloc] initWithArray:[string componentsSeparatedByString:@"\n"]];
       
   482     [string release];
       
   483     // remove a trailing "" element
       
   484     [array removeLastObject];
       
   485     self.themeArray = array;
       
   486     [array release];
       
   487     self.mapArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MAPS_DIRECTORY() error:NULL];
       
   488 
       
   489     self.tableView.rowHeight = 42;
       
   490     busy = NO;
       
   491     
       
   492     // draw a white background
       
   493     [self restoreBackgroundImage];
       
   494     
       
   495     // initialize some "default" values
       
   496     self.sizeLabel.text = NSLocalizedString(@"All",@"");
       
   497     self.slider.value = 0.05f;
       
   498     self.segmentedControl.selectedSegmentIndex = 0;
       
   499 
       
   500     self.templateFilterCommand = @"e$template_filter 0";
       
   501     self.mazeSizeCommand = @"e$maze_size 0";
       
   502     self.mapGenCommand = @"e$mapgen 0";
       
   503     self.lastIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
       
   504     
       
   505     oldValue = 5;
       
   506     oldPage = 0;
       
   507 }
       
   508 
       
   509 -(void) viewDidAppear:(BOOL) animated {
       
   510     [super viewDidAppear:animated];
       
   511     [self updatePreview];
       
   512 }
       
   513 
       
   514 #pragma mark -
       
   515 #pragma mark memory
       
   516 -(void) didReceiveMemoryWarning {
       
   517     [super didReceiveMemoryWarning];
       
   518 }
       
   519 
       
   520 -(void) viewDidUnload {
       
   521     self.previewButton = nil;
       
   522     self.seedCommand = nil;
       
   523     self.templateFilterCommand = nil;
       
   524     self.mapGenCommand = nil;
       
   525     self.mazeSizeCommand = nil;
       
   526     self.themeCommand = nil;
       
   527     
       
   528     self.previewButton = nil;
       
   529     self.tableView = nil;
       
   530     self.maxLabel = nil;
       
   531     self.sizeLabel = nil;
       
   532     self.segmentedControl = nil;
       
   533     self.slider = nil;
       
   534     
       
   535     self.lastIndexPath = nil;
       
   536     self.themeArray = nil;
       
   537     self.mapArray = nil;
       
   538     
       
   539     [super viewDidUnload];
       
   540     MSG_DIDUNLOAD();
       
   541 }
       
   542 
       
   543 -(void) dealloc {
       
   544     [seedCommand release];
       
   545     [templateFilterCommand release];
       
   546     [mapGenCommand release];
       
   547     [mazeSizeCommand release];
       
   548     [themeCommand release];
       
   549     
       
   550     [previewButton release];
       
   551     [tableView release];
       
   552     [maxLabel release];
       
   553     [sizeLabel release];
       
   554     [segmentedControl release];
       
   555     [slider release];
       
   556     
       
   557     [lastIndexPath release];
       
   558     [themeArray release];
       
   559     [mapArray release];
       
   560     
       
   561     [super dealloc];
       
   562 }
       
   563 
       
   564 
       
   565 @end