author | koda |
Fri, 13 Aug 2010 02:13:18 +0200 | |
changeset 3737 | 2ba6ac8a114b |
parent 3703 | 12d17c6e8855 |
child 3739 | 97cf933e5bd2 |
permissions | -rw-r--r-- |
3547 | 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 |
|
15 |
@synthesize listOfTeams, listOfSelectedTeams; |
|
16 |
||
17 |
#define NUMBERBUTTON_TAG 123456 |
|
18 |
#define SQUAREBUTTON_TAG 654321 |
|
19 |
#define LABEL_TAG 456123 |
|
20 |
||
21 |
#pragma mark - |
|
22 |
#pragma mark View lifecycle |
|
23 |
-(void) viewDidLoad { |
|
24 |
[super viewDidLoad]; |
|
3697 | 25 |
|
3547 | 26 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
27 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
3551 | 28 |
isFirstLoad = YES; |
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
29 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
30 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
31 |
[self.tableView setBackgroundView:nil]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
32 |
self.view.backgroundColor = [UIColor clearColor]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
33 |
self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
34 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
35 |
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
3547 | 36 |
} |
37 |
||
38 |
-(void) viewWillAppear:(BOOL)animated { |
|
39 |
[super viewWillAppear:animated]; |
|
40 |
||
3551 | 41 |
// avoid overwriting selected teams when returning on this view |
42 |
if (isFirstLoad) { |
|
43 |
// integer representation of various color (defined in SquareButtonView) |
|
44 |
NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 }; |
|
45 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
|
46 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
|
47 |
for (int i = 0; i < [contentsOfDir count]; i++) { |
|
48 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
|
49 |
[contentsOfDir objectAtIndex:i],@"team", |
|
50 |
[NSNumber numberWithInt:4],@"number", |
|
51 |
[NSNumber numberWithInt:colors[i%6]],@"color",nil]; |
|
52 |
[array addObject:dict]; |
|
53 |
[dict release]; |
|
54 |
} |
|
55 |
self.listOfTeams = array; |
|
56 |
[array release]; |
|
3697 | 57 |
|
3551 | 58 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
59 |
self.listOfSelectedTeams = emptyArray; |
|
60 |
[emptyArray release]; |
|
61 |
isFirstLoad = NO; |
|
3547 | 62 |
} |
63 |
[self.tableView reloadData]; |
|
64 |
} |
|
65 |
||
66 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
67 |
return rotationManager(interfaceOrientation); |
|
68 |
} |
|
69 |
||
70 |
||
71 |
#pragma mark - |
|
72 |
#pragma mark Table view data source |
|
73 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
74 |
return 2; |
|
75 |
} |
|
76 |
||
77 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
78 |
if (section == 0) |
|
79 |
return [listOfSelectedTeams count] ; |
|
80 |
else |
|
81 |
return [listOfTeams count]; |
|
82 |
} |
|
83 |
||
84 |
// Customize the appearance of table view cells. |
|
85 |
-(UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
86 |
static NSString *CellIdentifier0 = @"Cell0"; |
|
87 |
static NSString *CellIdentifier1 = @"Cell1"; |
|
88 |
NSInteger section = [indexPath section]; |
|
89 |
UITableViewCell *cell; |
|
3697 | 90 |
|
3547 | 91 |
if (section == 0) { |
92 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier0]; |
|
93 |
if (cell == nil) { |
|
94 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier0] autorelease]; |
|
95 |
||
96 |
UIButton *numberButton = [[HogButtonView alloc] initWithFrame:CGRectMake(12, 5, 88, 32)]; |
|
97 |
numberButton.tag = NUMBERBUTTON_TAG; |
|
98 |
[cell addSubview:numberButton]; |
|
99 |
[numberButton release]; |
|
3697 | 100 |
|
3547 | 101 |
SquareButtonView *squareButton = [[SquareButtonView alloc] initWithFrame:CGRectMake(12+88+7, 5, 36, 36)]; |
102 |
squareButton.tag = SQUAREBUTTON_TAG; |
|
103 |
[cell addSubview:squareButton]; |
|
104 |
[squareButton release]; |
|
3697 | 105 |
|
3547 | 106 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; |
107 |
label.textAlignment = UITextAlignmentLeft; |
|
108 |
label.backgroundColor = [UIColor clearColor]; |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
109 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
110 |
label.textColor = UICOLOR_HW_YELLOW_TEXT; |
3547 | 111 |
label.tag = LABEL_TAG; |
112 |
[cell.contentView addSubview:label]; |
|
113 |
[label release]; |
|
114 |
} |
|
3697 | 115 |
|
3547 | 116 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
3697 | 117 |
|
3547 | 118 |
UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG]; |
119 |
cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
|
3697 | 120 |
|
3547 | 121 |
HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG]; |
122 |
[numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]]; |
|
123 |
numberButton.ownerDictionary = selectedRow; |
|
3697 | 124 |
|
3547 | 125 |
SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG]; |
126 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
|
127 |
squareButton.ownerDictionary = selectedRow; |
|
128 |
} else { |
|
129 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
|
3697 | 130 |
if (cell == nil) |
3547 | 131 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
3697 | 132 |
|
3547 | 133 |
cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
134 |
} |
|
3697 | 135 |
|
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
136 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
137 |
cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
138 |
cell.backgroundColor = [UIColor blackColor]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
139 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
140 |
|
3547 | 141 |
return cell; |
142 |
} |
|
143 |
||
3703
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
144 |
-(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
145 |
return 40.0; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
146 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
147 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
148 |
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
149 |
NSString *fileToLoad; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
150 |
if (section == 0) |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
151 |
fileToLoad = @"PlayingTeamsLabel.png"; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
152 |
else |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
153 |
fileToLoad = @"AvailableTeamsLabel.png"; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
154 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
155 |
UIImage *img = [[UIImage alloc] initWithContentsOfFile:fileToLoad]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
156 |
UIImageView *imgView = [[[UIImageView alloc] initWithImage:img] autorelease]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
157 |
[img release]; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
158 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
159 |
return imgView; |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
160 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
161 |
|
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
162 |
/* |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
163 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
164 |
if (section == 0) |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
165 |
return NSLocalizedString(@"Playing Teams",@""); |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
166 |
else |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
167 |
return NSLocalizedString(@"Available Teams",@""); |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
168 |
} |
12d17c6e8855
halfway-through finishing the frontend with new graphics by Tiy + initial 'About' page set up
koda
parents:
3697
diff
changeset
|
169 |
*/ |
3547 | 170 |
|
171 |
#pragma mark - |
|
172 |
#pragma mark Table view delegate |
|
173 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
174 |
NSInteger row = [indexPath row]; |
|
175 |
NSInteger section = [indexPath section]; |
|
176 |
||
177 |
if (section == 0) { |
|
178 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
|
179 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
|
180 |
} else { |
|
181 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
|
3697 | 182 |
[self.listOfTeams removeObjectAtIndex:row]; |
3547 | 183 |
} |
184 |
[aTableView reloadData]; |
|
185 |
} |
|
186 |
||
187 |
||
188 |
#pragma mark - |
|
189 |
#pragma mark Memory management |
|
190 |
-(void) didReceiveMemoryWarning { |
|
191 |
// Releases the view if it doesn't have a superview. |
|
192 |
[super didReceiveMemoryWarning]; |
|
193 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
194 |
} |
|
195 |
||
196 |
-(void) viewDidUnload { |
|
197 |
self.listOfTeams = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3659
diff
changeset
|
198 |
MSG_DIDUNLOAD(); |
3547 | 199 |
[super viewDidUnload]; |
200 |
} |
|
201 |
||
202 |
||
203 |
-(void) dealloc { |
|
204 |
[self.listOfTeams release]; |
|
205 |
[super dealloc]; |
|
206 |
} |
|
207 |
||
208 |
||
209 |
@end |
|
210 |