project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 3930 8b00b4f93242
parent 3926 668b71f31e51
child 3948 24daa33a3114
equal deleted inserted replaced
3928:2560731c860d 3930:8b00b4f93242
    19  */
    19  */
    20 
    20 
    21 
    21 
    22 #import "GameConfigViewController.h"
    22 #import "GameConfigViewController.h"
    23 #import "SDL_uikitappdelegate.h"
    23 #import "SDL_uikitappdelegate.h"
       
    24 #import "MapConfigViewController.h"
    24 #import "TeamConfigViewController.h"
    25 #import "TeamConfigViewController.h"
    25 #import "SchemeWeaponConfigViewController.h"
    26 #import "SchemeWeaponConfigViewController.h"
    26 #import "HelpPageViewController.h"
    27 #import "HelpPageViewController.h"
    27 #import "CommodityFunctions.h"
    28 #import "CommodityFunctions.h"
    28 #import "UIImageExtra.h"
    29 #import "UIImageExtra.h"
    29 #import "PascalImports.h"
    30 #import "PascalImports.h"
    30 
    31 
    31 @implementation GameConfigViewController
    32 @implementation GameConfigViewController
    32 @synthesize hedgehogImage, imgContainer, helpPage;
    33 @synthesize hedgehogImage, imgContainer, helpPage, mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController;
       
    34 
    33 
    35 
    34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    36 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    35     return rotationManager(interfaceOrientation);
    37     return rotationManager(interfaceOrientation);
    36 }
    38 }
    37 
    39 
    38 -(IBAction) buttonPressed:(id) sender {    
    40 -(IBAction) buttonPressed:(id) sender {
    39     // works even if it's not actually a button
    41     // works even if it's not actually a button
    40     UIButton *theButton = (UIButton *)sender;
    42     UIButton *theButton;
       
    43     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
       
    44         theButton = [[(NSNotification *)sender userInfo] objectForKey:@"sender"];
       
    45     else
       
    46         theButton = (UIButton *)sender;
       
    47 
    41     switch (theButton.tag) {
    48     switch (theButton.tag) {
    42         case 0:
    49         case 0:
    43             playSound(@"backSound");
    50             playSound(@"backSound");
    44             if ([mapConfigViewController busy]) {
    51             if ([mapConfigViewController busy]) {
    45                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
    52                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Wait for the Preview",@"")
   178     return YES;
   185     return YES;
   179 }
   186 }
   180 
   187 
   181 -(void) startGame:(UIButton *)button {
   188 -(void) startGame:(UIButton *)button {
   182     button.enabled = YES;
   189     button.enabled = YES;
   183 
   190     
   184     if ([self isEverythingSet] == NO)
   191     if ([self isEverythingSet] == NO)
   185         return;
   192         return;
   186 
   193 
   187     // 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
   188     NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   195     NSDictionary *gameDictionary = [NSDictionary dictionaryWithObjectsAndKeys:mapConfigViewController.seedCommand,@"seed_command",
   240 
   247 
   241     CGRect screen = [[UIScreen mainScreen] bounds];
   248     CGRect screen = [[UIScreen mainScreen] bounds];
   242     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   249     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   243 
   250 
   244     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   251     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
       
   252         [[NSNotificationCenter defaultCenter] addObserver:self
       
   253                                                  selector:@selector(buttonPressed:)
       
   254                                                      name:@"buttonPressed"
       
   255                                                    object:nil];
   245         srandom(time(NULL));
   256         srandom(time(NULL));
   246         self.hedgehogImage = nil;
   257         self.hedgehogImage = nil;
   247         
   258         
   248         // load other controllers
   259         // load other controllers
   249         if (mapConfigViewController == nil)
   260         if (self.mapConfigViewController == nil)
   250             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
   261             self.mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
   251         mapConfigViewController.delegate = self;
   262         if (self.teamConfigViewController == nil)
   252         mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   263             self.teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   253         if (teamConfigViewController == nil)
   264         [self.mapConfigViewController.view addSubview:self.teamConfigViewController.view];
   254             teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   265         if (self.schemeWeaponConfigViewController == nil)
   255         teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480);
   266             self.schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   256         [mapConfigViewController.view addSubview:teamConfigViewController.view];
   267         [self.mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
   257         if (schemeWeaponConfigViewController == nil)
   268         self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   258             schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   269         self.teamConfigViewController.view.frame = CGRectMake(348, 200, 328, 480);
   259         schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600);
   270         self.schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 600);
   260         [mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
   271         
   261     } else {
   272     } else {
   262         // this is the visible controller
   273         // this is the visible controller
   263         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   274         if (mapConfigViewController == nil)
       
   275             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   264         // this must be loaded & added to auto set default scheme and ammo
   276         // this must be loaded & added to auto set default scheme and ammo
   265         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   277         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   266         [self.view addSubview:schemeWeaponConfigViewController.view];
   278         [self.view addSubview:schemeWeaponConfigViewController.view];
   267     }
   279     }
   268     [self.view addSubview:mapConfigViewController.view];
   280     [self.view addSubview:mapConfigViewController.view];
   342         mapConfigViewController = nil;
   354         mapConfigViewController = nil;
   343     if (teamConfigViewController.view.superview == nil)
   355     if (teamConfigViewController.view.superview == nil)
   344         teamConfigViewController = nil;
   356         teamConfigViewController = nil;
   345     if (schemeWeaponConfigViewController.view.superview == nil)
   357     if (schemeWeaponConfigViewController.view.superview == nil)
   346         schemeWeaponConfigViewController = nil;
   358         schemeWeaponConfigViewController = nil;
       
   359     if (helpPage.view.superview == nil)
       
   360         helpPage = nil;
   347 
   361 
   348     // Release any cached data, images, etc that aren't in use.
   362     // Release any cached data, images, etc that aren't in use.
   349     self.imgContainer = nil;
   363     self.imgContainer = nil;
   350     self.hedgehogImage = nil;
   364     self.hedgehogImage = nil;
   351     MSG_MEMCLEAN();
   365     MSG_MEMCLEAN();
   352     [super didReceiveMemoryWarning];
   366     [super didReceiveMemoryWarning];
   353 }
   367 }
   354 
   368 
   355 -(void) viewDidUnload {
   369 -(void) viewDidUnload {
       
   370     [[NSNotificationCenter defaultCenter] removeObserver:self forKeyPath:@"buttonPressed"];
   356     self.hedgehogImage = nil;
   371     self.hedgehogImage = nil;
   357     self.imgContainer = nil;
   372     self.imgContainer = nil;
   358     mapConfigViewController = nil;
   373     self.mapConfigViewController = nil;
   359     teamConfigViewController = nil;
   374     self.teamConfigViewController = nil;
   360     schemeWeaponConfigViewController = nil;
   375     self.schemeWeaponConfigViewController = nil;
       
   376     self.helpPage = nil;
   361     MSG_DIDUNLOAD();
   377     MSG_DIDUNLOAD();
   362     [super viewDidUnload];
   378     [super viewDidUnload];
   363 }
   379 }
   364 
   380 
   365 -(void) dealloc {
   381 -(void) dealloc {
   366     [hedgehogImage release];
   382     [hedgehogImage release];
   367     [imgContainer release];
   383     [imgContainer release];
   368     [mapConfigViewController release];
   384     [mapConfigViewController release];
   369     [teamConfigViewController release];
   385     [teamConfigViewController release];
   370     [schemeWeaponConfigViewController release];
   386     [schemeWeaponConfigViewController release];
       
   387     [helpPage release];
   371     [super dealloc];
   388     [super dealloc];
   372 }
   389 }
   373 
   390 
   374 @end
   391 @end