project_files/HedgewarsMobile/Classes/GameConfigViewController.m
changeset 6080 ce02ddfe8aa1
parent 6079 c10767edcd58
child 6108 7a8da11a6144
equal deleted inserted replaced
6079:c10767edcd58 6080:ce02ddfe8aa1
    53                 [[self parentViewController] dismissModalViewControllerAnimated:YES];
    53                 [[self parentViewController] dismissModalViewControllerAnimated:YES];
    54             }
    54             }
    55             break;
    55             break;
    56         case 1:
    56         case 1:
    57             [AudioManagerController playClickSound];
    57             [AudioManagerController playClickSound];
       
    58             if ([self isEverythingSet] == NO)
       
    59                 return;
    58             theButton.enabled = NO;
    60             theButton.enabled = NO;
       
    61             for (UIView *oneView in self.imgContainer.subviews) {
       
    62                 if ([oneView isMemberOfClass:[UIImageView class]]) {
       
    63                     UIImageView *anImageView = (UIImageView *)oneView;
       
    64                     [anImageView removeFromSuperview];
       
    65                 }
       
    66             }
    59             [self startGame:theButton];
    67             [self startGame:theButton];
       
    68             
    60             break;
    69             break;
    61         case 2:
    70         case 2:
    62             [AudioManagerController playClickSound];
    71             [AudioManagerController playClickSound];
    63             if (self.helpPage == nil)
    72             if (self.helpPage == nil)
    64                 self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageLobbyViewController-iPad" bundle:nil];
    73                 self.helpPage = [[HelpPageViewController alloc] initWithNibName:@"HelpPageLobbyViewController-iPad" bundle:nil];
   204     return YES;
   213     return YES;
   205 }
   214 }
   206 
   215 
   207 -(void) startGame:(UIButton *)button {
   216 -(void) startGame:(UIButton *)button {
   208     button.enabled = YES;
   217     button.enabled = YES;
   209     
       
   210     if ([self isEverythingSet] == NO)
       
   211         return;
       
   212 
   218 
   213     NSString *script = self.mapConfigViewController.missionCommand;
   219     NSString *script = self.mapConfigViewController.missionCommand;
   214     if ([script isEqualToString:@""])
   220     if ([script isEqualToString:@""])
   215         script = self.schemeWeaponConfigViewController.scriptCommand;
   221         script = self.schemeWeaponConfigViewController.scriptCommand;
   216 
   222 
   236     [self.interfaceBridge startLocalGame:gameDictionary];
   242     [self.interfaceBridge startLocalGame:gameDictionary];
   237 }
   243 }
   238 
   244 
   239 -(void) loadNiceHogs {
   245 -(void) loadNiceHogs {
   240     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   246     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   241     NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
   247     srand(time(NULL));
   242     UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)];
   248     NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()];
   243     
   249     UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath];
       
   250     [filePath release];
       
   251 
   244     NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
   252     NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL];
   245     int numberOfHats = [hatArray count];
   253     int numberOfHats = [hatArray count];
       
   254     int animationFrames = IS_VERY_POWERFUL([HWUtils modelType]) ? 18 : 1;
   246 
   255 
   247     if (self.imgContainer != nil)
   256     if (self.imgContainer != nil)
   248         [self.imgContainer removeFromSuperview];
   257         [self.imgContainer removeFromSuperview];
   249     
   258 
   250     self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   259     self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)];
   251     for (int i = 0; i < 1 + random()%20; i++) {
   260     for (int i = 0; i < 1 + random()%20; i++) {
   252         NSString *hat = [hatArray objectAtIndex:random()%numberOfHats];
   261         NSString *hat = [hatArray objectAtIndex:random()%numberOfHats];
   253         
   262 
   254         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
   263         NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat];
   255         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
   264         UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile];
       
   265         NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames];
       
   266         for (int j = 0; j < animationFrames; j++) {
       
   267             int x = ((j*32)/(int)hatSprite.size.height)*32;
       
   268             int y = (j*32)%(int)hatSprite.size.height;
       
   269             UIImage *hatSpriteFrame = [hatSprite cutAt:CGRectMake(x, y, 32, 32)];
       
   270             UIImage *hogSpriteFrame = [hogSprite cutAt:CGRectMake(x, y, 32, 32)];
       
   271             UIImage *hogWithHat = [hogSpriteFrame mergeWith:hatSpriteFrame atPoint:CGPointMake(0, 5)];
       
   272             [animation addObject:hogWithHat];
       
   273         }
       
   274         [hatSprite release];
   256         [hatFile release];
   275         [hatFile release];
   257         UIImage *hogWithHat = [sprite mergeWith:hatSprite atPoint:CGPointMake(0, 5)];
   276 
   258         [hatSprite release];
   277         UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]];
   259         
   278         hog.animationImages = animation;
   260         UIImageView *hog = [[UIImageView alloc] initWithImage:hogWithHat];
   279         hog.animationDuration = 3;
   261         int x = 15*(i+1)+random()%40;
   280         [animation release];
   262         if (x + 32 > 300)
   281 
   263             x = i*10;
   282         int x = 20*i+random()%128;
   264         hog.frame = CGRectMake(x, 30, 32, 32);
   283         if (x > 320 - 32)
       
   284             x = i*random()%32;
       
   285         hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height);
   265         [self.imgContainer addSubview:hog];
   286         [self.imgContainer addSubview:hog];
       
   287         [hog startAnimating];
   266         [hog release];
   288         [hog release];
   267     }
   289     }
       
   290 
   268     [self.view addSubview:self.imgContainer];
   291     [self.view addSubview:self.imgContainer];
   269     [sprite release];
   292     [hogSprite release];
   270     [pool drain];
   293     [pool drain];
   271 }
   294 }
   272 
   295 
   273 -(void) viewDidLoad {
   296 -(void) viewDidLoad {
   274     self.view.backgroundColor = [UIColor blackColor];
   297     self.view.backgroundColor = [UIColor blackColor];
   289         // center column
   312         // center column
   290         theLabel = [[UILabel alloc] initWithFrame:CGRectMake(337, 187, 350, 505) andTitle:nil withBorderWidth:2.7f];
   313         theLabel = [[UILabel alloc] initWithFrame:CGRectMake(337, 187, 350, 505) andTitle:nil withBorderWidth:2.7f];
   291         [self.mapConfigViewController.view addSubview:theLabel];
   314         [self.mapConfigViewController.view addSubview:theLabel];
   292         releaseAndNil(theLabel);
   315         releaseAndNil(theLabel);
   293         // right column
   316         // right column
   294         theLabel = [[UILabel alloc] initWithFrame:CGRectMake(704, 214, 320, 464) andTitle:nil withBorderWidth:2.7f];
   317         theLabel = [[UILabel alloc] initWithFrame:CGRectMake(704, 214, 320, 466) andTitle:nil withBorderWidth:2.7f];
   295         [self.mapConfigViewController.view addSubview:theLabel];
   318         [self.mapConfigViewController.view addSubview:theLabel];
   296         releaseAndNil(theLabel);
   319         releaseAndNil(theLabel);
   297         // top right column (map)
   320         // top right column (map)
   298         theLabel = [[UILabel alloc] initWithFrame:CGRectMake(714, 14, 300, 190) andTitle:nil withBorderWidth:2.3f];
   321         theLabel = [[UILabel alloc] initWithFrame:CGRectMake(714, 14, 300, 190) andTitle:nil withBorderWidth:2.3f];
   299         [self.mapConfigViewController.view addSubview:theLabel];
   322         [self.mapConfigViewController.view addSubview:theLabel];