18 * File created on 20/04/2010. |
18 * File created on 20/04/2010. |
19 */ |
19 */ |
20 |
20 |
21 |
21 |
22 #import "TeamConfigViewController.h" |
22 #import "TeamConfigViewController.h" |
23 #import "CommodityFunctions.h" |
|
24 #import "SquareButtonView.h" |
23 #import "SquareButtonView.h" |
|
24 |
25 |
25 |
26 @implementation TeamConfigViewController |
26 @implementation TeamConfigViewController |
27 @synthesize listOfTeams, listOfSelectedTeams, cachedContentsOfDir; |
27 @synthesize listOfTeams, listOfSelectedTeams, cachedContentsOfDir; |
28 |
28 |
29 #pragma mark - |
29 #pragma mark - |
45 [background release]; |
45 [background release]; |
46 } |
46 } |
47 } else |
47 } else |
48 self.view.backgroundColor = [UIColor blackColor]; |
48 self.view.backgroundColor = [UIColor blackColor]; |
49 |
49 |
50 self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
50 self.tableView.separatorColor = [UIColor darkYellowColor]; |
51 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
51 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
52 } |
52 } |
53 |
53 |
54 -(void) viewWillAppear:(BOOL)animated { |
54 -(void) viewWillAppear:(BOOL)animated { |
55 [super viewWillAppear:animated]; |
55 [super viewWillAppear:animated]; |
56 |
56 |
57 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
57 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
58 // avoid overwriting selected teams when returning on this view |
58 // avoid overwriting selected teams when returning on this view |
59 if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) { |
59 if ([self.cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) { |
60 NSArray *colors = getAvailableColors(); |
60 NSArray *colors = [HWUtils teamColors]; |
61 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
61 NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
62 for (int i = 0; i < [contentsOfDir count]; i++) { |
62 for (int i = 0; i < [contentsOfDir count]; i++) { |
63 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
63 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
64 [contentsOfDir objectAtIndex:i],@"team", |
64 [contentsOfDir objectAtIndex:i],@"team", |
65 [NSNumber numberWithInt:4],@"number", |
65 [NSNumber numberWithInt:4],@"number", |
103 |
103 |
104 -(UIImage *)drawHogsRepeated:(NSInteger) manyTimes { |
104 -(UIImage *)drawHogsRepeated:(NSInteger) manyTimes { |
105 NSString *imgString = [[NSString alloc] initWithFormat:@"%@/hedgehog.png",[[NSBundle mainBundle] resourcePath]]; |
105 NSString *imgString = [[NSString alloc] initWithFormat:@"%@/hedgehog.png",[[NSBundle mainBundle] resourcePath]]; |
106 UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:imgString]; |
106 UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:imgString]; |
107 [imgString release]; |
107 [imgString release]; |
108 CGFloat screenScale = getScreenScale(); |
108 CGFloat screenScale = [[UIScreen mainScreen] scale]; |
109 int w = hogSprite.size.width * screenScale; |
109 int w = hogSprite.size.width * screenScale; |
110 int h = hogSprite.size.height * screenScale; |
110 int h = hogSprite.size.height * screenScale; |
111 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
111 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); |
112 CGContextRef context = CGBitmapContextCreate(NULL, w * 3, h, 8, 4 * w * 3, colorSpace, kCGImageAlphaPremultipliedFirst); |
112 CGContextRef context = CGBitmapContextCreate(NULL, w * 3, h, 8, 4 * w * 3, colorSpace, kCGImageAlphaPremultipliedFirst); |
113 |
113 |
118 |
118 |
119 // Create bitmap image info from pixel data in current context |
119 // Create bitmap image info from pixel data in current context |
120 CGImageRef imageRef = CGBitmapContextCreateImage(context); |
120 CGImageRef imageRef = CGBitmapContextCreateImage(context); |
121 |
121 |
122 // Create a new UIImage object |
122 // Create a new UIImage object |
123 UIImage *resultImage; |
123 UIImage *resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp]; |
124 if ([self respondsToSelector:@selector(imageWithCGImage:scale:orientation:)]) |
|
125 resultImage = [UIImage imageWithCGImage:imageRef scale:screenScale orientation:UIImageOrientationUp]; |
|
126 else |
|
127 resultImage = [UIImage imageWithCGImage:imageRef]; |
|
128 |
124 |
129 // Release colorspace, context and bitmap information |
125 // Release colorspace, context and bitmap information |
130 CGColorSpaceRelease(colorSpace); |
126 CGColorSpaceRelease(colorSpace); |
131 CGContextRelease(context); |
127 CGContextRelease(context); |
132 CFRelease(imageRef); |
128 CFRelease(imageRef); |
197 [spriteView release]; |
193 [spriteView release]; |
198 } else |
194 } else |
199 cell.accessoryView = nil; |
195 cell.accessoryView = nil; |
200 } |
196 } |
201 |
197 |
202 cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
198 cell.textLabel.textColor = [UIColor lightYellowColor]; |
203 cell.backgroundColor = UICOLOR_HW_ALMOSTBLACK; |
199 cell.backgroundColor = [UIColor blackColorTransparent]; |
204 cell.selectionStyle = UITableViewCellSelectionStyleNone; |
200 cell.selectionStyle = UITableViewCellSelectionStyleNone; |
205 |
201 |
206 return cell; |
202 return cell; |
207 } |
203 } |
208 |
204 |
210 return 40.0; |
206 return 40.0; |
211 } |
207 } |
212 |
208 |
213 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
209 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
214 CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
210 CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
215 NSString *text; |
211 NSString *text = (section == 0) ? NSLocalizedString(@"Playing Teams",@"") : NSLocalizedString(@"Available Teams",@""); |
216 if (section == 0) |
212 UILabel *theLabel = [[UILabel alloc] initWithFrame:frame andTitle:text]; |
217 text = NSLocalizedString(@"Playing Teams",@""); |
|
218 else |
|
219 text = NSLocalizedString(@"Available Teams",@""); |
|
220 UILabel *theLabel = createBlueLabel(text, frame); |
|
221 theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
213 theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
222 |
214 |
223 UIView *theView = [[[UIView alloc] init] autorelease]; |
215 UIView *theView = [[[UIView alloc] init] autorelease]; |
224 [theView addSubview:theLabel]; |
216 [theView addSubview:theLabel]; |
225 [theLabel release]; |
217 [theLabel release]; |