project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 6634 e00762923086
parent 6353 d8f62c805619
child 6636 4450e746dc34
equal deleted inserted replaced
6633:2dc43ce68721 6634:e00762923086
    24 #import "TeamConfigViewController.h"
    24 #import "TeamConfigViewController.h"
    25 #import "SchemeWeaponConfigViewController.h"
    25 #import "SchemeWeaponConfigViewController.h"
    26 #import "HelpPageViewController.h"
    26 #import "HelpPageViewController.h"
    27 #import "GameInterfaceBridge.h"
    27 #import "GameInterfaceBridge.h"
    28 
    28 
    29 
       
    30 @implementation GameConfigViewController
    29 @implementation GameConfigViewController
    31 @synthesize imgContainer, helpPage, mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController;
    30 @synthesize imgContainer, helpPage, titleImage, sliderBackground,
       
    31             mapConfigViewController, teamConfigViewController, schemeWeaponConfigViewController;
    32 
    32 
    33 
    33 
    34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    35     return rotationManager(interfaceOrientation);
    35     return rotationManager(interfaceOrientation);
    36 }
    36 }
   241 
   241 
   242     if (self.imgContainer != nil)
   242     if (self.imgContainer != nil)
   243         [self.imgContainer removeFromSuperview];
   243         [self.imgContainer removeFromSuperview];
   244 
   244 
   245     self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   245     self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   246     for (int i = 0; i < 1 + random()%20; i++) {
   246     NSInteger numberOfHogs = 1 + random() % 20;
       
   247     DLog(@"Drawing %d nice hedgehogs", numberOfHogs);
       
   248     for (int i = 0; i < numberOfHogs; i++) {
   247         NSString *hat = [hatArray objectAtIndex:random()%numberOfHats];
   249         NSString *hat = [hatArray objectAtIndex:random()%numberOfHats];
   248 
   250 
   249         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
   251         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
   250         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile];
   252         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile];
   251         NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames];
   253         NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames];
   280 }
   282 }
   281 
   283 
   282 -(void) viewDidLoad {
   284 -(void) viewDidLoad {
   283     self.view.backgroundColor = [UIColor blackColor];
   285     self.view.backgroundColor = [UIColor blackColor];
   284 
   286 
   285     CGRect screen = [[UIScreen mainScreen] bounds];
   287     CGRect screenRect = [[UIScreen mainScreen] safeBounds];
   286     self.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width);
   288     self.view.frame = screenRect;
   287 
   289 
   288     if (IS_IPAD()) {
   290     if (IS_IPAD()) {
   289         // the label for the filter slider
   291         // the label for the filter slider
   290         UILabel *filterLabel = [[UILabel alloc] initWithFrame:CGRectMake(116, 714, 310, 40)
   292         UILabel *backLabel = [[UILabel alloc] initWithFrame:CGRectMake(116, 714, 310, 40)
   291                                                      andTitle:nil
   293                                                    andTitle:nil
   292                                               withBorderWidth:2.0f];
   294                                             withBorderWidth:2.0f];
   293         [self.view insertSubview:filterLabel belowSubview:self.mapConfigViewController.slider];
   295         self.sliderBackground = backLabel;
   294         [filterLabel release];
   296         [backLabel release];
       
   297         [self.view addSubview:self.sliderBackground];
   295 
   298 
   296         // the label for max hogs
   299         // the label for max hogs
   297         UILabel *maxLabel = [[UILabel alloc] initWithFrame:CGRectMake(598, 714, 310, 40)
   300         UILabel *maxLabel = [[UILabel alloc] initWithFrame:CGRectMake(598, 714, 310, 40)
   298                                                   andTitle:NSLocalizedString(@"Loading...",@"")
   301                                                   andTitle:NSLocalizedString(@"Loading...",@"")
   299                                            withBorderWidth:2.0f];
   302                                            withBorderWidth:2.0f];
   301         maxLabel.textColor = [UIColor whiteColor];
   304         maxLabel.textColor = [UIColor whiteColor];
   302         maxLabel.textAlignment = UITextAlignmentCenter;
   305         maxLabel.textAlignment = UITextAlignmentCenter;
   303         [self.view addSubview:maxLabel];
   306         [self.view addSubview:maxLabel];
   304         self.mapConfigViewController.maxLabel = maxLabel;
   307         self.mapConfigViewController.maxLabel = maxLabel;
   305         [maxLabel release];
   308         [maxLabel release];
   306 
   309     } else {
   307         // as this is loaded from a NIB we need to set its size and position
   310         self.mapConfigViewController.view.frame = CGRectMake(0, 0, screenRect.size.height, screenRect.size.width-44);
       
   311     }
       
   312     [self.view addSubview:self.mapConfigViewController.view];
       
   313     [self.view bringSubviewToFront:self.mapConfigViewController.slider];
       
   314 
       
   315     [super viewDidLoad];
       
   316 }
       
   317 
       
   318 -(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval) duration {
       
   319     if (IS_IPAD() == NO)
       
   320         return;
       
   321 
       
   322     if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
       
   323          toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
       
   324         if (self.imgContainer == nil)
       
   325             [NSThread detachNewThreadSelector:@selector(loadNiceHogs) toTarget:self withObject:nil];
       
   326 
       
   327         self.imgContainer.alpha = 1;
       
   328         self.titleImage.frame = CGRectMake(357, 17, 309, 165);
       
   329         self.schemeWeaponConfigViewController.view.frame = CGRectMake(0, 60, 320, 620);
   308         self.mapConfigViewController.view.frame = CGRectMake(704, 0, 320, 680);
   330         self.mapConfigViewController.view.frame = CGRectMake(704, 0, 320, 680);
       
   331         self.teamConfigViewController.view.frame = CGRectMake(337, 187, 350, 505);
       
   332         self.mapConfigViewController.maxLabel.frame = CGRectMake(121, 714, 300, 40);
       
   333         self.sliderBackground.frame = CGRectMake(603, 714, 300, 40);
       
   334         self.mapConfigViewController.slider.frame = CGRectMake(653, 724, 200, 23);
   309     } else {
   335     } else {
   310         self.mapConfigViewController.view.frame = CGRectMake(0, 0, screen.size.height, screen.size.width-44);
   336         self.imgContainer.alpha = 0;
   311     }
   337         self.titleImage.frame = CGRectMake(37, 28, 309, 165);
   312     [self.view addSubview:self.mapConfigViewController.view];
   338         self.schemeWeaponConfigViewController.view.frame = CGRectMake(0, 214, 378, 366);
   313 
   339         self.mapConfigViewController.view.frame = CGRectMake(390, 0, 378, 580);
   314     [super viewDidLoad];
   340         self.teamConfigViewController.view.frame = CGRectMake(170, 590, 428, 366);
       
   341         self.mapConfigViewController.maxLabel.frame = CGRectMake(104, 975, 200, 40);
       
   342         self.sliderBackground.frame = CGRectMake(465, 975, 200, 40);
       
   343         self.mapConfigViewController.slider.frame = CGRectMake(475, 983, 180, 23);
       
   344     }
   315 }
   345 }
   316 
   346 
   317 -(void) viewWillAppear:(BOOL)animated {
   347 -(void) viewWillAppear:(BOOL)animated {
   318     if (IS_IPAD())
   348     // load hogs only on iPad and when interface allows enough space
       
   349     if (IS_IPAD() && (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
       
   350                       self.interfaceOrientation == UIInterfaceOrientationLandscapeRight))
   319         [NSThread detachNewThreadSelector:@selector(loadNiceHogs) toTarget:self withObject:nil];
   351         [NSThread detachNewThreadSelector:@selector(loadNiceHogs) toTarget:self withObject:nil];
   320 
   352 
   321     [self.mapConfigViewController viewWillAppear:animated];
   353     [self.mapConfigViewController viewWillAppear:animated];
   322     [self.teamConfigViewController viewWillAppear:animated];
   354     [self.teamConfigViewController viewWillAppear:animated];
   323     [self.schemeWeaponConfigViewController viewWillAppear:animated];
   355     [self.schemeWeaponConfigViewController viewWillAppear:animated];
   347     [super viewDidDisappear:animated];
   379     [super viewDidDisappear:animated];
   348 }
   380 }
   349 
   381 
   350 -(void) didReceiveMemoryWarning {
   382 -(void) didReceiveMemoryWarning {
   351     self.imgContainer = nil;
   383     self.imgContainer = nil;
       
   384 
       
   385     if (self.titleImage.superview == nil)
       
   386         self.titleImage = nil;
       
   387     if (self.sliderBackground.superview == nil)
       
   388         self.sliderBackground = nil;
   352 
   389 
   353     if (self.mapConfigViewController.view.superview == nil)
   390     if (self.mapConfigViewController.view.superview == nil)
   354         self.mapConfigViewController = nil;
   391         self.mapConfigViewController = nil;
   355     if (self.teamConfigViewController.view.superview == nil)
   392     if (self.teamConfigViewController.view.superview == nil)
   356         self.teamConfigViewController = nil;
   393         self.teamConfigViewController = nil;
   362     [super didReceiveMemoryWarning];
   399     [super didReceiveMemoryWarning];
   363 }
   400 }
   364 
   401 
   365 -(void) viewDidUnload {
   402 -(void) viewDidUnload {
   366     self.imgContainer = nil;
   403     self.imgContainer = nil;
       
   404     self.titleImage = nil;
       
   405     self.sliderBackground = nil;
   367     self.schemeWeaponConfigViewController = nil;
   406     self.schemeWeaponConfigViewController = nil;
   368     self.teamConfigViewController = nil;
   407     self.teamConfigViewController = nil;
   369     self.mapConfigViewController = nil;
   408     self.mapConfigViewController = nil;
   370     self.helpPage = nil;
   409     self.helpPage = nil;
   371     MSG_DIDUNLOAD();
   410     MSG_DIDUNLOAD();
   372     [super viewDidUnload];
   411     [super viewDidUnload];
   373 }
   412 }
   374 
   413 
   375 -(void) dealloc {
   414 -(void) dealloc {
   376     releaseAndNil(imgContainer);
   415     releaseAndNil(imgContainer);
       
   416     releaseAndNil(titleImage);
       
   417     releaseAndNil(sliderBackground);
   377     releaseAndNil(schemeWeaponConfigViewController);
   418     releaseAndNil(schemeWeaponConfigViewController);
   378     releaseAndNil(teamConfigViewController);
   419     releaseAndNil(teamConfigViewController);
   379     releaseAndNil(mapConfigViewController);
   420     releaseAndNil(mapConfigViewController);
   380     releaseAndNil(helpPage);
   421     releaseAndNil(helpPage);
   381     [super dealloc];
   422     [super dealloc];