3339
|
1 |
//
|
3352
|
2 |
// GravesViewController.m
|
3339
|
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"
|
3352
|
11 |
#import "UIImageExtra.h"
|
3339
|
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 |
// because we also have multi frame graves, let's take the first one only
|
3352
|
35 |
UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:gravePath andCutAt:CGRectMake(0, 0, 32, 32)];
|
|
36 |
[gravePath release];
|
|
37 |
|
|
38 |
[sprites addObject:graveSprite];
|
|
39 |
[graveSprite release];
|
3339
|
40 |
}
|
|
41 |
self.graveSprites = sprites;
|
|
42 |
[sprites release];
|
|
43 |
}
|
|
44 |
|
|
45 |
- (void)viewWillAppear:(BOOL)animated {
|
|
46 |
[super viewWillAppear:animated];
|
|
47 |
|
|
48 |
// this moves the tableview to the top
|
|
49 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
|
|
50 |
}
|
|
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 |
|
|
68 |
|
|
69 |
#pragma mark -
|
|
70 |
#pragma mark Table view data source
|
|
71 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
72 |
return 1;
|
|
73 |
}
|
|
74 |
|
|
75 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
76 |
return [self.graveArray count];
|
|
77 |
}
|
|
78 |
|
|
79 |
// Customize the appearance of table view cells.
|
|
80 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
81 |
|
|
82 |
static NSString *CellIdentifier = @"Cell";
|
|
83 |
|
|
84 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
85 |
if (cell == nil) {
|
|
86 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
87 |
}
|
|
88 |
|
|
89 |
NSString *grave = [[graveArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
|
|
90 |
cell.textLabel.text = grave;
|
|
91 |
|
3340
|
92 |
if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) {
|
3339
|
93 |
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
94 |
self.lastIndexPath = indexPath;
|
|
95 |
} else {
|
|
96 |
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
97 |
}
|
|
98 |
|
3340
|
99 |
cell.imageView.image = [graveSprites objectAtIndex:[indexPath row]];
|
3339
|
100 |
return cell;
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
/*
|
|
105 |
// Override to support conditional editing of the table view.
|
|
106 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
107 |
// Return NO if you do not want the specified item to be editable.
|
|
108 |
return YES;
|
|
109 |
}
|
|
110 |
*/
|
|
111 |
|
|
112 |
|
|
113 |
/*
|
|
114 |
// Override to support editing the table view.
|
|
115 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
116 |
|
|
117 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
118 |
// Delete the row from the data source
|
|
119 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
120 |
}
|
|
121 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
122 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
123 |
}
|
|
124 |
}
|
|
125 |
*/
|
|
126 |
|
|
127 |
|
|
128 |
/*
|
|
129 |
// Override to support rearranging the table view.
|
|
130 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
131 |
}
|
|
132 |
*/
|
|
133 |
|
|
134 |
|
|
135 |
/*
|
|
136 |
// Override to support conditional rearranging of the table view.
|
|
137 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
138 |
// Return NO if you do not want the item to be re-orderable.
|
|
139 |
return YES;
|
|
140 |
}
|
|
141 |
*/
|
|
142 |
|
|
143 |
|
|
144 |
#pragma mark -
|
|
145 |
#pragma mark Table view delegate
|
|
146 |
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
147 |
int newRow = [indexPath row];
|
|
148 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
|
|
149 |
|
|
150 |
if (newRow != oldRow) {
|
3340
|
151 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
|
3339
|
152 |
|
|
153 |
// tell our boss to write this new stuff on disk
|
|
154 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
|
|
155 |
[self.tableView reloadData];
|
|
156 |
|
|
157 |
self.lastIndexPath = indexPath;
|
|
158 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
3340
|
159 |
}
|
3339
|
160 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
161 |
[self.navigationController popViewControllerAnimated:YES];
|
|
162 |
}
|
|
163 |
|
|
164 |
|
|
165 |
#pragma mark -
|
|
166 |
#pragma mark Memory management
|
|
167 |
- (void)didReceiveMemoryWarning {
|
|
168 |
// Releases the view if it doesn't have a superview.
|
|
169 |
[super didReceiveMemoryWarning];
|
|
170 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
171 |
}
|
|
172 |
|
|
173 |
- (void)viewDidUnload {
|
|
174 |
[super viewDidUnload];
|
|
175 |
self.lastIndexPath = nil;
|
|
176 |
self.teamDictionary = nil;
|
|
177 |
self.graveArray = nil;
|
3340
|
178 |
self.graveSprites = nil;
|
3339
|
179 |
}
|
|
180 |
|
|
181 |
- (void)dealloc {
|
3340
|
182 |
[graveSprites release];
|
3339
|
183 |
[graveArray release];
|
|
184 |
[teamDictionary release];
|
|
185 |
[lastIndexPath release];
|
|
186 |
[super dealloc];
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
@end
|
|
191 |
|