cocoaTouch/GameConfigViewController.m
changeset 3490 016b3172b645
parent 3487 b1d00f1950c8
child 3513 f589230fa21b
equal deleted inserted replaced
3489:aedf289192f5 3490:016b3172b645
    62     
    62     
    63     [self.view addSubview:activeController.view];
    63     [self.view addSubview:activeController.view];
    64 }
    64 }
    65 
    65 
    66 -(void) startGame {
    66 -(void) startGame {
       
    67     // don't start playing if the preview is in progress
       
    68     if ([mapConfigViewController busy]) {
       
    69         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
       
    70                                                         message:NSLocalizedString(@"Before playing the preview needs to be generated",@"")
       
    71                                                        delegate:nil
       
    72                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
       
    73                                               otherButtonTitles:nil];
       
    74         [alert show];
       
    75         [alert release];
       
    76         return;
       
    77     }
       
    78     
    67     // play only if there is more than one team
    79     // play only if there is more than one team
    68     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
    80     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
    69         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
    81         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
    70                                                         message:NSLocalizedString(@"You need to select at least two teams to play a game",@"")
    82                                                         message:NSLocalizedString(@"You need to select at least two teams to play a game",@"")
    71                                                        delegate:nil
    83                                                        delegate:nil
    89                                               otherButtonTitles:nil];
   101                                               otherButtonTitles:nil];
    90         [alert show];
   102         [alert show];
    91         [alert release];
   103         [alert release];
    92         return;
   104         return;
    93     }
   105     }
       
   106     
       
   107     // create the configuration file that is going to be sent to engine
    94     NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   108     NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
    95                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   109                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
    96                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   110                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
    97                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   111                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
    98                                                                       mapConfigViewController.themeCommand,@"theme_command",
   112                                                                       mapConfigViewController.themeCommand,@"theme_command",
    99                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",nil];
   113                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",nil];
   100     [dict writeToFile:GAMECONFIG_FILE() atomically:YES];
   114     [dict writeToFile:GAMECONFIG_FILE() atomically:YES];
   101     [dict release];
   115     [dict release];
       
   116 
       
   117     // finally launch game and remove this controller
   102     [[self parentViewController] dismissModalViewControllerAnimated:YES];
   118     [[self parentViewController] dismissModalViewControllerAnimated:YES];
   103     [[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
   119     [[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
   104 }
   120 }
   105 
   121 
   106 -(void) viewDidLoad {
   122 -(void) viewDidLoad {
   135 
   151 
   136 -(void) didReceiveMemoryWarning {
   152 -(void) didReceiveMemoryWarning {
   137     // Releases the view if it doesn't have a superview.
   153     // Releases the view if it doesn't have a superview.
   138     [super didReceiveMemoryWarning];
   154     [super didReceiveMemoryWarning];
   139     // Release any cached data, images, etc that aren't in use.
   155     // Release any cached data, images, etc that aren't in use.
   140     if (mapConfigViewController.view.superview == nil ) 
   156     if (mapConfigViewController.view.superview == nil) 
   141         mapConfigViewController = nil;
   157         mapConfigViewController = nil;
   142     if (teamConfigViewController.view.superview == nil)
   158     if (teamConfigViewController.view.superview == nil)
   143         teamConfigViewController = nil;
   159         teamConfigViewController = nil;
   144     activeController = nil;
   160     activeController = nil;
   145     MSG_MEMCLEAN();
   161     MSG_MEMCLEAN();
   146 }
   162 }
   147 
   163 
   148 
   164 
   149 -(void) viewDidUnload {
   165 -(void) viewDidUnload {
   150     NSLog(@"unloading");
       
   151     activeController = nil;
   166     activeController = nil;
   152     mapConfigViewController = nil;
   167     mapConfigViewController = nil;
   153     teamConfigViewController = nil;
   168     teamConfigViewController = nil;
   154     [super viewDidUnload];
   169     [super viewDidUnload];
       
   170     MSG_DIDUNLOAD();
   155 }
   171 }
   156 
   172 
   157 
   173 
   158 -(void) dealloc {
   174 -(void) dealloc {
   159     [activeController release];
   175     [activeController release];