summary refs log tree commit diff stats
path: root/Classes/GameModeSelection.m
diff options
context:
space:
mode:
Diffstat (limited to 'Classes/GameModeSelection.m')
-rw-r--r--Classes/GameModeSelection.m90
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