project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 3923 694e6f6e0e30
parent 3911 46d7a5cf8ac6
child 3926 668b71f31e51
equal deleted inserted replaced
3922:44804043b691 3923:694e6f6e0e30
    79     switch (theSegment.selectedSegmentIndex) {
    79     switch (theSegment.selectedSegmentIndex) {
    80         case 0:
    80         case 0:
    81             // this init here is just aestetic as this controller was already set up in viewDidLoad
    81             // this init here is just aestetic as this controller was already set up in viewDidLoad
    82             if (mapConfigViewController == nil) {
    82             if (mapConfigViewController == nil) {
    83                 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
    83                 mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
       
    84                 [self.view addSubview:mapConfigViewController.view];
    84             }
    85             }
    85             activeController = mapConfigViewController;
    86             // this message is compulsory otherwise the table won't be loaded at all
       
    87             [mapConfigViewController viewWillAppear:NO];
       
    88             [self.view bringSubviewToFront:mapConfigViewController.view];
    86             break;
    89             break;
    87         case 1:
    90         case 1:
    88             if (teamConfigViewController == nil) {
    91             if (teamConfigViewController == nil) {
    89                 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    92                 teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
    90                 // this message is compulsory otherwise the table won't be loaded at all
    93                 [self.view addSubview:teamConfigViewController.view];
    91             }
    94             }
    92             activeController = teamConfigViewController;
    95             // this message is compulsory otherwise the table won't be loaded at all
       
    96             [teamConfigViewController viewWillAppear:NO];
       
    97             [self.view bringSubviewToFront:teamConfigViewController.view];
    93             break;
    98             break;
    94         case 2:
    99         case 2:
    95             if (schemeWeaponConfigViewController == nil) {
   100             if (schemeWeaponConfigViewController == nil) {
    96                 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   101                 schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
       
   102                 [self.view addSubview:schemeWeaponConfigViewController.view];
    97             }
   103             }
    98             activeController = schemeWeaponConfigViewController;
   104             // this message is compulsory otherwise the table won't be loaded at all
    99             break;
   105             [schemeWeaponConfigViewController viewWillAppear:NO];
   100     }
   106             [self.view bringSubviewToFront:schemeWeaponConfigViewController.view];
   101 
   107             break;
   102     // this message is compulsory otherwise the table won't be loaded at all
   108         default:
   103     [activeController viewWillAppear:NO];
   109             DLog(@"Nope");
   104     [self.view addSubview:activeController.view];
   110             break;
       
   111     }
   105 }
   112 }
   106 
   113 
   107 -(BOOL) isEverythingSet {
   114 -(BOOL) isEverythingSet {
   108     // don't start playing if the preview is in progress
   115     // don't start playing if the preview is in progress
   109     if ([mapConfigViewController busy]) {
   116     if ([mapConfigViewController busy]) {
   232 
   239 
   233     CGRect screen = [[UIScreen mainScreen] bounds];
   240     CGRect screen = [[UIScreen mainScreen] bounds];
   234     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   241     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   235 
   242 
   236     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   243     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   237         // load a base image that will be updated in viewWill Load
       
   238         NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
       
   239         UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)];
       
   240         self.hedgehogImage = sprite;
       
   241         [sprite release];
       
   242         srandom(time(NULL));
   244         srandom(time(NULL));
       
   245         self.hedgehogImage = nil;
   243         
   246         
   244         // load other controllers
   247         // load other controllers
   245         if (mapConfigViewController == nil)
   248         if (mapConfigViewController == nil)
   246             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
   249             mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPad" bundle:nil];
   247         mapConfigViewController.delegate = self;
   250         mapConfigViewController.delegate = self;
       
   251         mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   248         if (teamConfigViewController == nil)
   252         if (teamConfigViewController == nil)
   249             teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   253             teamConfigViewController = [[TeamConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   250         teamConfigViewController.view.frame = CGRectMake(362, 200, 300, 480);
   254         teamConfigViewController.view.frame = CGRectMake(362, 200, 328, 480);
   251         teamConfigViewController.view.backgroundColor = [UIColor clearColor];
       
   252         [mapConfigViewController.view addSubview:teamConfigViewController.view];
   255         [mapConfigViewController.view addSubview:teamConfigViewController.view];
   253         if (schemeWeaponConfigViewController == nil)
   256         if (schemeWeaponConfigViewController == nil)
   254             schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   257             schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   255         schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 550);
   258         schemeWeaponConfigViewController.view.frame = CGRectMake(10, 70, 300, 550);
   256         [mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
   259         [mapConfigViewController.view addSubview:schemeWeaponConfigViewController.view];
   257         mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
       
   258     } else {
   260     } else {
   259         // this is the visible controller
   261         // this is the visible controller
   260         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   262         mapConfigViewController = [[MapConfigViewController alloc] initWithNibName:@"MapConfigViewController-iPhone" bundle:nil];
   261         // this must be loaded & added to auto set default scheme and ammo
   263         // this must be loaded & added to auto set default scheme and ammo
   262         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   264         schemeWeaponConfigViewController = [[SchemeWeaponConfigViewController alloc] initWithStyle:UITableViewStyleGrouped];
   263         [self.view addSubview:schemeWeaponConfigViewController.view];
   265         [self.view addSubview:schemeWeaponConfigViewController.view];
   264     }
   266     }
   265     activeController = mapConfigViewController;
       
   266 
       
   267     [self.view addSubview:mapConfigViewController.view];
   267     [self.view addSubview:mapConfigViewController.view];
   268 
   268 
   269     [super viewDidLoad];
   269     [super viewDidLoad];
   270 }
   270 }
   271 
   271 
   272 -(void) viewWillAppear:(BOOL)animated {
   272 -(void) viewWillAppear:(BOOL)animated {
   273     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
   273     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
       
   274         // load a base image that will be updated in viewWill Load
       
   275         if (self.hedgehogImage == nil) {
       
   276             NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
       
   277             UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)];
       
   278             self.hedgehogImage = sprite;
       
   279             [sprite release];
       
   280         }
       
   281         
   274         NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
   282         NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
   275         int numberOfHats = [hatArray count];
   283         int numberOfHats = [hatArray count];
   276         if (self.imgContainer == nil)
   284         if (self.imgContainer == nil)
   277             self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   285             self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   278         
   286         
   327     [super viewDidDisappear:animated];
   335     [super viewDidDisappear:animated];
   328 }
   336 }
   329 
   337 
   330 -(void) didReceiveMemoryWarning {
   338 -(void) didReceiveMemoryWarning {
   331     // Releases the view if it doesn't have a superview.
   339     // Releases the view if it doesn't have a superview.
   332     if (activeController.view.superview == nil)
       
   333         activeController = nil;
       
   334     if (mapConfigViewController.view.superview == nil)
   340     if (mapConfigViewController.view.superview == nil)
   335         mapConfigViewController = nil;
   341         mapConfigViewController = nil;
   336     if (teamConfigViewController.view.superview == nil)
   342     if (teamConfigViewController.view.superview == nil)
   337         teamConfigViewController = nil;
   343         teamConfigViewController = nil;
   338     if (schemeWeaponConfigViewController.view.superview == nil)
   344     if (schemeWeaponConfigViewController.view.superview == nil)
   339         schemeWeaponConfigViewController = nil;    
   345         schemeWeaponConfigViewController = nil;
       
   346 
   340     // Release any cached data, images, etc that aren't in use.
   347     // Release any cached data, images, etc that aren't in use.
   341 
       
   342     self.imgContainer = nil;
   348     self.imgContainer = nil;
       
   349     self.hedgehogImage = nil;
       
   350     MSG_MEMCLEAN();
   343     [super didReceiveMemoryWarning];
   351     [super didReceiveMemoryWarning];
   344     MSG_MEMCLEAN();
       
   345 }
   352 }
   346 
   353 
   347 -(void) viewDidUnload {
   354 -(void) viewDidUnload {
   348     hedgehogImage = nil;
   355     self.hedgehogImage = nil;
   349     imgContainer = nil;
   356     self.imgContainer = nil;
   350     activeController = nil;
       
   351     mapConfigViewController = nil;
   357     mapConfigViewController = nil;
   352     teamConfigViewController = nil;
   358     teamConfigViewController = nil;
   353     schemeWeaponConfigViewController = nil;
   359     schemeWeaponConfigViewController = nil;
   354     MSG_DIDUNLOAD();
   360     MSG_DIDUNLOAD();
   355     [super viewDidUnload];
   361     [super viewDidUnload];