9 #import "GravesViewController.h" |
9 #import "GravesViewController.h" |
10 #import "CommodityFunctions.h" |
10 #import "CommodityFunctions.h" |
11 #import "UIImageExtra.h" |
11 #import "UIImageExtra.h" |
12 |
12 |
13 @implementation GravesViewController |
13 @implementation GravesViewController |
14 @synthesize teamDictionary, graveArray, graveSprites, lastIndexPath; |
14 @synthesize teamDictionary, graveArray, lastIndexPath; |
15 |
15 |
16 |
16 |
17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
17 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
18 return rotationManager(interfaceOrientation); |
18 return rotationManager(interfaceOrientation); |
19 } |
19 } |
20 |
20 |
21 |
21 |
22 #pragma mark - |
22 #pragma mark - |
23 #pragma mark View lifecycle |
23 #pragma mark View lifecycle |
24 - (void)viewDidLoad { |
24 -(void) viewDidLoad { |
25 [super viewDidLoad]; |
25 [super viewDidLoad]; |
26 |
26 |
27 // load all the voices names and store them into voiceArray |
27 // load all the grave names and store them into graveArray |
28 NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; |
28 self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; |
29 self.graveArray = array; |
|
30 |
|
31 NSMutableArray *sprites = [[NSMutableArray alloc] initWithCapacity:[graveArray count]]; |
|
32 for (NSString *graveName in graveArray) { |
|
33 NSString *gravePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),graveName]; |
|
34 // because we also have multi frame graves, let's take the first one only |
|
35 UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:gravePath andCutAt:CGRectMake(0, 0, 32, 32)]; |
|
36 [gravePath release]; |
|
37 |
|
38 [sprites addObject:graveSprite]; |
|
39 [graveSprite release]; |
|
40 } |
|
41 self.graveSprites = sprites; |
|
42 [sprites release]; |
|
43 } |
29 } |
44 |
30 |
45 - (void)viewWillAppear:(BOOL)animated { |
31 -(void) viewWillAppear:(BOOL)animated { |
46 [super viewWillAppear:animated]; |
32 [super viewWillAppear:animated]; |
47 |
33 [self.tableView reloadData]; |
48 // this moves the tableview to the top |
34 // this moves the tableview to the top |
49 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
35 [self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
50 } |
36 } |
51 |
|
52 /* |
|
53 - (void)viewDidAppear:(BOOL)animated { |
|
54 [super viewDidAppear:animated]; |
|
55 } |
|
56 */ |
|
57 /* |
|
58 - (void)viewWillDisappear:(BOOL)animated { |
|
59 [super viewWillDisappear:animated]; |
|
60 } |
|
61 */ |
|
62 /* |
|
63 - (void)viewDidDisappear:(BOOL)animated { |
|
64 [super viewDidDisappear:animated]; |
|
65 } |
|
66 */ |
|
67 |
37 |
68 |
38 |
69 #pragma mark - |
39 #pragma mark - |
70 #pragma mark Table view data source |
40 #pragma mark Table view data source |
71 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
41 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
75 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
45 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
76 return [self.graveArray count]; |
46 return [self.graveArray count]; |
77 } |
47 } |
78 |
48 |
79 // Customize the appearance of table view cells. |
49 // Customize the appearance of table view cells. |
80 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
50 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
81 |
51 |
82 static NSString *CellIdentifier = @"Cell"; |
52 static NSString *CellIdentifier = @"Cell"; |
83 |
53 |
84 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
54 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
85 if (cell == nil) |
55 if (cell == nil) |
86 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
56 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
87 |
57 |
88 NSString *grave = [[graveArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension]; |
58 NSString *grave = [graveArray objectAtIndex:[indexPath row]]; |
89 cell.textLabel.text = grave; |
59 cell.textLabel.text = [grave stringByDeletingPathExtension]; |
90 |
60 |
91 if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) { |
61 if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) { |
92 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
62 cell.accessoryType = UITableViewCellAccessoryCheckmark; |
93 self.lastIndexPath = indexPath; |
63 self.lastIndexPath = indexPath; |
94 } else { |
64 } else { |
95 cell.accessoryType = UITableViewCellAccessoryNone; |
65 cell.accessoryType = UITableViewCellAccessoryNone; |
96 } |
66 } |
|
67 |
|
68 NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave]; |
|
69 // because we also have multi frame graves, let's take the first one only |
|
70 UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)]; |
|
71 [graveFilePath release]; |
|
72 cell.imageView.image = graveSprite; |
|
73 [graveSprite release]; |
97 |
74 |
98 cell.imageView.image = [graveSprites objectAtIndex:[indexPath row]]; |
|
99 return cell; |
75 return cell; |
100 } |
76 } |
101 |
|
102 |
|
103 /* |
|
104 // Override to support conditional editing of the table view. |
|
105 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
106 // Return NO if you do not want the specified item to be editable. |
|
107 return YES; |
|
108 } |
|
109 */ |
|
110 |
|
111 |
|
112 /* |
|
113 // Override to support editing the table view. |
|
114 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
115 |
|
116 if (editingStyle == UITableViewCellEditingStyleDelete) { |
|
117 // Delete the row from the data source |
|
118 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
119 } |
|
120 else if (editingStyle == UITableViewCellEditingStyleInsert) { |
|
121 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
122 } |
|
123 } |
|
124 */ |
|
125 |
|
126 |
|
127 /* |
|
128 // Override to support rearranging the table view. |
|
129 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
130 } |
|
131 */ |
|
132 |
|
133 |
|
134 /* |
|
135 // Override to support conditional rearranging of the table view. |
|
136 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
137 // Return NO if you do not want the item to be re-orderable. |
|
138 return YES; |
|
139 } |
|
140 */ |
|
141 |
77 |
142 |
78 |
143 #pragma mark - |
79 #pragma mark - |
144 #pragma mark Table view delegate |
80 #pragma mark Table view delegate |
145 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
81 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
149 if (newRow != oldRow) { |
85 if (newRow != oldRow) { |
150 [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
86 [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
151 |
87 |
152 // tell our boss to write this new stuff on disk |
88 // tell our boss to write this new stuff on disk |
153 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
89 [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
154 [self.tableView reloadData]; |
|
155 |
90 |
|
91 UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
92 newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
93 UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
94 oldCell.accessoryType = UITableViewCellAccessoryNone; |
156 self.lastIndexPath = indexPath; |
95 self.lastIndexPath = indexPath; |
157 [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
96 [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
158 } |
97 } |
159 [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
98 [aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
160 [self.navigationController popViewControllerAnimated:YES]; |
99 [self.navigationController popViewControllerAnimated:YES]; |
161 } |
100 } |
162 |
101 |
163 |
102 |
164 #pragma mark - |
103 #pragma mark - |
172 - (void)viewDidUnload { |
111 - (void)viewDidUnload { |
173 [super viewDidUnload]; |
112 [super viewDidUnload]; |
174 self.lastIndexPath = nil; |
113 self.lastIndexPath = nil; |
175 self.teamDictionary = nil; |
114 self.teamDictionary = nil; |
176 self.graveArray = nil; |
115 self.graveArray = nil; |
177 self.graveSprites = nil; |
|
178 } |
116 } |
179 |
117 |
180 - (void)dealloc { |
118 - (void)dealloc { |
181 [graveSprites release]; |
|
182 [graveArray release]; |
119 [graveArray release]; |
183 [teamDictionary release]; |
120 [teamDictionary release]; |
184 [lastIndexPath release]; |
121 [lastIndexPath release]; |
185 [super dealloc]; |
122 [super dealloc]; |
186 } |
123 } |