author | smaxx |
Fri, 30 Jul 2010 18:20:42 +0200 | |
changeset 3689 | e2be39ee19f0 |
parent 3662 | a44406f4369b |
child 3697 | d5b30d6373fc |
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]; |
|
25 |
||
26 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
|
27 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
3551 | 28 |
isFirstLoad = YES; |
3547 | 29 |
} |
30 |
||
31 |
-(void) viewWillAppear:(BOOL)animated { |
|
32 |
[super viewWillAppear:animated]; |
|
33 |
||
3551 | 34 |
// avoid overwriting selected teams when returning on this view |
35 |
if (isFirstLoad) { |
|
36 |
// integer representation of various color (defined in SquareButtonView) |
|
37 |
NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 }; |
|
38 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL]; |
|
39 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]]; |
|
40 |
for (int i = 0; i < [contentsOfDir count]; i++) { |
|
41 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys: |
|
42 |
[contentsOfDir objectAtIndex:i],@"team", |
|
43 |
[NSNumber numberWithInt:4],@"number", |
|
44 |
[NSNumber numberWithInt:colors[i%6]],@"color",nil]; |
|
45 |
[array addObject:dict]; |
|
46 |
[dict release]; |
|
47 |
} |
|
48 |
self.listOfTeams = array; |
|
49 |
[array release]; |
|
50 |
||
51 |
NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil]; |
|
52 |
self.listOfSelectedTeams = emptyArray; |
|
53 |
[emptyArray release]; |
|
54 |
isFirstLoad = NO; |
|
3547 | 55 |
} |
56 |
[self.tableView reloadData]; |
|
57 |
} |
|
58 |
||
59 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
60 |
return rotationManager(interfaceOrientation); |
|
61 |
} |
|
62 |
||
63 |
||
64 |
#pragma mark - |
|
65 |
#pragma mark Table view data source |
|
66 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
67 |
return 2; |
|
68 |
} |
|
69 |
||
70 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
71 |
if (section == 0) |
|
72 |
return [listOfSelectedTeams count] ; |
|
73 |
else |
|
74 |
return [listOfTeams count]; |
|
75 |
} |
|
76 |
||
77 |
-(NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section { |
|
78 |
if (section == 0) |
|
79 |
return NSLocalizedString(@"Playing Teams",@""); |
|
80 |
else |
|
81 |
return NSLocalizedString(@"Available Teams",@""); |
|
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; |
|
90 |
||
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]; |
|
100 |
||
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]; |
|
105 |
||
106 |
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12+88+7+36+7, 10, 250, 25)]; |
|
107 |
label.textAlignment = UITextAlignmentLeft; |
|
108 |
label.backgroundColor = [UIColor clearColor]; |
|
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
|
109 |
label.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize] + 2]; |
3547 | 110 |
label.tag = LABEL_TAG; |
111 |
[cell.contentView addSubview:label]; |
|
112 |
[label release]; |
|
113 |
} |
|
114 |
||
115 |
NSMutableDictionary *selectedRow = [listOfSelectedTeams objectAtIndex:[indexPath row]]; |
|
116 |
||
117 |
UILabel *cellLabel = (UILabel *)[cell viewWithTag:LABEL_TAG]; |
|
118 |
cellLabel.text = [[selectedRow objectForKey:@"team"] stringByDeletingPathExtension]; |
|
119 |
||
120 |
HogButtonView *numberButton = (HogButtonView *)[cell viewWithTag:NUMBERBUTTON_TAG]; |
|
121 |
[numberButton drawManyHogs:[[selectedRow objectForKey:@"number"] intValue]]; |
|
122 |
numberButton.ownerDictionary = selectedRow; |
|
123 |
||
124 |
SquareButtonView *squareButton = (SquareButtonView *)[cell viewWithTag:SQUAREBUTTON_TAG]; |
|
125 |
[squareButton selectColor:[[selectedRow objectForKey:@"color"] intValue]]; |
|
126 |
squareButton.ownerDictionary = selectedRow; |
|
3625 | 127 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
3659 | 128 |
cellLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1]; |
3625 | 129 |
} |
3547 | 130 |
} else { |
131 |
cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier1]; |
|
132 |
if (cell == nil) |
|
133 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; |
|
134 |
||
135 |
cell.textLabel.text = [[[listOfTeams objectAtIndex:[indexPath row]] objectForKey:@"team"] stringByDeletingPathExtension]; |
|
3625 | 136 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
137 |
cell.textLabel.textColor = [UIColor colorWithRed:(CGFloat)0xFE/255 green:(CGFloat)0xCB/255 blue:0 alpha:1 ]; |
|
138 |
} |
|
3547 | 139 |
} |
3625 | 140 |
|
3547 | 141 |
return cell; |
142 |
} |
|
143 |
||
144 |
||
145 |
#pragma mark - |
|
146 |
#pragma mark Table view delegate |
|
147 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
148 |
NSInteger row = [indexPath row]; |
|
149 |
NSInteger section = [indexPath section]; |
|
150 |
||
151 |
if (section == 0) { |
|
152 |
[self.listOfTeams addObject:[self.listOfSelectedTeams objectAtIndex:row]]; |
|
153 |
[self.listOfSelectedTeams removeObjectAtIndex:row]; |
|
154 |
} else { |
|
155 |
[self.listOfSelectedTeams addObject:[self.listOfTeams objectAtIndex:row]]; |
|
156 |
[self.listOfTeams removeObjectAtIndex:row]; |
|
157 |
} |
|
158 |
[aTableView reloadData]; |
|
159 |
} |
|
160 |
||
161 |
||
162 |
#pragma mark - |
|
163 |
#pragma mark Memory management |
|
164 |
-(void) didReceiveMemoryWarning { |
|
165 |
// Releases the view if it doesn't have a superview. |
|
166 |
[super didReceiveMemoryWarning]; |
|
167 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
168 |
} |
|
169 |
||
170 |
-(void) viewDidUnload { |
|
171 |
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
|
172 |
MSG_DIDUNLOAD(); |
3547 | 173 |
[super viewDidUnload]; |
174 |
} |
|
175 |
||
176 |
||
177 |
-(void) dealloc { |
|
178 |
[self.listOfTeams release]; |
|
179 |
[super dealloc]; |
|
180 |
} |
|
181 |
||
182 |
||
183 |
@end |
|
184 |