3339
|
1 |
//
|
|
2 |
// HogHatViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 02/04/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
3340
|
9 |
#import "GravesViewController.h"
|
3339
|
10 |
#import "CommodityFunctions.h"
|
|
11 |
|
|
12 |
|
|
13 |
@implementation GravesViewController
|
|
14 |
@synthesize teamDictionary, graveArray, graveSprites, 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 |
// load all the voices names and store them into voiceArray
|
|
28 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
|
|
29 |
self.graveArray = array;
|
3340
|
30 |
|
|
31 |
NSMutableArray *sprites = [[NSMutableArray alloc] initWithCapacity:[graveArray count]];
|
3339
|
32 |
for (NSString *graveName in graveArray) {
|
3340
|
33 |
NSString *gravePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),graveName];
|
|
34 |
UIImage *image = [[UIImage alloc] initWithContentsOfFile:gravePath];
|
|
35 |
[gravePath release];
|
|
36 |
|
|
37 |
// because we also have multi frame graves, let's take the first one only
|
|
38 |
if (image.size.height > 32) {
|
|
39 |
CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
|
|
40 |
CGImageRef cgImage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
|
|
41 |
[image release];
|
|
42 |
image = [[UIImage alloc] initWithCGImage:cgImage];
|
|
43 |
CGImageRelease(cgImage);
|
|
44 |
}
|
|
45 |
[sprites addObject:image];
|
|
46 |
[image release];
|
3339
|
47 |
}
|
|
48 |
self.graveSprites = sprites;
|
|
49 |
[sprites release];
|
|
50 |
}
|
|
51 |
|
|
52 |
- (void)viewWillAppear:(BOOL)animated {
|
|
53 |
[super viewWillAppear:animated];
|
|
54 |
|
|
55 |
// this moves the tableview to the top
|
|
56 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
|
|
57 |
}
|
|
58 |
|
|
59 |
/*
|
|
60 |
- (void)viewDidAppear:(BOOL)animated {
|
|
61 |
[super viewDidAppear:animated];
|
|
62 |
}
|
|
63 |
*/
|
|
64 |
/*
|
|
65 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
66 |
[super viewWillDisappear:animated];
|
|
67 |
}
|
|
68 |
*/
|
|
69 |
/*
|
|
70 |
- (void)viewDidDisappear:(BOOL)animated {
|
|
71 |
[super viewDidDisappear:animated];
|
|
72 |
}
|
|
73 |
*/
|
|
74 |
|
|
75 |
|
|
76 |
#pragma mark -
|
|
77 |
#pragma mark Table view data source
|
|
78 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
79 |
return 1;
|
|
80 |
}
|
|
81 |
|
|
82 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
83 |
return [self.graveArray count];
|
|
84 |
}
|
|
85 |
|
|
86 |
// Customize the appearance of table view cells.
|
|
87 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
88 |
|
|
89 |
static NSString *CellIdentifier = @"Cell";
|
|
90 |
|
|
91 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
92 |
if (cell == nil) {
|
|
93 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
94 |
}
|
|
95 |
|
|
96 |
NSString *grave = [[graveArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
|
|
97 |
cell.textLabel.text = grave;
|
|
98 |
|
3340
|
99 |
if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) {
|
3339
|
100 |
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
101 |
self.lastIndexPath = indexPath;
|
|
102 |
} else {
|
|
103 |
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
104 |
}
|
|
105 |
|
3340
|
106 |
cell.imageView.image = [graveSprites objectAtIndex:[indexPath row]];
|
3339
|
107 |
return cell;
|
|
108 |
}
|
|
109 |
|
|
110 |
|
|
111 |
/*
|
|
112 |
// Override to support conditional editing of the table view.
|
|
113 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
114 |
// Return NO if you do not want the specified item to be editable.
|
|
115 |
return YES;
|
|
116 |
}
|
|
117 |
*/
|
|
118 |
|
|
119 |
|
|
120 |
/*
|
|
121 |
// Override to support editing the table view.
|
|
122 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
123 |
|
|
124 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
125 |
// Delete the row from the data source
|
|
126 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
127 |
}
|
|
128 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
129 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
130 |
}
|
|
131 |
}
|
|
132 |
*/
|
|
133 |
|
|
134 |
|
|
135 |
/*
|
|
136 |
// Override to support rearranging the table view.
|
|
137 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
138 |
}
|
|
139 |
*/
|
|
140 |
|
|
141 |
|
|
142 |
/*
|
|
143 |
// Override to support conditional rearranging of the table view.
|
|
144 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
145 |
// Return NO if you do not want the item to be re-orderable.
|
|
146 |
return YES;
|
|
147 |
}
|
|
148 |
*/
|
|
149 |
|
|
150 |
|
|
151 |
#pragma mark -
|
|
152 |
#pragma mark Table view delegate
|
|
153 |
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
154 |
int newRow = [indexPath row];
|
|
155 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
|
|
156 |
|
|
157 |
if (newRow != oldRow) {
|
3340
|
158 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
|
3339
|
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];
|
3340
|
166 |
}
|
3339
|
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.graveArray = nil;
|
3340
|
185 |
self.graveSprites = nil;
|
3339
|
186 |
}
|
|
187 |
|
|
188 |
- (void)dealloc {
|
3340
|
189 |
[graveSprites release];
|
3339
|
190 |
[graveArray release];
|
|
191 |
[teamDictionary release];
|
|
192 |
[lastIndexPath release];
|
|
193 |
[super dealloc];
|
|
194 |
}
|
|
195 |
|
|
196 |
|
|
197 |
@end
|
|
198 |
|