diff options
author | Starla Insigna <starla4444@gmail.com> | 2013-01-02 23:08:46 -0500 |
---|---|---|
committer | Starla Insigna <starla4444@gmail.com> | 2013-01-02 23:08:46 -0500 |
commit | 28497668761472e085d0c9955aa8077d11bf353c (patch) | |
tree | 48676176c8f2de27f4959d05f209f2f98da3979b /Classes/GameModeSelection.m | |
parent | 6e96fb2144718722208d22f892716b55548135e1 (diff) | |
download | cartcollect-28497668761472e085d0c9955aa8077d11bf353c.tar.gz cartcollect-28497668761472e085d0c9955aa8077d11bf353c.tar.bz2 cartcollect-28497668761472e085d0c9955aa8077d11bf353c.zip |
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.
Diffstat (limited to 'Classes/GameModeSelection.m')
-rw-r--r-- | Classes/GameModeSelection.m | 90 |
1 files changed, 32 insertions, 58 deletions
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 @@ | |||
26 | 26 | ||
27 | if (nil != self) | 27 | if (nil != self) |
28 | { | 28 | { |
29 | if (!m_gameMode.unlocked) | ||
30 | { | ||
31 | @throw [NSException exceptionWithName:NSInvalidArgumentException | ||
32 | reason:@"Game mode must be unlocked to appear on selection screen" | ||
33 | userInfo:nil]; | ||
34 | } | ||
35 | |||
29 | self.anchorPoint = CGPointMake(0.5f, 0.5f); | 36 | self.anchorPoint = CGPointMake(0.5f, 0.5f); |
30 | 37 | ||
31 | gameMode = m_gameMode; | 38 | gameMode = m_gameMode; |
@@ -34,16 +41,6 @@ | |||
34 | 41 | ||
35 | NSString* name = gameMode.name; | 42 | NSString* name = gameMode.name; |
36 | NSString* location = gameMode.location; | 43 | NSString* location = gameMode.location; |
37 | NSString* filenameMod; | ||
38 | |||
39 | if (gameMode.unlocked) | ||
40 | { | ||
41 | filenameMod = [NSString stringWithFormat:@"%@-unlocked", name]; | ||
42 | } else { | ||
43 | filenameMod = [NSString stringWithFormat:@"%@-locked", name]; | ||
44 | name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0]; | ||
45 | location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0]; | ||
46 | } | ||
47 | 44 | ||
48 | // First, create the frame that we will put the level picture inside | 45 | // First, create the frame that we will put the level picture inside |
49 | CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; | 46 | CGImageRef framestuff = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"framestuff" ofType:@"png"]] CGImage]; |
@@ -99,26 +96,13 @@ | |||
99 | context = UIGraphicsGetCurrentContext(); | 96 | context = UIGraphicsGetCurrentContext(); |
100 | CGContextSaveGState(context); | 97 | CGContextSaveGState(context); |
101 | 98 | ||
102 | if (gameMode.unlocked) | 99 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); |
103 | { | 100 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; |
104 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
105 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height)]; | ||
106 | } else { | ||
107 | // Draw the picture in grayscale if the level has not yet been unlocked | ||
108 | CGContextClipToMask(context, CGRectMake(10, 0, boxSize.width, boxSize.height), [selectionBackground CGImage]); | ||
109 | CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]); | ||
110 | CGContextFillRect(context, CGRectMake(10, 0, boxSize.width, boxSize.height)); | ||
111 | CGContextRestoreGState(context); | ||
112 | |||
113 | CGContextSaveGState(context); | ||
114 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | ||
115 | [selectionBackground drawInRect:CGRectMake(10, 0, boxSize.width, boxSize.height) blendMode:kCGBlendModeLuminosity alpha:1.0]; | ||
116 | } | ||
117 | 101 | ||
118 | CGContextRestoreGState(context); | 102 | CGContextRestoreGState(context); |
119 | CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | 103 | CGImageRef pictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; |
120 | 104 | ||
121 | CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", filenameMod]]; | 105 | CCSprite* picture = [CCSprite spriteWithCGImage:pictureRef key:[NSString stringWithFormat:@"gms-%@", name]]; |
122 | 106 | ||
123 | // We're also going to need a "selected" image state for the button | 107 | // We're also going to need a "selected" image state for the button |
124 | CGContextSaveGState(context); | 108 | CGContextSaveGState(context); |
@@ -128,7 +112,7 @@ | |||
128 | CGContextRestoreGState(context); | 112 | CGContextRestoreGState(context); |
129 | CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | 113 | CGImageRef selectedButtonRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; |
130 | UIGraphicsEndImageContext(); | 114 | UIGraphicsEndImageContext(); |
131 | CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", filenameMod]]; | 115 | CCSprite* selectedButton = [CCSprite spriteWithCGImage:selectedButtonRef key:[NSString stringWithFormat:@"gms-%@-selected", name]]; |
132 | 116 | ||
133 | CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; | 117 | CCMenuItemSprite* pictureMenuItem = [CCMenuItemSprite itemFromNormalSprite:picture selectedSprite:selectedButton target:self selector:@selector(buttonTapped)]; |
134 | NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; | 118 | NMPanelMenu* theMenu = [NMPanelMenu menuWithItems:pictureMenuItem, nil]; |
@@ -150,32 +134,29 @@ | |||
150 | 134 | ||
151 | CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | 135 | CGImageRef titleImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; |
152 | UIGraphicsEndImageContext(); | 136 | UIGraphicsEndImageContext(); |
153 | CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", filenameMod]]; | 137 | CCSprite* titleSprite = [CCSprite spriteWithCGImage:titleImage key:[NSString stringWithFormat:@"gms-%@-title", name]]; |
154 | titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); | 138 | titleSprite.position = ccp(-10, (boxSize.height)/2+(combinedTitleSize.height)/2); |
155 | [self addChild:titleSprite]; | 139 | [self addChild:titleSprite]; |
156 | 140 | ||
157 | if (gameMode.unlocked) | 141 | Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; |
142 | |||
143 | if (localHighscore != nil) | ||
158 | { | 144 | { |
159 | Highscore* localHighscore = [Highscore localHighscoreForGameMode:name]; | 145 | // Render the highscore label |
146 | NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; | ||
147 | UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; | ||
148 | CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; | ||
160 | 149 | ||
161 | if (localHighscore != nil) | 150 | UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); |
162 | { | 151 | CGContextRef context = UIGraphicsGetCurrentContext(); |
163 | // Render the highscore label | 152 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); |
164 | NSString* highscoreString = [NSString stringWithFormat:@"Highscore: %d", localHighscore.score]; | 153 | [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; |
165 | UIFont* highscoreFont = [UIFont fontWithName:@"AmericanTypewriter" size:16.0f]; | 154 | |
166 | CGSize highscoreSize = [highscoreString sizeWithFont:highscoreFont]; | 155 | CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; |
167 | 156 | UIGraphicsEndImageContext(); | |
168 | UIGraphicsBeginImageContext(CGSizeMake(highscoreSize.width+10, highscoreSize.height+10)); | 157 | CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; |
169 | CGContextRef context = UIGraphicsGetCurrentContext(); | 158 | highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); |
170 | CGContextSetShadow(context, CGSizeMake(-6, 6), 4.0f); | 159 | [self addChild:highscoreSprite]; |
171 | [highscoreString drawInRect:CGRectMake(10, 0, highscoreSize.width, highscoreSize.height) withFont:highscoreFont]; | ||
172 | |||
173 | CGImageRef highscoreImage = [UIGraphicsGetImageFromCurrentImageContext() CGImage]; | ||
174 | UIGraphicsEndImageContext(); | ||
175 | CCSprite* highscoreSprite = [CCSprite spriteWithCGImage:highscoreImage key:[NSString stringWithFormat:@"gms-%@-highscore-%d", name, localHighscore.score]]; | ||
176 | highscoreSprite.position = ccp(-5, 0-64-(highscoreSize.height)/2-10); | ||
177 | [self addChild:highscoreSprite]; | ||
178 | } | ||
179 | } | 160 | } |
180 | } | 161 | } |
181 | 162 | ||
@@ -184,18 +165,11 @@ | |||
184 | 165 | ||
185 | - (void)buttonTapped | 166 | - (void)buttonTapped |
186 | { | 167 | { |
187 | if (gameMode.unlocked) | 168 | if (delegate != nil) |
188 | { | 169 | { |
189 | if (delegate != nil) | 170 | [delegate didSelectGameMode:self]; |
190 | { | ||
191 | [delegate didSelectGameMode:self]; | ||
192 | } else { | ||
193 | NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); | ||
194 | } | ||
195 | } else { | 171 | } else { |
196 | UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"To unlock this game mode:" message:gameMode.unlockCondition delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; | 172 | NSLog(@"I don't have a GameModeSelectionDelegate to call for some reason..."); |
197 | [alertView show]; | ||
198 | [alertView release]; | ||
199 | } | 173 | } |
200 | } | 174 | } |
201 | 175 | ||