From d8f00310e486aed1ab289a0f816acec571193c32 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Wed, 24 Aug 2011 11:53:40 -0400 Subject: Added support for multiple local highscore lists This revision increments the database version to 2. Also fixed a small problem with GameModeSelection that aligned the highscore text incorrectly. --- Classes/GameModeSelection.m | 53 +++++++++++++++++++-------------------------- 1 file changed, 22 insertions(+), 31 deletions(-) (limited to 'Classes/GameModeSelection.m') diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m index 582c9dd..69f1ddb 100644 --- a/Classes/GameModeSelection.m +++ b/Classes/GameModeSelection.m @@ -9,6 +9,7 @@ #import "GameModeSelection.h" #import "UIImage+ColorMasking.h" #import "NMPanelMenu.h" +#import "Highscore.h" @implementation GameModeSelection @@ -19,11 +20,6 @@ return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlocked:unlocked] autorelease]; } -+ (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename highscore:(int)highscore -{ - return [[[GameModeSelection alloc] initWithName:name location:location filename:filename highscore:highscore] autorelease]; -} - + (id)selectionWithName:(NSString *)name location:(NSString *)location filename:(NSString *)filename unlockCondition:(NSString*)unlockCondition { return [[[GameModeSelection alloc] initWithName:name location:location filename:filename unlockCondition:unlockCondition] autorelease]; @@ -162,34 +158,29 @@ CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); [self addChild:titleSprite]; - } - - return self; -} - -- (id)initWithName:(NSString *)m_name location:(NSString *)m_location filename:(NSString *)m_filename highscore:(int)m_highscore -{ - self = [self initWithName:m_name location:m_location filename:m_filename unlocked:YES]; - - if (nil != self) - { - if (m_highscore != 0) + + if (unlocked) { - // Render the highscore label - NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", m_highscore]; - 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]; + Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; - CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; - UIGraphicsEndImageContext(); - CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore", m_filename]]; - highscoreSprite.position = ccp((128-highscoreSize.width)/2, 0-64-(highscoreSize.height)/2-10); - [self addChild:highscoreSprite]; + 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", filename]]; + highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); + [self addChild:highscoreSprite]; + } } } -- cgit 1.4.1