author | nemo |
Wed, 19 May 2010 02:10:28 +0000 | |
changeset 3476 | 1ec68b8d3bd1 |
parent 3377 | a3f0849f26bc |
child 3487 | b1d00f1950c8 |
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 |
/* |
|
136 |
// Override to support conditional editing of the table view. |
|
137 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
138 |
// Return NO if you do not want the specified item to be editable. |
|
139 |
return YES; |
|
140 |
} |
|
141 |
*/ |
|
142 |
||
143 |
||
144 |
/* |
|
145 |
// Override to support editing the table view. |
|
146 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
147 |
||
148 |
if (editingStyle == UITableViewCellEditingStyleDelete) { |
|
149 |
// Delete the row from the data source |
|
150 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
151 |
} |
|
152 |
else if (editingStyle == UITableViewCellEditingStyleInsert) { |
|
153 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
154 |
} |
|
155 |
} |
|
156 |
*/ |
|
157 |
||
158 |
||
159 |
/* |
|
160 |
// Override to support rearranging the table view. |
|
161 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
162 |
} |
|
163 |
*/ |
|
164 |
||
165 |
/* |
|
166 |
// Override to support conditional rearranging of the table view. |
|
167 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
168 |
// Return NO if you do not want the item to be re-orderable. |
|
169 |
return YES; |
|
170 |
} |
|
171 |
*/ |
|
172 |
||
173 |
#pragma mark - |
|
174 |
#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
|
175 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
3364 | 176 |
NSInteger row = [indexPath row]; |
177 |
NSInteger section = [indexPath section]; |
|
3361 | 178 |
|
3364 | 179 |
if (section == 0) { |
180 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
|
181 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
|
182 |
} else { |
|
183 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
|
184 |
[self.listOfTeams removeObjectAtIndex:row]; |
|
185 |
} |
|
3374
0d522416d97f
lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents:
3365
diff
changeset
|
186 |
[aTableView reloadData]; |
3361 | 187 |
} |
188 |
||
189 |
||
190 |
#pragma mark - |
|
191 |
#pragma mark Memory management |
|
192 |
-(void) didReceiveMemoryWarning { |
|
193 |
// Releases the view if it doesn't have a superview. |
|
194 |
[super didReceiveMemoryWarning]; |
|
195 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
196 |
} |
|
197 |
||
198 |
-(void) viewDidUnload { |
|
199 |
self.listOfTeams = nil; |
|
200 |
} |
|
201 |
||
202 |
||
203 |
-(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
|
204 |
[self.listOfTeams release]; |
3361 | 205 |
[super dealloc]; |
206 |
} |
|
207 |
||
208 |
||
209 |
@end |
|
210 |