project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 3971 5c82ee165ed5
parent 3948 24daa33a3114
child 3973 0d1a420531ef
equal deleted inserted replaced
3970:0f6e3219c108 3971:5c82ee165ed5
    46         theButton = (UIButton *)sender;
    46         theButton = (UIButton *)sender;
    47 
    47 
    48     switch (theButton.tag) {
    48     switch (theButton.tag) {
    49         case 0:
    49         case 0:
    50             playSound(@"backSound");
    50             playSound(@"backSound");
    51             if ([mapConfigViewController busy]) {
    51             if ([self.mapConfigViewController busy]) {
    52                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
    52                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
    53                                                                 message:NSLocalizedString(@"Before returning the preview needs to be generated",@"")
    53                                                                 message:NSLocalizedString(@"Before returning the preview needs to be generated",@"")
    54                                                                delegate:nil
    54                                                                delegate:nil
    55                                                       cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
    55                                                       cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
    56                                                       otherButtonTitles:nil];
    56                                                       otherButtonTitles:nil];
   119     }
   119     }
   120 }
   120 }
   121 
   121 
   122 -(BOOL) isEverythingSet {
   122 -(BOOL) isEverythingSet {
   123     // don't start playing if the preview is in progress
   123     // don't start playing if the preview is in progress
   124     if ([mapConfigViewController busy]) {
   124     if ([self.mapConfigViewController busy]) {
   125         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
   125         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
   126                                                         message:NSLocalizedString(@"Before playing the preview needs to be generated",@"")
   126                                                         message:NSLocalizedString(@"Before playing the preview needs to be generated",@"")
   127                                                        delegate:nil
   127                                                        delegate:nil
   128                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   128                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   129                                               otherButtonTitles:nil];
   129                                               otherButtonTitles:nil];
   131         [alert release];
   131         [alert release];
   132         return NO;
   132         return NO;
   133     }
   133     }
   134     
   134     
   135     // play only if there is more than one team
   135     // play only if there is more than one team
   136     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
   136     if ([self.teamConfigViewController.listOfSelectedTeams count] < 2) {
   137         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
   137         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
   138                                                         message:NSLocalizedString(@"Select at least two teams to play a game",@"")
   138                                                         message:NSLocalizedString(@"Select at least two teams to play a game",@"")
   139                                                        delegate:nil
   139                                                        delegate:nil
   140                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   140                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   141                                               otherButtonTitles:nil];
   141                                               otherButtonTitles:nil];
   147     // play if there's room for enough hogs in the selected map
   147     // play if there's room for enough hogs in the selected map
   148     int hogs = 0;
   148     int hogs = 0;
   149     for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams)
   149     for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams)
   150         hogs += [[teamData objectForKey:@"number"] intValue];
   150         hogs += [[teamData objectForKey:@"number"] intValue];
   151     
   151     
   152     if (hogs > mapConfigViewController.maxHogs) {
   152     if (hogs > self.mapConfigViewController.maxHogs) {
   153         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"")
   153         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"")
   154                                                         message:NSLocalizedString(@"The map is too small for that many hogs",@"")
   154                                                         message:NSLocalizedString(@"The map is too small for that many hogs",@"")
   155                                                        delegate:nil
   155                                                        delegate:nil
   156                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   156                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   157                                               otherButtonTitles:nil];
   157                                               otherButtonTitles:nil];
   158         [alert show];
   158         [alert show];
   159         [alert release];
   159         [alert release];
   160         return NO;
   160         return NO;
   161     }
   161     }
   162     
   162     
   163     if ([teamConfigViewController.listOfSelectedTeams count] > HW_getMaxNumberOfTeams()) {
   163     if ([self.teamConfigViewController.listOfSelectedTeams count] > HW_getMaxNumberOfTeams()) {
   164         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many teams",@"")
   164         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many teams",@"")
   165                                                         message:NSLocalizedString(@"Max six teams are allowed in the same game",@"")
   165                                                         message:NSLocalizedString(@"Max six teams are allowed in the same game",@"")
   166                                                        delegate:nil
   166                                                        delegate:nil
   167                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   167                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   168                                               otherButtonTitles:nil];
   168                                               otherButtonTitles:nil];
   169         [alert show];
   169         [alert show];
   170         [alert release];
   170         [alert release];
   171         return NO;
   171         return NO;
   172     }
   172     }
   173     
   173     
   174     if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) {
   174     if ([self.schemeWeaponConfigViewController.selectedScheme length] == 0 || [self.schemeWeaponConfigViewController.selectedWeapon length] == 0 ) {
   175         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"")
   175         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"")
   176                                                         message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"")
   176                                                         message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"")
   177                                                        delegate:nil
   177                                                        delegate:nil
   178                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   178                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   179                                               otherButtonTitles:nil];
   179                                               otherButtonTitles:nil];
   190     
   190     
   191     if ([self isEverythingSet] == NO)
   191     if ([self isEverythingSet] == NO)
   192         return;
   192         return;
   193 
   193 
   194     // create the configuration file that is going to be sent to engine
   194     // create the configuration file that is going to be sent to engine
   195     NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   195     NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
   196                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   196                                     self.mapConfigViewController.seedCommand,@"seed_command",
   197                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   197                                     self.mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   198                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   198                                     self.mapConfigViewController.mapGenCommand,@"mapgen_command",
   199                                                                       mapConfigViewController.themeCommand,@"theme_command",
   199                                     self.mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   200                                                                       mapConfigViewController.staticMapCommand,@"staticmap_command",
   200                                     self.mapConfigViewController.themeCommand,@"theme_command",
   201                                                                       mapConfigViewController.missionCommand,@"mission_command",  
   201                                     self.mapConfigViewController.staticMapCommand,@"staticmap_command",
   202                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
   202                                     self.mapConfigViewController.missionCommand,@"mission_command",  
   203                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
   203                                     self.teamConfigViewController.listOfSelectedTeams,@"teams_list",
   204                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
   204                                     self.schemeWeaponConfigViewController.selectedScheme,@"scheme",
   205                                                                       [NSNumber numberWithInt:self.interfaceOrientation],@"orientation",
   205                                     self.schemeWeaponConfigViewController.selectedWeapon,@"weapon",
   206                                                                       nil];
   206                                     [NSNumber numberWithInt:self.interfaceOrientation],@"orientation",
   207 
   207                                     nil];
       
   208     
   208     // finally launch game and remove this controller
   209     // finally launch game and remove this controller
   209     DLog(@"sending config %@", gameDictionary);
   210     DLog(@"sending config %@", gameDictionary);
   210 
   211 
   211     if ([[gameDictionary allKeys] count] == 11) {
   212     if ([[gameDictionary allKeys] count] == 11) {
   212         NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:gameDictionary,@"game_dictionary", @"",@"savefile",
   213         NSDictionary *allDataNecessary = [NSDictionary dictionaryWithObjectsAndKeys:gameDictionary,@"game_dictionary", @"",@"savefile",
   213                                                                                     [NSNumber numberWithBool:NO],@"netgame", nil];
   214                                                                                     [NSNumber numberWithBool:NO],@"netgame", nil];
   214         [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
   215         [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:allDataNecessary];
   215         
   216         
   216         // tell controllers that they're being reloaded
   217         // tell controllers that they're being reloaded
   217         [mapConfigViewController viewWillAppear:YES];
   218         [self.mapConfigViewController viewWillAppear:YES];
       
   219         [self.schemeWeaponConfigViewController viewWillAppear:YES];
   218     } else {
   220     } else {
   219         DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n",
   221         DLog(@"gameconfig data not complete!!");
   220              mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController);
       
   221         [self.parentViewController dismissModalViewControllerAnimated:YES];
   222         [self.parentViewController dismissModalViewControllerAnimated:YES];
   222 
   223 
   223         // present an alert to the user, with an image on the ipad (too big for the iphone)
   224         // present an alert to the user, with an image on the ipad (too big for the iphone)
   224         NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@"");
   225         NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@"");
   225         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   226         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   315 
   316 
   316 -(void) viewWillAppear:(BOOL)animated {
   317 -(void) viewWillAppear:(BOOL)animated {
   317     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   318     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   318         [NSThread detachNewThreadSelector:@selector(loadNiceHogs) toTarget:self withObject:nil];
   319         [NSThread detachNewThreadSelector:@selector(loadNiceHogs) toTarget:self withObject:nil];
   319 
   320 
   320     [mapConfigViewController viewWillAppear:animated];
   321     [self.mapConfigViewController viewWillAppear:animated];
   321     [teamConfigViewController viewWillAppear:animated];
   322     [self.teamConfigViewController viewWillAppear:animated];
   322     [schemeWeaponConfigViewController viewWillAppear:animated];
   323     [self.schemeWeaponConfigViewController viewWillAppear:animated];
   323     // add other controllers here and below
   324     // add other controllers here and below
   324 
   325 
   325     [super viewWillAppear:animated];
   326     [super viewWillAppear:animated];
   326 }
   327 }
   327 
   328 
   328 -(void) viewDidAppear:(BOOL)animated {
   329 -(void) viewDidAppear:(BOOL)animated {
   329     [mapConfigViewController viewDidAppear:animated];
   330     [self.mapConfigViewController viewDidAppear:animated];
   330     [teamConfigViewController viewDidAppear:animated];
   331     [self.teamConfigViewController viewDidAppear:animated];
   331     [schemeWeaponConfigViewController viewDidAppear:animated];
   332     [self.schemeWeaponConfigViewController viewDidAppear:animated];
   332     [super viewDidAppear:animated];
   333     [super viewDidAppear:animated];
   333 }
   334 }
   334 
   335 
   335 -(void) viewWillDisappear:(BOOL)animated {
   336 -(void) viewWillDisappear:(BOOL)animated {
   336     [mapConfigViewController viewWillDisappear:animated];
   337     [self.mapConfigViewController viewWillDisappear:animated];
   337     [teamConfigViewController viewWillDisappear:animated];
   338     [self.teamConfigViewController viewWillDisappear:animated];
   338     [schemeWeaponConfigViewController viewWillDisappear:animated];
   339     [self.schemeWeaponConfigViewController viewWillDisappear:animated];
   339     [super viewWillDisappear:animated];
   340     [super viewWillDisappear:animated];
   340 }
   341 }
   341 
   342 
   342 -(void) viewDidDisappear:(BOOL)animated {
   343 -(void) viewDidDisappear:(BOOL)animated {
   343     [mapConfigViewController viewDidDisappear:animated];
   344     [self.mapConfigViewController viewDidDisappear:animated];
   344     [teamConfigViewController viewDidDisappear:animated];
   345     [self.teamConfigViewController viewDidDisappear:animated];
   345     [schemeWeaponConfigViewController viewDidDisappear:animated];
   346     [self.schemeWeaponConfigViewController viewDidDisappear:animated];
   346     [super viewDidDisappear:animated];
   347     [super viewDidDisappear:animated];
   347 }
   348 }
   348 
   349 
   349 -(void) didReceiveMemoryWarning {
   350 -(void) didReceiveMemoryWarning {
   350     // Releases the view if it doesn't have a superview.
   351     if (self.mapConfigViewController.view.superview == nil)
   351     if (mapConfigViewController.view.superview == nil)
   352         self.mapConfigViewController = nil;
   352         mapConfigViewController = nil;
   353     if (self.teamConfigViewController.view.superview == nil)
   353     if (teamConfigViewController.view.superview == nil)
   354         self.teamConfigViewController = nil;
   354         teamConfigViewController = nil;
   355     if (self.schemeWeaponConfigViewController.view.superview == nil)
   355     if (schemeWeaponConfigViewController.view.superview == nil)
   356         self.schemeWeaponConfigViewController = nil;
   356         schemeWeaponConfigViewController = nil;
   357     if (self.helpPage.view.superview == nil)
   357     if (helpPage.view.superview == nil)
   358         self.helpPage = nil;
   358         helpPage = nil;
       
   359 
   359 
   360     // Release any cached data, images, etc that aren't in use.
   360     // Release any cached data, images, etc that aren't in use.
   361     self.imgContainer = nil;
   361     self.imgContainer = nil;
   362     MSG_MEMCLEAN();
   362     MSG_MEMCLEAN();
   363     [super didReceiveMemoryWarning];
   363     [super didReceiveMemoryWarning];