project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 3697 d5b30d6373fc
parent 3662 a44406f4369b
child 3703 12d17c6e8855
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    41                                                       otherButtonTitles:nil];
    41                                                       otherButtonTitles:nil];
    42                 [alert show];
    42                 [alert show];
    43                 [alert release];
    43                 [alert release];
    44             } else {
    44             } else {
    45                 [[self parentViewController] dismissModalViewControllerAnimated:YES];
    45                 [[self parentViewController] dismissModalViewControllerAnimated:YES];
    46                 
    46 
    47             }
    47             }
    48             break;
    48             break;
    49         case 1:
    49         case 1:
    50             theButton.enabled = NO;
    50             theButton.enabled = NO;
    51             [self startGame:theButton];
    51             [self startGame:theButton];
    81                 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    81                 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    82             }
    82             }
    83             activeController = schemeWeaponConfigViewController;
    83             activeController = schemeWeaponConfigViewController;
    84             break;
    84             break;
    85     }
    85     }
    86     
    86 
    87     // this message is compulsory otherwise the table won't be loaded at all
    87     // this message is compulsory otherwise the table won't be loaded at all
    88     [activeController viewWillAppear:NO];      
    88     [activeController viewWillAppear:NO];
    89     [self.view addSubview:activeController.view];
    89     [self.view addSubview:activeController.view];
    90 }
    90 }
    91 
    91 
    92 -(void) startGame:(UIButton *)button {
    92 -(void) startGame:(UIButton *)button {
    93     button.enabled = YES;
    93     button.enabled = YES;
   101                                               otherButtonTitles:nil];
   101                                               otherButtonTitles:nil];
   102         [alert show];
   102         [alert show];
   103         [alert release];
   103         [alert release];
   104         return;
   104         return;
   105     }
   105     }
   106     
   106 
   107     // play only if there is more than one team
   107     // play only if there is more than one team
   108     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
   108     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
   109         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
   109         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
   110                                                         message:NSLocalizedString(@"Select at least two teams to play a game",@"")
   110                                                         message:NSLocalizedString(@"Select at least two teams to play a game",@"")
   111                                                        delegate:nil
   111                                                        delegate:nil
   113                                               otherButtonTitles:nil];
   113                                               otherButtonTitles:nil];
   114         [alert show];
   114         [alert show];
   115         [alert release];
   115         [alert release];
   116         return;
   116         return;
   117     }
   117     }
   118     
   118 
   119     // play if there's room for enough hogs in the selected map
   119     // play if there's room for enough hogs in the selected map
   120     int hogs = 0;
   120     int hogs = 0;
   121     for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams)
   121     for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams)
   122         hogs += [[teamData objectForKey:@"number"] intValue];
   122         hogs += [[teamData objectForKey:@"number"] intValue];
   123 
   123 
   129                                               otherButtonTitles:nil];
   129                                               otherButtonTitles:nil];
   130         [alert show];
   130         [alert show];
   131         [alert release];
   131         [alert release];
   132         return;
   132         return;
   133     }
   133     }
   134     
   134 
   135     if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) {
   135     if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) {
   136         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"")
   136         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"")
   137                                                         message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"")
   137                                                         message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"")
   138                                                        delegate:nil
   138                                                        delegate:nil
   139                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   139                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   140                                               otherButtonTitles:nil];
   140                                               otherButtonTitles:nil];
   141         [alert show];
   141         [alert show];
   142         [alert release];
   142         [alert release];
   143         return;
   143         return;
   144     }
   144     }
   145     
   145 
   146     // create the configuration file that is going to be sent to engine
   146     // create the configuration file that is going to be sent to engine
   147     NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   147     NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   148                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   148                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   149                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   149                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   150                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   150                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   152                                                                       mapConfigViewController.staticMapCommand,@"staticmap_command",
   152                                                                       mapConfigViewController.staticMapCommand,@"staticmap_command",
   153                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
   153                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
   154                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
   154                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
   155                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
   155                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
   156                                                                       nil];
   156                                                                       nil];
   157     
   157 
   158     // finally launch game and remove this controller
   158     // finally launch game and remove this controller
   159     DLog(@"sending config %@", gameDictionary);
   159     DLog(@"sending config %@", gameDictionary);
   160     
   160 
   161     if ([[gameDictionary allKeys] count] == 9) {
   161     if ([[gameDictionary allKeys] count] == 9) {
   162         [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary];
   162         [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary];
   163     } else {
   163     } else {
   164         DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n",
   164         DLog(@"gameconfig data not complete!!\nmapConfigViewController = %@\nteamConfigViewController = %@\nschemeWeaponConfigViewController = %@\n",
   165              mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController);
   165              mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController);
   166         [self.parentViewController dismissModalViewControllerAnimated:YES];
   166         [self.parentViewController dismissModalViewControllerAnimated:YES];
   167         
   167 
   168         // present an alert to the user, with an image on the ipad (too big for the iphone)
   168         // present an alert to the user, with an image on the ipad (too big for the iphone)
   169         NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@"");
   169         NSString *msg = NSLocalizedString(@"Something went wrong with your configuration. Please try again.",@"");
   170         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   170         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
   171             msg = [msg stringByAppendingString:@"\n\n\n\n\n\n\n\n"];    // this makes space for the image
   171             msg = [msg stringByAppendingString:@"\n\n\n\n\n\n\n\n"];    // this makes space for the image
   172         
   172 
   173         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops"
   173         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoops"
   174                                                         message:msg
   174                                                         message:msg
   175                                                        delegate:nil
   175                                                        delegate:nil
   176                                               cancelButtonTitle:@"Ok"
   176                                               cancelButtonTitle:@"Ok"
   177                                               otherButtonTitles:nil];
   177                                               otherButtonTitles:nil];
   178         
   178 
   179         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   179         if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   180             UIImageView *deniedImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"denied.png"]];
   180             UIImageView *deniedImg = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"denied.png"]];
   181             deniedImg.frame = CGRectMake(25, 80, 240, 160);
   181             deniedImg.frame = CGRectMake(25, 80, 240, 160);
   182             [alert addSubview:deniedImg];
   182             [alert addSubview:deniedImg];
   183             [deniedImg release];
   183             [deniedImg release];
   188 
   188 
   189 }
   189 }
   190 
   190 
   191 -(void) viewDidLoad {
   191 -(void) viewDidLoad {
   192     self.view.backgroundColor = [UIColor blackColor];
   192     self.view.backgroundColor = [UIColor blackColor];
   193     
   193 
   194     CGRect screen = [[UIScreen mainScreen] bounds];
   194     CGRect screen = [[UIScreen mainScreen] bounds];
   195     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   195     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   196 
   196 
   197     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   197     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   198         if (mapConfigViewController == nil)
   198         if (mapConfigViewController == nil)
   218         // this must be loaded & added to auto set default scheme and ammo
   218         // this must be loaded & added to auto set default scheme and ammo
   219         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   219         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   220         [self.view addSubview:schemeWeaponConfigViewController.view];
   220         [self.view addSubview:schemeWeaponConfigViewController.view];
   221     }
   221     }
   222     activeController = mapConfigViewController;
   222     activeController = mapConfigViewController;
   223     
   223 
   224     [self.view addSubview:mapConfigViewController.view];
   224     [self.view addSubview:mapConfigViewController.view];
   225     
   225 
   226     [super viewDidLoad];
   226     [super viewDidLoad];
   227 }
   227 }
   228 
   228 
   229 -(void) viewWillAppear:(BOOL)animated {
   229 -(void) viewWillAppear:(BOOL)animated {
   230     [mapConfigViewController viewWillAppear:animated];
   230     [mapConfigViewController viewWillAppear:animated];
   231     [teamConfigViewController viewWillAppear:animated];
   231     [teamConfigViewController viewWillAppear:animated];
   232     [schemeWeaponConfigViewController viewWillAppear:animated];
   232     [schemeWeaponConfigViewController viewWillAppear:animated];
   233     // ADD other controllers here
   233     // ADD other controllers here
   234      
   234 
   235     [super viewWillAppear:animated];
   235     [super viewWillAppear:animated];
   236 }
   236 }
   237 
   237 
   238 -(void) viewDidAppear:(BOOL)animated {
   238 -(void) viewDidAppear:(BOOL)animated {
   239     [mapConfigViewController viewDidAppear:animated];
   239     [mapConfigViewController viewDidAppear:animated];
   241     [schemeWeaponConfigViewController viewDidAppear:animated];
   241     [schemeWeaponConfigViewController viewDidAppear:animated];
   242     [super viewDidAppear:animated];
   242     [super viewDidAppear:animated];
   243 }
   243 }
   244 
   244 
   245 -(void) didReceiveMemoryWarning {
   245 -(void) didReceiveMemoryWarning {
   246     if (activeController.view.superview == nil) 
   246     if (activeController.view.superview == nil)
   247         activeController = nil;
   247         activeController = nil;
   248     // Releases the view if it doesn't have a superview.
   248     // Releases the view if it doesn't have a superview.
   249     [super didReceiveMemoryWarning];
   249     [super didReceiveMemoryWarning];
   250     // Release any cached data, images, etc that aren't in use.
   250     // Release any cached data, images, etc that aren't in use.
   251     if (mapConfigViewController.view.superview == nil) 
   251     if (mapConfigViewController.view.superview == nil)
   252         mapConfigViewController = nil;
   252         mapConfigViewController = nil;
   253     if (teamConfigViewController.view.superview == nil)
   253     if (teamConfigViewController.view.superview == nil)
   254         teamConfigViewController = nil;
   254         teamConfigViewController = nil;
   255     if (schemeWeaponConfigViewController.view.superview == nil)
   255     if (schemeWeaponConfigViewController.view.superview == nil)
   256         schemeWeaponConfigViewController = nil;
   256         schemeWeaponConfigViewController = nil;