author | koda |
Sun, 20 Jun 2010 18:35:59 +0200 | |
changeset 3523 | 6592fbb969da |
parent 3514 | 59dbd31e9953 |
child 3546 | ccf4854df294 |
permissions | -rw-r--r-- |
3361 | 1 |
// |
2 |
// TeamConfigViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 20/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "TeamConfigViewController.h" |
|
10 |
#import "CommodityFunctions.h" |
|
11 |
#import "HogButtonView.h" |
|
12 |
#import "SquareButtonView.h" |
|
13 |
||
14 |
@implementation TeamConfigViewController |
|
3364 | 15 |
@synthesize listOfTeams, listOfSelectedTeams; |
3361 | 16 |
|
17 |
#define NUMBERBUTTON_TAG 123456 |
|
18 |
#define SQUAREBUTTON_TAG 654321 |
|
3364 | 19 |
#define LABEL_TAG 456123 |
3361 | 20 |
|
21 |
#pragma mark - |
|
22 |
#pragma mark View lifecycle |
|
23 |
-(void) viewDidLoad { |
|
24 |
[super viewDidLoad]; |
|
25 |
||
26 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
|
27 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
28 |
} |
|
29 |
||
30 |
-(void) viewWillAppear:(BOOL)animated { |
|
31 |
[super viewWillAppear:animated]; |
|
32 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
33 |
// integer representation of various color (defined in SquareButtonView) |
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
34 |
NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 }; |
3361 | 35 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
3364 | 36 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
37 |
for (int i = 0; i < [contentsOfDir count]; i++) { |
|
38 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
|
39 |
[contentsOfDir objectAtIndex:i],@"team", |
|
40 |
[NSNumber numberWithInt:4],@"number", |
|
41 |
[NSNumber numberWithInt:colors[i%6]],@"color",nil]; |
|
42 |
[array addObject:dict]; |
|
43 |
[dict release]; |
|
44 |
} |
|
3361 | 45 |
self.listOfTeams = array; |
46 |
[array release]; |
|
47 |
||
3364 | 48 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
49 |
self.listOfSelectedTeams = emptyArray; |
|
50 |
[emptyArray release]; |
|
51 |
||
3361 | 52 |
[self.tableView reloadData]; |
53 |
} |
|
54 |
||
55 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
56 |
return rotationManager(interfaceOrientation); |
|
57 |
} |
|
58 |
||
59 |
||
60 |
#pragma mark - |
|
61 |
#pragma mark Table view data source |
|
62 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
3364 | 63 |
return 2; |
3361 | 64 |
} |
65 |
||
66 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
3364 | 67 |
if (section == 0) |
68 |
return [listOfSelectedTeams count] ; |
|
69 |
else |
|
70 |
return [listOfTeams count]; |
|
3361 | 71 |
} |
72 |
||
3364 | 73 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
74 |
if (section == 0) |
|
75 |
return NSLocalizedString(@"Playing Teams",@""); |
|
76 |
else |
|
77 |
return NSLocalizedString(@"Available Teams",@""); |
|
78 |
} |
|
3361 | 79 |
|
80 |
// Customize the appearance of table view cells. |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
81 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3364 | 82 |
static NSString *CellIdentifier0 = @"Cell0"; |
83 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
84 |
NSInteger section = [indexPath section]; |
|
85 |
UITableViewCell *cell; |
|
3361 | 86 |
|
3364 | 87 |
if (section == 0) { |
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
88 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
3364 | 89 |
if (cell == nil) { |
90 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
91 |
||
92 |
UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; |
|
93 |
numberButton.tag = NUMBERBUTTON_TAG; |
|
94 |
[cell addSubview:numberButton]; |
|
95 |
[numberButton release]; |
|
96 |
||
97 |
SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; |
|
98 |
squareButton.tag = SQUAREBUTTON_TAG; |
|
99 |
[cell addSubview:squareButton]; |
|
100 |
[squareButton release]; |
|
101 |
||
102 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; |
|
103 |
label.textAlignment = UITextAlignmentLeft; |
|
104 |
label.backgroundColor = [UIColor clearColor]; |
|
105 |
label.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; |
|
106 |
label.tag = LABEL_TAG; |
|
107 |
[cell.contentView addSubview:label]; |
|
108 |
[label release]; |
|
109 |
} |
|
3361 | 110 |
|
3364 | 111 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
112 |
||
113 |
UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG]; |
|
114 |
cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
|
115 |
||
116 |
HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG]; |
|
117 |
[numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]]; |
|
118 |
numberButton.ownerDictionary = selectedRow; |
|
3361 | 119 |
|
3364 | 120 |
SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG]; |
121 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
|
122 |
squareButton.ownerDictionary = selectedRow; |
|
123 |
} else { |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
124 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
3364 | 125 |
if (cell == nil) |
126 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
|
127 |
||
128 |
cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
|
3361 | 129 |
} |
3364 | 130 |
|
3361 | 131 |
return cell; |
132 |
} |
|
133 |
||
134 |
||
135 |
#pragma mark - |
|
136 |
#pragma mark Table view delegate |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
137 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3364 | 138 |
NSInteger row = [indexPath row]; |
139 |
NSInteger section = [indexPath section]; |
|
3361 | 140 |
|
3364 | 141 |
if (section == 0) { |
142 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
|
143 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
|
144 |
} else { |
|
145 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
|
146 |
[self.listOfTeams removeObjectAtIndex:row]; |
|
147 |
} |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
148 |
[aTableView reloadData]; |
3361 | 149 |
} |
150 |
||
151 |
||
152 |
#pragma mark - |
|
153 |
#pragma mark Memory management |
|
154 |
-(void) didReceiveMemoryWarning { |
|
155 |
// Releases the view if it doesn't have a superview. |
|
156 |
[super didReceiveMemoryWarning]; |
|
157 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
158 |
} |
|
159 |
||
160 |
-(void) viewDidUnload { |
|
161 |
self.listOfTeams = nil; |
|
3490 | 162 |
[super viewDidUnload]; |
163 |
MSG_DIDUNLOAD(); |
|
3361 | 164 |
} |
165 |
||
166 |
||
167 |
-(void) dealloc { |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
168 |
[self.listOfTeams release]; |
3361 | 169 |
[super dealloc]; |
170 |
} |
|
171 |
||
172 |
||
173 |
@end |
|
174 |