project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 3616 85d69ddb41b6
parent 3548 4d220ee7c75f
child 3619 1155d8970646
equal deleted inserted replaced
3615:b78d7959540a 3616:85d69ddb41b6
    15 
    15 
    16 @implementation GameConfigViewController
    16 @implementation GameConfigViewController
    17 
    17 
    18 
    18 
    19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    19 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    20     // dirty trick to avoid rotating below the curl
    20     return rotationManager(interfaceOrientation);
    21     return interfaceOrientation == self.parentViewController.interfaceOrientation;
       
    22 }
    21 }
    23 
    22 
    24 -(IBAction) buttonPressed:(id) sender {
    23 -(IBAction) buttonPressed:(id) sender {
    25     // works even if it's not actually a button
    24     // works even if it's not actually a button
    26     UIButton *theButton = (UIButton *)sender;
    25     UIButton *theButton = (UIButton *)sender;
    86     }
    85     }
    87     
    86     
    88     // play only if there is more than one team
    87     // play only if there is more than one team
    89     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
    88     if ([teamConfigViewController.listOfSelectedTeams count] < 2) {
    90         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
    89         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too few teams playing",@"")
    91                                                         message:NSLocalizedString(@"You need to select at least two teams to play a game",@"")
    90                                                         message:NSLocalizedString(@"Select at least two teams to play a game",@"")
    92                                                        delegate:nil
    91                                                        delegate:nil
    93                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
    92                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
    94                                               otherButtonTitles:nil];
    93                                               otherButtonTitles:nil];
    95         [alert show];
    94         [alert show];
    96         [alert release];
    95         [alert release];
   102     for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams)
   101     for (NSDictionary *teamData in teamConfigViewController.listOfSelectedTeams)
   103         hogs += [[teamData objectForKey:@"number"] intValue];
   102         hogs += [[teamData objectForKey:@"number"] intValue];
   104 
   103 
   105     if (hogs > mapConfigViewController.maxHogs) {
   104     if (hogs > mapConfigViewController.maxHogs) {
   106         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"")
   105         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Too many hogs",@"")
   107                                                         message:NSLocalizedString(@"The map you selected is too small for that many hogs",@"")
   106                                                         message:NSLocalizedString(@"The map is too small for that many hogs",@"")
   108                                                        delegate:nil
   107                                                        delegate:nil
   109                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   108                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   110                                               otherButtonTitles:nil];
   109                                               otherButtonTitles:nil];
   111         [alert show];
   110         [alert show];
   112         [alert release];
   111         [alert release];
   113         return;
   112         return;
   114     }
   113     }
   115     
   114     
   116     if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) {
   115     if ([schemeWeaponConfigViewController.selectedScheme length] == 0 || [schemeWeaponConfigViewController.selectedWeapon length] == 0 ) {
   117         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"")
   116         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Missing detail",@"")
   118                                                         message:NSLocalizedString(@"Make sure you selected one Scheme and one Weapon for this game",@"")
   117                                                         message:NSLocalizedString(@"Select one Scheme and one Weapon for this game",@"")
   119                                                        delegate:nil
   118                                                        delegate:nil
   120                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   119                                               cancelButtonTitle:NSLocalizedString(@"Ok, got it",@"")
   121                                               otherButtonTitles:nil];
   120                                               otherButtonTitles:nil];
   122         [alert show];
   121         [alert show];
   123         [alert release];
   122         [alert release];
   124         return;
   123         return;
   125     }
   124     }
   126     
   125     
   127     // create the configuration file that is going to be sent to engine
   126     // create the configuration file that is going to be sent to engine
   128     NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   127     NSDictionary *gameDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   129                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   128                                                                       mapConfigViewController.templateFilterCommand,@"templatefilter_command",
   130                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   129                                                                       mapConfigViewController.mapGenCommand,@"mapgen_command",
   131                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   130                                                                       mapConfigViewController.mazeSizeCommand,@"mazesize_command",
   132                                                                       mapConfigViewController.themeCommand,@"theme_command",
   131                                                                       mapConfigViewController.themeCommand,@"theme_command",
   133                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
   132                                                                       teamConfigViewController.listOfSelectedTeams,@"teams_list",
   134                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
   133                                                                       schemeWeaponConfigViewController.selectedScheme,@"scheme",
   135                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
   134                                                                       schemeWeaponConfigViewController.selectedWeapon,@"weapon",
   136                                                                       nil];
   135                                                                       nil];
   137     [dict writeToFile:GAMECONFIG_FILE() atomically:YES];
       
   138     [dict release];
       
   139 
   136 
   140     // finally launch game and remove this controller
   137     // finally launch game and remove this controller
   141     [[self parentViewController] dismissModalViewControllerAnimated:YES];
   138     [[self parentViewController] dismissModalViewControllerAnimated:YES];
   142     [[SDLUIKitDelegate sharedAppDelegate] startSDLgame];
   139     [[SDLUIKitDelegate sharedAppDelegate] startSDLgame:gameDictionary];
       
   140     [gameDictionary release];
   143 }
   141 }
   144 
   142 
   145 -(void) viewDidLoad {
   143 -(void) viewDidLoad {
   146     CGRect screen = [[UIScreen mainScreen] bounds];
   144     CGRect screen = [[UIScreen mainScreen] bounds];
   147     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   145     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   163             if ([oneView isMemberOfClass:[UIToolbar class]]) {
   161             if ([oneView isMemberOfClass:[UIToolbar class]]) {
   164                 [[oneView viewWithTag:12345] setHidden:YES];
   162                 [[oneView viewWithTag:12345] setHidden:YES];
   165                 break;
   163                 break;
   166             }
   164             }
   167         }
   165         }
   168     } else
   166     } else {
       
   167         // this is the visible controller
   169         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   168         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
       
   169         // this must be loaded to auto set default scheme and ammo
       
   170         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   171     }
   170     activeController = mapConfigViewController;
   172     activeController = mapConfigViewController;
   171     
   173     
   172     [self.view addSubview:mapConfigViewController.view];
   174     [self.view addSubview:mapConfigViewController.view];
   173     
   175     
   174     [super viewDidLoad];
   176     [super viewDidLoad];