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 |
|
|
31 |
-(void) viewWillAppear:(BOOL)animated {
|
|
32 |
[super viewWillAppear:animated];
|
|
33 |
|
3364
|
34 |
unsigned int 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 |
NSLog(@"%@",listOfTeams);
|
|
54 |
}
|
|
55 |
|
|
56 |
/*
|
|
57 |
- (void)viewDidAppear:(BOOL)animated {
|
|
58 |
[super viewDidAppear:animated];
|
|
59 |
}
|
|
60 |
*/
|
|
61 |
/*
|
|
62 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
63 |
[super viewWillDisappear:animated];
|
|
64 |
}
|
|
65 |
*/
|
|
66 |
/*
|
|
67 |
- (void)viewDidDisappear:(BOOL)animated {
|
|
68 |
[super viewDidDisappear:animated];
|
|
69 |
}
|
|
70 |
*/
|
|
71 |
|
|
72 |
|
|
73 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
74 |
return rotationManager(interfaceOrientation);
|
|
75 |
}
|
|
76 |
|
|
77 |
|
|
78 |
#pragma mark -
|
|
79 |
#pragma mark Table view data source
|
|
80 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
3364
|
81 |
return 2;
|
3361
|
82 |
}
|
|
83 |
|
|
84 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
3364
|
85 |
if (section == 0)
|
|
86 |
return [listOfSelectedTeams count] ;
|
|
87 |
else
|
|
88 |
return [listOfTeams count];
|
3361
|
89 |
}
|
|
90 |
|
3364
|
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 |
}
|
3361
|
97 |
|
|
98 |
// Customize the appearance of table view cells.
|
|
99 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
3364
|
100 |
static NSString *CellIdentifier0 = @"Cell0";
|
|
101 |
static NSString *CellIdentifier1 = @"Cell1";
|
|
102 |
NSInteger section = [indexPath section];
|
|
103 |
UITableViewCell *cell;
|
3361
|
104 |
|
3364
|
105 |
if (section == 0) {
|
|
106 |
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
|
|
107 |
if (cell == nil) {
|
|
108 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease];
|
|
109 |
|
|
110 |
UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)];
|
|
111 |
numberButton.tag = NUMBERBUTTON_TAG;
|
|
112 |
[cell addSubview:numberButton];
|
|
113 |
[numberButton 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 |
}
|
3361
|
128 |
|
3364
|
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;
|
3361
|
137 |
|
3364
|
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];
|
3361
|
147 |
}
|
3364
|
148 |
|
3361
|
149 |
return cell;
|
|
150 |
}
|
|
151 |
|
|
152 |
|
|
153 |
/*
|
|
154 |
// Override to support conditional editing of the table view.
|
|
155 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
156 |
// Return NO if you do not want the specified item to be editable.
|
|
157 |
return YES;
|
|
158 |
}
|
|
159 |
*/
|
|
160 |
|
|
161 |
|
|
162 |
/*
|
|
163 |
// Override to support editing the table view.
|
|
164 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
165 |
|
|
166 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
167 |
// Delete the row from the data source
|
|
168 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
169 |
}
|
|
170 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
171 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
172 |
}
|
|
173 |
}
|
|
174 |
*/
|
|
175 |
|
|
176 |
|
|
177 |
/*
|
|
178 |
// Override to support rearranging the table view.
|
|
179 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
180 |
}
|
|
181 |
*/
|
|
182 |
|
|
183 |
/*
|
|
184 |
// Override to support conditional rearranging of the table view.
|
|
185 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
186 |
// Return NO if you do not want the item to be re-orderable.
|
|
187 |
return YES;
|
|
188 |
}
|
|
189 |
*/
|
|
190 |
|
|
191 |
#pragma mark -
|
|
192 |
#pragma mark Table view delegate
|
3364
|
193 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
194 |
NSInteger row = [indexPath row];
|
|
195 |
NSInteger section = [indexPath section];
|
3361
|
196 |
|
3364
|
197 |
if (section == 0) {
|
|
198 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]];
|
|
199 |
[self.listOfSelectedTeams removeObjectAtIndex:row];
|
|
200 |
} else {
|
|
201 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]];
|
|
202 |
[self.listOfTeams removeObjectAtIndex:row];
|
|
203 |
}
|
|
204 |
[self.tableView reloadData];
|
3361
|
205 |
}
|
|
206 |
|
|
207 |
|
|
208 |
#pragma mark -
|
|
209 |
#pragma mark Memory management
|
|
210 |
-(void) didReceiveMemoryWarning {
|
|
211 |
// Releases the view if it doesn't have a superview.
|
|
212 |
[super didReceiveMemoryWarning];
|
|
213 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
214 |
}
|
|
215 |
|
|
216 |
-(void) viewDidUnload {
|
|
217 |
self.listOfTeams = nil;
|
|
218 |
}
|
|
219 |
|
|
220 |
|
|
221 |
-(void) dealloc {
|
|
222 |
[listOfTeams release];
|
|
223 |
[super dealloc];
|
|
224 |
}
|
|
225 |
|
|
226 |
|
|
227 |
@end
|
|
228 |
|