From 28497668761472e085d0c9955aa8077d11bf353c Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 2 Jan 2013 23:08:46 -0500 Subject: Removed locked game modes from selection screen Also removed cluttering attributes "unlockCondition" and "starsToUnlock" from GameModeInfo because they're really not that generalized (and unlockCondition doesn't really make sense if locked game modes are invisible anyway). starsToUnlock can be replaced by simply putting if statements in to GameModeManager's setStars: and then unlocking modes based off that. Completing the tutorial also now unlocks both Collect AND Jump. The idea is that we should make more than just Collect available at the start, and have only a few super hidden game modes that are unlockable; hence locked game modes being invisible. --- Classes/GameModeSelection.m | 90 ++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 58 deletions(-) (limited to 'Classes/GameModeSelection.m') diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m index 61004fa..ea5f45b 100644 --- a/Classes/GameModeSelection.m +++ b/Classes/GameModeSelection.m @@ -26,6 +26,13 @@ if (nil != self) { + if (!m_gameMode.unlocked) + { + @throw [NSException exceptionWithName:NSInvalidArgumentException + reason:@"Game mode must be unlocked to appear on selection screen" + userInfo:nil]; + } + self.anchorPoint = CGPointMake(0.5f, 0.5f); gameMode = m_gameMode; @@ -34,16 +41,6 @@ NSString* name = gameMode.name; NSString* location = gameMode.location; - NSString* filenameMod; - - if (gameMode.unlocked) - { - filenameMod = [NSString stringWithFormat:@"%@-unlocked", name]; - } else { - filenameMod = [NSString stringWithFormat:@"%@-locked", name]; - name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; - location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; - } // First, create the frame that we will put the level picture inside CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; @@ -99,26 +96,13 @@ context = UIGraphicsGetCurrentContext(); CGContextSaveGState(context); - if (gameMode.unlocked) - { - CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); - [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; - } else { - // Draw the picture in grayscale if the level has not yet been unlocked - CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); - CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); - CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); - CGContextRestoreGState(context); - - CGContextSaveGState(context); - CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); - [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height) blendMode:kCGBlendModeLuminosity alpha:1.0]; - } + CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); + [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; CGContextRestoreGState(context); CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; - CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", filenameMod]]; + CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", name]]; // We're also going to need a "selected" image state for the button CGContextSaveGState(context); @@ -128,7 +112,7 @@ CGContextRestoreGState(context); CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; UIGraphicsEndImageContext(); - CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; + CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", name]]; CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; @@ -150,32 +134,29 @@ CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; UIGraphicsEndImageContext(); - CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; + CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", name]]; titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); [self addChild:titleSprite]; - if (gameMode.unlocked) + Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; + + if (localHighscore != nil) { - Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; + // Render the highscore label + NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; + UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; + CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; - if (localHighscore != nil) - { - // Render the highscore label - NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; - UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; - CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; - - UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); - CGContextRef context = UIGraphicsGetCurrentContext(); - CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); - [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; - - CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; - UIGraphicsEndImageContext(); - CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; - highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); - [self addChild:highscoreSprite]; - } + UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); + CGContextRef context = UIGraphicsGetCurrentContext(); + CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); + [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; + + CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; + UIGraphicsEndImageContext(); + CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; + highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); + [self addChild:highscoreSprite]; } } @@ -184,18 +165,11 @@ - (void)buttonTapped { - if (gameMode.unlocked) + if (delegate != nil) { - if (delegate != nil) - { - [delegate didSelectGameMode:self]; - } else { - NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); - } + [delegate didSelectGameMode:self]; } else { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:gameMode.unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; - [alertView show]; - [alertView release]; + NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); } } -- cgit 1.4.1