author | koda |
Thu, 29 Apr 2010 17:20:42 +0000 | |
changeset 3375 | 88bb88294e06 |
parent 3374 | 0d522416d97f |
child 3377 | a3f0849f26bc |
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); |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
28 |
self.tableView.backgroundColor = [UIColor redColor]; |
3361 | 29 |
} |
30 |
||
31 |
-(void) viewWillAppear:(BOOL)animated { |
|
32 |
[super viewWillAppear:animated]; |
|
33 |
||
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
34 |
// 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
|
35 |
NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 }; |
3361 | 36 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
3364 | 37 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
38 |
for (int i = 0; i < [contentsOfDir count]; i++) { |
|
39 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
|
40 |
[contentsOfDir objectAtIndex:i],@"team", |
|
41 |
[NSNumber numberWithInt:4],@"number", |
|
42 |
[NSNumber numberWithInt:colors[i%6]],@"color",nil]; |
|
43 |
[array addObject:dict]; |
|
44 |
[dict release]; |
|
45 |
} |
|
3361 | 46 |
self.listOfTeams = array; |
47 |
[array release]; |
|
48 |
||
3364 | 49 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
50 |
self.listOfSelectedTeams = emptyArray; |
|
51 |
[emptyArray release]; |
|
52 |
||
3361 | 53 |
[self.tableView reloadData]; |
54 |
} |
|
55 |
||
56 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
57 |
return rotationManager(interfaceOrientation); |
|
58 |
} |
|
59 |
||
60 |
||
61 |
#pragma mark - |
|
62 |
#pragma mark Table view data source |
|
63 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
3364 | 64 |
return 2; |
3361 | 65 |
} |
66 |
||
67 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
3364 | 68 |
if (section == 0) |
69 |
return [listOfSelectedTeams count] ; |
|
70 |
else |
|
71 |
return [listOfTeams count]; |
|
3361 | 72 |
} |
73 |
||
3364 | 74 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
75 |
if (section == 0) |
|
76 |
return NSLocalizedString(@"Playing Teams",@""); |
|
77 |
else |
|
78 |
return NSLocalizedString(@"Available Teams",@""); |
|
79 |
} |
|
3361 | 80 |
|
81 |
// 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
|
82 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
3364 | 83 |
static NSString *CellIdentifier0 = @"Cell0"; |
84 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
85 |
NSInteger section = [indexPath section]; |
|
86 |
UITableViewCell *cell; |
|
3361 | 87 |
|
3364 | 88 |
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
|
89 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
3364 | 90 |
if (cell == nil) { |
91 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
92 |
||
93 |
UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; |
|
94 |
numberButton.tag = NUMBERBUTTON_TAG; |
|
95 |
[cell addSubview:numberButton]; |
|
96 |
[numberButton release]; |
|
97 |
||
98 |
SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; |
|
99 |
squareButton.tag = SQUAREBUTTON_TAG; |
|
100 |
[cell addSubview:squareButton]; |
|
101 |
[squareButton release]; |
|
102 |
||
103 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; |
|
104 |
label.textAlignment = UITextAlignmentLeft; |
|
105 |
label.backgroundColor = [UIColor clearColor]; |
|
106 |
label.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2]; |
|
107 |
label.tag = LABEL_TAG; |
|
108 |
[cell.contentView addSubview:label]; |
|
109 |
[label release]; |
|
110 |
} |
|
3361 | 111 |
|
3364 | 112 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
113 |
||
114 |
UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG]; |
|
115 |
cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
|
116 |
||
117 |
HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG]; |
|
118 |
[numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]]; |
|
119 |
numberButton.ownerDictionary = selectedRow; |
|
3361 | 120 |
|
3364 | 121 |
SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG]; |
122 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
|
123 |
squareButton.ownerDictionary = selectedRow; |
|
124 |
} 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
|
125 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
3364 | 126 |
if (cell == nil) |
127 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
|
128 |
||
129 |
cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
|
3361 | 130 |
} |
3364 | 131 |
|
3361 | 132 |
return cell; |
133 |
} |
|
134 |
||
135 |
||
136 |
/* |
|
137 |
// Override to support conditional editing of the table view. |
|
138 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
139 |
// Return NO if you do not want the specified item to be editable. |
|
140 |
return YES; |
|
141 |
} |
|
142 |
*/ |
|
143 |
||
144 |
||
145 |
/* |
|
146 |
// Override to support editing the table view. |
|
147 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
148 |
||
149 |
if (editingStyle == UITableViewCellEditingStyleDelete) { |
|
150 |
// Delete the row from the data source |
|
151 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
152 |
} |
|
153 |
else if (editingStyle == UITableViewCellEditingStyleInsert) { |
|
154 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
155 |
} |
|
156 |
} |
|
157 |
*/ |
|
158 |
||
159 |
||
160 |
/* |
|
161 |
// Override to support rearranging the table view. |
|
162 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
163 |
} |
|
164 |
*/ |
|
165 |
||
166 |
/* |
|
167 |
// Override to support conditional rearranging of the table view. |
|
168 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
169 |
// Return NO if you do not want the item to be re-orderable. |
|
170 |
return YES; |
|
171 |
} |
|
172 |
*/ |
|
173 |
||
174 |
#pragma mark - |
|
175 |
#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
|
176 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3364 | 177 |
NSInteger row = [indexPath row]; |
178 |
NSInteger section = [indexPath section]; |
|
3361 | 179 |
|
3364 | 180 |
if (section == 0) { |
181 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
|
182 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
|
183 |
} else { |
|
184 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
|
185 |
[self.listOfTeams removeObjectAtIndex:row]; |
|
186 |
} |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
187 |
[aTableView reloadData]; |
3361 | 188 |
} |
189 |
||
190 |
||
191 |
#pragma mark - |
|
192 |
#pragma mark Memory management |
|
193 |
-(void) didReceiveMemoryWarning { |
|
194 |
// Releases the view if it doesn't have a superview. |
|
195 |
[super didReceiveMemoryWarning]; |
|
196 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
197 |
} |
|
198 |
||
199 |
-(void) viewDidUnload { |
|
200 |
self.listOfTeams = nil; |
|
201 |
} |
|
202 |
||
203 |
||
204 |
-(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
|
205 |
[self.listOfTeams release]; |
3361 | 206 |
[super dealloc]; |
207 |
} |
|
208 |
||
209 |
||
210 |
@end |
|
211 |