10 #import "CommodityFunctions.h" |
10 #import "CommodityFunctions.h" |
11 #import "HogButtonView.h" |
11 #import "HogButtonView.h" |
12 #import "SquareButtonView.h" |
12 #import "SquareButtonView.h" |
13 |
13 |
14 @implementation TeamConfigViewController |
14 @implementation TeamConfigViewController |
15 @synthesize listOfTeams; |
15 @synthesize listOfTeams, listOfSelectedTeams; |
16 |
16 |
17 #define NUMBERBUTTON_TAG 123456 |
17 #define NUMBERBUTTON_TAG 123456 |
18 #define SQUAREBUTTON_TAG 654321 |
18 #define SQUAREBUTTON_TAG 654321 |
|
19 #define LABEL_TAG 456123 |
19 |
20 |
20 #pragma mark - |
21 #pragma mark - |
21 #pragma mark View lifecycle |
22 #pragma mark View lifecycle |
22 -(void) viewDidLoad { |
23 -(void) viewDidLoad { |
23 [super viewDidLoad]; |
24 [super viewDidLoad]; |
25 CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
26 CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
26 self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
27 self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
27 } |
28 } |
28 |
29 |
29 |
30 |
30 |
|
31 -(void) viewWillAppear:(BOOL)animated { |
31 -(void) viewWillAppear:(BOOL)animated { |
32 [super viewWillAppear:animated]; |
32 [super viewWillAppear:animated]; |
33 |
33 |
|
34 unsigned int colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 }; |
34 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
35 NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
35 NSMutableArray *array = [[NSMutableArray alloc] initWithArray:contentsOfDir copyItems:YES]; |
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 } |
36 self.listOfTeams = array; |
45 self.listOfTeams = array; |
37 [array release]; |
46 [array release]; |
38 |
47 |
|
48 NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
|
49 self.listOfSelectedTeams = emptyArray; |
|
50 [emptyArray release]; |
|
51 |
39 [self.tableView reloadData]; |
52 [self.tableView reloadData]; |
40 NSLog(@"%@",listOfTeams); |
53 NSLog(@"%@",listOfTeams); |
41 } |
54 } |
42 |
55 |
43 /* |
56 /* |
63 |
76 |
64 |
77 |
65 #pragma mark - |
78 #pragma mark - |
66 #pragma mark Table view data source |
79 #pragma mark Table view data source |
67 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
80 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
68 return 1; |
81 return 2; |
69 } |
82 } |
70 |
83 |
71 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
84 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
72 return [listOfTeams count]; |
85 if (section == 0) |
73 } |
86 return [listOfSelectedTeams count] ; |
74 |
87 else |
|
88 return [listOfTeams count]; |
|
89 } |
|
90 |
|
91 -(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
|
92 if (section == 0) |
|
93 return NSLocalizedString(@"Playing Teams",@""); |
|
94 else |
|
95 return NSLocalizedString(@"Available Teams",@""); |
|
96 } |
75 |
97 |
76 // Customize the appearance of table view cells. |
98 // Customize the appearance of table view cells. |
77 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
99 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
78 static NSString *CellIdentifier = @"Cell"; |
100 static NSString *CellIdentifier0 = @"Cell0"; |
79 |
101 static NSString *CellIdentifier1 = @"Cell1"; |
80 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
102 NSInteger section = [indexPath section]; |
81 if (cell == nil) { |
103 UITableViewCell *cell; |
82 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
104 |
83 |
105 if (section == 0) { |
84 UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; |
106 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
85 numberButton.tag = NUMBERBUTTON_TAG; |
107 if (cell == nil) { |
86 [cell addSubview:numberButton]; |
108 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
87 [numberButton release]; |
109 |
88 |
110 UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; |
89 SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; |
111 numberButton.tag = NUMBERBUTTON_TAG; |
90 squareButton.tag = SQUAREBUTTON_TAG; |
112 [cell addSubview:numberButton]; |
91 [cell addSubview:squareButton]; |
113 [numberButton release]; |
92 [squareButton release]; |
114 |
|
115 SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; |
|
116 squareButton.tag = SQUAREBUTTON_TAG; |
|
117 [cell addSubview:squareButton]; |
|
118 [squareButton release]; |
|
119 |
|
120 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; |
|
121 label.textAlignment = UITextAlignmentLeft; |
|
122 label.backgroundColor = [UIColor clearColor]; |
|
123 label.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; |
|
124 label.tag = LABEL_TAG; |
|
125 [cell.contentView addSubview:label]; |
|
126 [label release]; |
|
127 } |
|
128 |
|
129 NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
|
130 |
|
131 UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG]; |
|
132 cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
|
133 |
|
134 HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG]; |
|
135 [numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]]; |
|
136 numberButton.ownerDictionary = selectedRow; |
|
137 |
|
138 SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG]; |
|
139 [squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
|
140 squareButton.ownerDictionary = selectedRow; |
|
141 } else { |
|
142 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
|
143 if (cell == nil) |
|
144 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
|
145 |
|
146 cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
93 } |
147 } |
94 |
148 |
95 cell.textLabel.text = [[listOfTeams objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
|
96 |
|
97 return cell; |
149 return cell; |
98 } |
150 } |
99 |
151 |
100 |
152 |
101 /* |
153 /* |
126 // Override to support rearranging the table view. |
178 // Override to support rearranging the table view. |
127 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
179 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
128 } |
180 } |
129 */ |
181 */ |
130 |
182 |
131 |
|
132 /* |
183 /* |
133 // Override to support conditional rearranging of the table view. |
184 // Override to support conditional rearranging of the table view. |
134 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
185 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
135 // Return NO if you do not want the item to be re-orderable. |
186 // Return NO if you do not want the item to be re-orderable. |
136 return YES; |
187 return YES; |
137 } |
188 } |
138 */ |
189 */ |
139 |
190 |
140 |
|
141 #pragma mark - |
191 #pragma mark - |
142 #pragma mark Table view delegate |
192 #pragma mark Table view delegate |
143 |
193 -(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
144 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
194 NSInteger row = [indexPath row]; |
145 // Navigation logic may go here. Create and push another view controller. |
195 NSInteger section = [indexPath section]; |
146 /* |
196 |
147 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil]; |
197 if (section == 0) { |
148 // ... |
198 [self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
149 // Pass the selected object to the new view controller. |
199 [self.listOfSelectedTeams removeObjectAtIndex:row]; |
150 [self.navigationController pushViewController:detailViewController animated:YES]; |
200 } else { |
151 [detailViewController release]; |
201 [self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
152 */ |
202 [self.listOfTeams removeObjectAtIndex:row]; |
|
203 } |
|
204 [self.tableView reloadData]; |
153 } |
205 } |
154 |
206 |
155 |
207 |
156 #pragma mark - |
208 #pragma mark - |
157 #pragma mark Memory management |
209 #pragma mark Memory management |
158 |
|
159 -(void) didReceiveMemoryWarning { |
210 -(void) didReceiveMemoryWarning { |
160 // Releases the view if it doesn't have a superview. |
211 // Releases the view if it doesn't have a superview. |
161 [super didReceiveMemoryWarning]; |
212 [super didReceiveMemoryWarning]; |
162 // Relinquish ownership any cached data, images, etc that aren't in use. |
213 // Relinquish ownership any cached data, images, etc that aren't in use. |
163 } |
214 } |