3305
|
1 |
//
|
|
2 |
// SingleTeamViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 02/04/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "SingleTeamViewController.h"
|
|
10 |
#import "HogHatViewController.h"
|
|
11 |
|
|
12 |
@implementation SingleTeamViewController
|
3312
|
13 |
@synthesize hogsList, hatList, secondaryItems, teamName;
|
3305
|
14 |
|
|
15 |
|
|
16 |
#pragma mark -
|
|
17 |
#pragma mark View lifecycle
|
|
18 |
- (void)viewDidLoad {
|
|
19 |
[super viewDidLoad];
|
|
20 |
|
|
21 |
// Uncomment the following line to preserve selection between presentations.
|
|
22 |
//self.clearsSelectionOnViewWillAppear = NO;
|
|
23 |
|
|
24 |
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
|
|
25 |
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
|
|
26 |
|
|
27 |
NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:
|
|
28 |
NSLocalizedString(@"Color",@""),
|
|
29 |
NSLocalizedString(@"Grave",@""),
|
|
30 |
NSLocalizedString(@"Voice",@""),
|
|
31 |
NSLocalizedString(@"Fort",@""),
|
|
32 |
NSLocalizedString(@"Flag",@""),
|
|
33 |
NSLocalizedString(@"Level",@""),nil];
|
|
34 |
self.secondaryItems = array;
|
|
35 |
[array release];
|
|
36 |
}
|
|
37 |
|
|
38 |
|
|
39 |
- (void)viewWillAppear:(BOOL)animated {
|
|
40 |
[super viewWillAppear:animated];
|
3312
|
41 |
|
|
42 |
// load data about the team and extract info
|
3305
|
43 |
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
3308
|
44 |
NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/Teams/%@.plist",[paths objectAtIndex:0],self.teamName];
|
3305
|
45 |
NSDictionary *teamDict = [[NSDictionary alloc] initWithContentsOfFile:teamFile];
|
|
46 |
[teamFile release];
|
|
47 |
|
3312
|
48 |
// grab the hog list
|
3305
|
49 |
self.hogsList = [teamDict objectForKey:@"hedgehogs"];
|
3312
|
50 |
// grab the name of the team
|
3305
|
51 |
self.teamName = [teamDict objectForKey:@"teamname"];
|
3312
|
52 |
self.title = self.teamName;
|
3305
|
53 |
[teamDict release];
|
3312
|
54 |
|
|
55 |
// load the images of the hat for aach hog
|
|
56 |
NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[self.hogsList count]];
|
|
57 |
for (NSDictionary *hog in self.hogsList) {
|
|
58 |
NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/Data/Graphics/Hats/%@.png",[[NSBundle mainBundle] resourcePath],[hog objectForKey:@"hat"]];
|
|
59 |
|
|
60 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile: hatFile];
|
|
61 |
CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
|
|
62 |
CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
|
|
63 |
[image release];
|
|
64 |
|
|
65 |
UIImage *hatSprite = [[UIImage alloc] initWithCGImage:cgImgage];
|
|
66 |
[array addObject:hatSprite];
|
|
67 |
CGImageRelease(cgImgage);
|
|
68 |
[hatSprite release];
|
|
69 |
}
|
|
70 |
self.hatList = array;
|
|
71 |
[array release];
|
3305
|
72 |
}
|
|
73 |
|
|
74 |
/*
|
|
75 |
- (void)viewDidAppear:(BOOL)animated {
|
|
76 |
[super viewDidAppear:animated];
|
|
77 |
}
|
|
78 |
*/
|
|
79 |
/*
|
|
80 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
81 |
[super viewWillDisappear:animated];
|
|
82 |
}
|
|
83 |
*/
|
|
84 |
/*
|
|
85 |
- (void)viewDidDisappear:(BOOL)animated {
|
|
86 |
[super viewDidDisappear:animated];
|
|
87 |
}
|
|
88 |
*/
|
|
89 |
|
|
90 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
91 |
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
#pragma mark -
|
|
96 |
#pragma mark Table view data source
|
|
97 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
98 |
return 3;
|
|
99 |
}
|
|
100 |
|
|
101 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
3312
|
102 |
NSInteger rows = 0;
|
3305
|
103 |
switch (section) {
|
|
104 |
case 0:
|
|
105 |
rows = 1;
|
|
106 |
break;
|
|
107 |
case 1:
|
|
108 |
rows = 8;
|
|
109 |
break;
|
|
110 |
case 2:
|
|
111 |
rows = 6;
|
|
112 |
break;
|
|
113 |
default:
|
|
114 |
break;
|
|
115 |
}
|
|
116 |
return rows;
|
|
117 |
}
|
|
118 |
|
|
119 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
120 |
static NSString *CellIdentifier = @"Cell";
|
|
121 |
|
|
122 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
123 |
if (cell == nil) {
|
|
124 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
|
|
125 |
reuseIdentifier:CellIdentifier] autorelease];
|
|
126 |
}
|
|
127 |
|
|
128 |
NSInteger row = [indexPath row];
|
|
129 |
switch ([indexPath section]) {
|
|
130 |
case 0:
|
|
131 |
cell.textLabel.text = teamName;
|
|
132 |
break;
|
|
133 |
case 1:
|
|
134 |
cell.textLabel.text = [[self.hogsList objectAtIndex:row] objectForKey:@"hogname"];
|
|
135 |
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
|
3312
|
136 |
cell.imageView.image = [self.hatList objectAtIndex:row];
|
3305
|
137 |
break;
|
|
138 |
case 2:
|
|
139 |
cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
|
|
140 |
break;
|
|
141 |
default:
|
|
142 |
break;
|
|
143 |
}
|
|
144 |
|
|
145 |
return cell;
|
|
146 |
}
|
|
147 |
|
|
148 |
|
|
149 |
/*
|
|
150 |
// Override to support conditional editing of the table view.
|
|
151 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
152 |
// Return NO if you do not want the specified item to be editable.
|
|
153 |
return YES;
|
|
154 |
}
|
|
155 |
*/
|
|
156 |
|
|
157 |
|
|
158 |
/*
|
|
159 |
// Override to support editing the table view.
|
|
160 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
161 |
|
|
162 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
163 |
// Delete the row from the data source
|
|
164 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
165 |
}
|
|
166 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
167 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
168 |
}
|
|
169 |
}
|
|
170 |
*/
|
|
171 |
|
|
172 |
|
|
173 |
/*
|
|
174 |
// Override to support rearranging the table view.
|
|
175 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
176 |
}
|
|
177 |
*/
|
|
178 |
|
|
179 |
|
|
180 |
/*
|
|
181 |
// Override to support conditional rearranging of the table view.
|
|
182 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
183 |
// Return NO if you do not want the item to be re-orderable.
|
|
184 |
return YES;
|
|
185 |
}
|
|
186 |
*/
|
|
187 |
|
|
188 |
|
|
189 |
#pragma mark -
|
|
190 |
#pragma mark Table view delegate
|
|
191 |
|
|
192 |
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
193 |
if (1 == [indexPath section]) {
|
|
194 |
if (nil == hogChildController) {
|
|
195 |
hogChildController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
|
|
196 |
}
|
|
197 |
|
|
198 |
hogChildController.hog = [hogsList objectAtIndex:[indexPath row]];
|
|
199 |
//NSLog(@"%@",hogChildController.hog);
|
|
200 |
[self.navigationController pushViewController:hogChildController animated:YES];
|
|
201 |
}
|
|
202 |
}
|
|
203 |
|
|
204 |
|
|
205 |
#pragma mark -
|
|
206 |
#pragma mark Memory management
|
|
207 |
|
|
208 |
-(void) didReceiveMemoryWarning {
|
|
209 |
// Releases the view if it doesn't have a superview.
|
|
210 |
[super didReceiveMemoryWarning];
|
|
211 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
212 |
}
|
|
213 |
|
|
214 |
-(void) viewDidUnload {
|
|
215 |
self.hogsList = nil;
|
|
216 |
self.secondaryItems = nil;
|
|
217 |
self.teamName = nil;
|
|
218 |
}
|
|
219 |
|
|
220 |
|
|
221 |
-(void) dealloc {
|
|
222 |
[secondaryItems release];
|
|
223 |
[hogsList release];
|
|
224 |
[teamName release];
|
|
225 |
[super dealloc];
|
|
226 |
}
|
|
227 |
|
|
228 |
|
|
229 |
@end
|
|
230 |
|