|
1 // |
|
2 // HogHatViewController.m |
|
3 // HedgewarsMobile |
|
4 // |
|
5 // Created by Vittorio on 02/04/10. |
|
6 // Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 // |
|
8 |
|
9 #import "HogHatViewController.h" |
|
10 #import "CommodityFunctions.h" |
|
11 |
|
12 |
|
13 @implementation LevelViewController |
|
14 @synthesize teamDictionary, levelArray, levelSprites, lastIndexPath; |
|
15 |
|
16 |
|
17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
18 return rotationManager(interfaceOrientation); |
|
19 } |
|
20 |
|
21 |
|
22 #pragma mark - |
|
23 #pragma mark View lifecycle |
|
24 - (void)viewDidLoad { |
|
25 [super viewDidLoad]; |
|
26 |
|
27 NSArray *array = [[NSArray alloc] initWithObjects: |
|
28 NSLocalizedString(@"Human",@""), |
|
29 NSLocalizedString(@"Weaky",@""), |
|
30 NSLocalizedString(@"Average",@""), |
|
31 NSLocalizedString(@"Bully",@""), |
|
32 NSLocalizedString(@"Aggressive",@""),nil] |
|
33 self.levelArray = array; |
|
34 [array release]; |
|
35 /* |
|
36 NSMutableArray *sprites = [[NSMutableArray alloc] initWithCapacity:[graveArray count]; |
|
37 for (NSString *graveName in graveArray) { |
|
38 NSString *gravePath = [[NSString alloc] initWithFormat@"%@/%@",GRAVES_DIRECTORY(),graveName]; |
|
39 UIImage *image = [[UIImage alloc] initWithContentsOfFile:gravePath]; |
|
40 [gravePath release]; |
|
41 [sprites addObject:image]; |
|
42 [image release]; |
|
43 } |
|
44 self.graveSprites = sprites; |
|
45 [sprites release]; |
|
46 */ |
|
47 } |
|
48 |
|
49 - (void)viewWillAppear:(BOOL)animated { |
|
50 [super viewWillAppear:animated]; |
|
51 |
|
52 // this moves the tableview to the top |
|
53 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
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 #pragma mark - |
|
74 #pragma mark Table view data source |
|
75 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
76 return 1; |
|
77 } |
|
78 |
|
79 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
80 return [self.levelArray count]; |
|
81 } |
|
82 |
|
83 // Customize the appearance of table view cells. |
|
84 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
85 |
|
86 static NSString *CellIdentifier = @"Cell"; |
|
87 |
|
88 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
89 if (cell == nil) { |
|
90 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
91 } |
|
92 |
|
93 cell.textLabel.text = [[levelArray objectAtIndex:[indexPath row]] stringValue]; |
|
94 NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0] |
|
95 if ([cell.textLabel.text isEqualToString:[[hog objectForKey:@"level"]] stringValue]) { |
|
96 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
97 self.lastIndexPath = indexPath; |
|
98 } else { |
|
99 cell.accessoryType = UITableViewCellAccessoryNone; |
|
100 } |
|
101 |
|
102 cell.imageView.image = [levelSprites objectAtIndex:[indexPath row]]: |
|
103 return cell; |
|
104 } |
|
105 |
|
106 |
|
107 /* |
|
108 // Override to support conditional editing of the table view. |
|
109 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
110 // Return NO if you do not want the specified item to be editable. |
|
111 return YES; |
|
112 } |
|
113 */ |
|
114 |
|
115 |
|
116 /* |
|
117 // Override to support editing the table view. |
|
118 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
119 |
|
120 if (editingStyle == UITableViewCellEditingStyleDelete) { |
|
121 // Delete the row from the data source |
|
122 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
123 } |
|
124 else if (editingStyle == UITableViewCellEditingStyleInsert) { |
|
125 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
126 } |
|
127 } |
|
128 */ |
|
129 |
|
130 |
|
131 /* |
|
132 // Override to support rearranging the table view. |
|
133 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
134 } |
|
135 */ |
|
136 |
|
137 |
|
138 /* |
|
139 // Override to support conditional rearranging of the table view. |
|
140 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
141 // Return NO if you do not want the item to be re-orderable. |
|
142 return YES; |
|
143 } |
|
144 */ |
|
145 |
|
146 |
|
147 #pragma mark - |
|
148 #pragma mark Table view delegate |
|
149 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
150 int newRow = [indexPath row]; |
|
151 int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
152 |
|
153 if (newRow != oldRow) { |
|
154 NSMutableArray *hogs = [teamDictionary objectForKey:@"hedgehogs"]; |
|
155 |
|
156 for (NSDictionary *hog in hogs) { |
|
157 [hog setObject:[NSNumber numberWithInt:newRow] forKey:@"level"]; |
|
158 } |
|
159 |
|
160 // tell our boss to write this new stuff on disk |
|
161 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
162 [self.tableView reloadData]; |
|
163 |
|
164 self.lastIndexPath = indexPath; |
|
165 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
166 |
|
167 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
168 [self.navigationController popViewControllerAnimated:YES]; |
|
169 } |
|
170 |
|
171 |
|
172 #pragma mark - |
|
173 #pragma mark Memory management |
|
174 - (void)didReceiveMemoryWarning { |
|
175 // Releases the view if it doesn't have a superview. |
|
176 [super didReceiveMemoryWarning]; |
|
177 // Relinquish ownership any cached data, images, etc that aren't in use. |
|
178 } |
|
179 |
|
180 - (void)viewDidUnload { |
|
181 [super viewDidUnload]; |
|
182 self.lastIndexPath = nil; |
|
183 self.teamDictionary = nil; |
|
184 self.levelArray = nil; |
|
185 self.levelSprites = nil; |
|
186 } |
|
187 |
|
188 - (void)dealloc { |
|
189 [levelArray release]; |
|
190 [levelSprites release]; |
|
191 [teamDictionary release]; |
|
192 [lastIndexPath release]; |
|
193 [super dealloc]; |
|
194 } |
|
195 |
|
196 |
|
197 @end |
|
198 |