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.m88
1 files changed, 88 insertions, 0 deletions
diff --git a/Classes/GameModeSelection.m b/Classes/GameModeSelection.m new file mode 100644 index 0000000..56e65d9 --- /dev/null +++ b/Classes/GameModeSelection.m
@@ -0,0 +1,88 @@
1//
2// GameModeSelection.m
3// Cartographic
4//
5// Created by Starla Insigna on 8/18/11.
6// Copyright 2011 Four Island. All rights reserved.
7//
8
9#import "GameModeSelection.h"
10
11@implementation GameModeSelection
12
13@synthesize name, location, unlocked, highscore, unlockCondition;
14
15- (id)initWithName:(NSString*)m_name location:(NSString*)m_location filename:(NSString*)filename unlocked:(BOOL)m_unlocked;
16{
17 self = [super init];
18
19 if (nil != self)
20 {
21 self.anchorPoint = CGPointMake(0.5f, 0.5f);
22
23 name = m_name;
24 location = m_location;
25 unlocked = m_unlocked;
26
27 if (!unlocked)
28 {
29 name = [@"" stringByPaddingToLength:name.length withString:@"?" startingAtIndex:0];
30 location = [@"" stringByPaddingToLength:location.length withString:@"?" startingAtIndex:0];
31 }
32
33 nameLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"%@ (%@)", location, name] fntFile:@"levelnames.fnt"];
34
35 [self addChild:nameLabel];
36 nameLabel.position = ccp(0, -32-nameLabel.contentSize.height);
37
38 UIImage* innerPicture = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:filename ofType:@"png"]];
39 UIGraphicsBeginImageContext(CGSizeMake(128, 128));
40 CGContextRef context = UIGraphicsGetCurrentContext();
41 UIGraphicsPushContext(context);
42
43 if (unlocked)
44 {
45 [innerPicture drawInRect:CGRectMake(0, 0, 128, 128)];
46 } else {
47 CGContextSetFillColorWithColor(context, [[UIColor whiteColor] CGColor]);
48 CGContextFillRect(context, CGRectMake(0, 0, 128, 128));
49 [innerPicture drawInRect:CGRectMake(0, 0, 128, 128) blendMode:kCGBlendModeLuminosity alpha:1.0];
50 }
51
52 UIGraphicsPopContext();
53 CGImageRef innerPictureRef = [UIGraphicsGetImageFromCurrentImageContext() CGImage];
54 UIGraphicsEndImageContext();
55
56 picture = [CCSprite spriteWithCGImage:innerPictureRef key:filename];
57 picture.position = ccp(0, 32);
58 [self addChild:picture];
59 }
60
61 return self;
62}
63
64- (void)setHighscore:(int)m_highscore
65{
66 if (unlocked)
67 {
68 highscore = m_highscore;
69
70 otherLabel = [CCLabelBMFont labelWithString:[NSString stringWithFormat:@"Highscore: %d", highscore] fntFile:@"leveldescriptions.fnt"];
71 otherLabel.position = ccp(0, -32-nameLabel.contentSize.height-otherLabel.contentSize.height);
72 [self addChild:otherLabel];
73 }
74}
75
76- (void)setUnlockCondition:(NSString *)m_unlockCondition
77{
78 if (!unlocked)
79 {
80 unlockCondition = m_unlockCondition;
81
82 otherLabel = [CCLabelBMFont labelWithString:unlockCondition fntFile:@"leveldescriptions.fnt"];
83 otherLabel.position = ccp(0, -32-nameLabel.contentSize.height-otherLabel.contentSize.height);
84 [self addChild:otherLabel];
85 }
86}
87
88@end