# HG changeset patch # User koda # Date 1317519909 -7200 # Node ID ce02ddfe8aa13f9519edbcf77afca894bc25003b # Parent c10767edcd5818a763eb7829199051649271482b on ipad2 and above animate the little hogs on game config and fix the hat display imaging diff -r c10767edcd58 -r ce02ddfe8aa1 project_files/HedgewarsMobile/Classes/GameConfigViewController.h --- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.h Sun Oct 02 01:35:20 2011 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.h Sun Oct 02 03:45:09 2011 +0200 @@ -47,5 +47,6 @@ -(IBAction) buttonPressed:(id) sender; -(IBAction) segmentPressed:(id) sender; -(void) startGame:(UIButton *)button; +-(BOOL) isEverythingSet; @end diff -r c10767edcd58 -r ce02ddfe8aa1 project_files/HedgewarsMobile/Classes/GameConfigViewController.m --- a/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Sun Oct 02 01:35:20 2011 +0200 +++ b/project_files/HedgewarsMobile/Classes/GameConfigViewController.m Sun Oct 02 03:45:09 2011 +0200 @@ -55,8 +55,17 @@ break; case 1: [AudioManagerController playClickSound]; + if ([self isEverythingSet] == NO) + return; theButton.enabled = NO; + for (UIView *oneView in self.imgContainer.subviews) { + if ([oneView isMemberOfClass:[UIImageView class]]) { + UIImageView *anImageView = (UIImageView *)oneView; + [anImageView removeFromSuperview]; + } + } [self startGame:theButton]; + break; case 2: [AudioManagerController playClickSound]; @@ -206,9 +215,6 @@ -(void) startGame:(UIButton *)button { button.enabled = YES; - - if ([self isEverythingSet] == NO) - return; NSString *script = self.mapConfigViewController.missionCommand; if ([script isEqualToString:@""]) @@ -238,35 +244,52 @@ -(void) loadNiceHogs { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSString *filePath = [NSString stringWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()]; - UIImage *sprite = [[UIImage alloc] initWithContentsOfFile:filePath andCutAt:CGRectMake(96, 0, 32, 32)]; - + srand(time(NULL)); + NSString *filePath = [[NSString alloc] initWithFormat:@"%@/Hedgehog/Idle.png",GRAPHICS_DIRECTORY()]; + UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:filePath]; + [filePath release]; + NSArray *hatArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:HATS_DIRECTORY() error:NULL]; int numberOfHats = [hatArray count]; + int animationFrames = IS_VERY_POWERFUL([HWUtils modelType]) ? 18 : 1; if (self.imgContainer != nil) [self.imgContainer removeFromSuperview]; - + self.imgContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 40)]; for (int i = 0; i < 1 + random()%20; i++) { NSString *hat = [hatArray objectAtIndex:random()%numberOfHats]; - + NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@", HATS_DIRECTORY(), hat]; - UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)]; - [hatFile release]; - UIImage *hogWithHat = [sprite mergeWith:hatSprite atPoint:CGPointMake(0, 5)]; + UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile:hatFile]; + NSMutableArray *animation = [[NSMutableArray alloc] initWithCapacity:animationFrames]; + for (int j = 0; j < animationFrames; j++) { + int x = ((j*32)/(int)hatSprite.size.height)*32; + int y = (j*32)%(int)hatSprite.size.height; + UIImage *hatSpriteFrame = [hatSprite cutAt:CGRectMake(x, y, 32, 32)]; + UIImage *hogSpriteFrame = [hogSprite cutAt:CGRectMake(x, y, 32, 32)]; + UIImage *hogWithHat = [hogSpriteFrame mergeWith:hatSpriteFrame atPoint:CGPointMake(0, 5)]; + [animation addObject:hogWithHat]; + } [hatSprite release]; - - UIImageView *hog = [[UIImageView alloc] initWithImage:hogWithHat]; - int x = 15*(i+1)+random()%40; - if (x + 32 > 300) - x = i*10; - hog.frame = CGRectMake(x, 30, 32, 32); + [hatFile release]; + + UIImageView *hog = [[UIImageView alloc] initWithImage:[animation objectAtIndex:0]]; + hog.animationImages = animation; + hog.animationDuration = 3; + [animation release]; + + int x = 20*i+random()%128; + if (x > 320 - 32) + x = i*random()%32; + hog.frame = CGRectMake(x, 25, hog.frame.size.width, hog.frame.size.height); [self.imgContainer addSubview:hog]; + [hog startAnimating]; [hog release]; } + [self.view addSubview:self.imgContainer]; - [sprite release]; + [hogSprite release]; [pool drain]; } @@ -291,7 +314,7 @@ [self.mapConfigViewController.view addSubview:theLabel]; releaseAndNil(theLabel); // right column - theLabel = [[UILabel alloc] initWithFrame:CGRectMake(704, 214, 320, 464) andTitle:nil withBorderWidth:2.7f]; + theLabel = [[UILabel alloc] initWithFrame:CGRectMake(704, 214, 320, 466) andTitle:nil withBorderWidth:2.7f]; [self.mapConfigViewController.view addSubview:theLabel]; releaseAndNil(theLabel); // top right column (map) diff -r c10767edcd58 -r ce02ddfe8aa1 project_files/HedgewarsMobile/Classes/UIImageExtra.m --- a/project_files/HedgewarsMobile/Classes/UIImageExtra.m Sun Oct 02 01:35:20 2011 +0200 +++ b/project_files/HedgewarsMobile/Classes/UIImageExtra.m Sun Oct 02 03:45:09 2011 +0200 @@ -51,15 +51,16 @@ CGFloat screenScale = [[UIScreen mainScreen] scale]; int w = self.size.width * screenScale; int h = self.size.height * screenScale; - + int yOffset = self.size.height - secondImage.size.height + secondImagePoint.y; + if (w == 0 || h == 0) { - DLog(@"Can have 0 dimesions"); + DLog(@"Cannot have 0 dimesions"); return self; } // Create a bitmap graphics context; this will also set it as the current context CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); - CGContextRef context = CGBitmapContextCreate(NULL, w, h, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst); + CGContextRef context = CGBitmapContextCreate(NULL, w, h+yOffset, 8, 4 * w, colorSpace, kCGImageAlphaPremultipliedFirst); // draw the two images in the current context CGContextDrawImage(context, CGRectMake(0, 0, self.size.width*screenScale, self.size.height*screenScale), [self CGImage]);