3270
|
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 |
|
|
11 |
|
|
12 |
@implementation HogHatViewController
|
|
13 |
@synthesize hatList, hog;
|
|
14 |
|
|
15 |
#pragma mark -
|
|
16 |
#pragma mark View lifecycle
|
|
17 |
|
|
18 |
|
|
19 |
- (void)viewDidLoad {
|
|
20 |
[super viewDidLoad];
|
|
21 |
|
|
22 |
//NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
23 |
NSString *hatPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"];
|
|
24 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatPath
|
|
25 |
error:NULL];
|
|
26 |
self.hatList = array;
|
|
27 |
//NSLog(@"%@", hatList);
|
|
28 |
}
|
|
29 |
|
|
30 |
- (void)viewWillAppear:(BOOL)animated {
|
|
31 |
[super viewWillAppear:animated];
|
|
32 |
self.title = [hog objectForKey:@"hogname"];
|
|
33 |
[self.tableView reloadData];
|
|
34 |
}
|
|
35 |
|
|
36 |
/*
|
|
37 |
- (void)viewDidAppear:(BOOL)animated {
|
|
38 |
[super viewDidAppear:animated];
|
|
39 |
}
|
|
40 |
*/
|
|
41 |
/*
|
|
42 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
43 |
[super viewWillDisappear:animated];
|
|
44 |
}
|
|
45 |
*/
|
|
46 |
/*
|
|
47 |
- (void)viewDidDisappear:(BOOL)animated {
|
|
48 |
[super viewDidDisappear:animated];
|
|
49 |
}
|
|
50 |
*/
|
|
51 |
|
|
52 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
53 |
// Override to allow orientations other than the default portrait orientation.
|
|
54 |
return YES;
|
|
55 |
}
|
|
56 |
|
|
57 |
|
|
58 |
#pragma mark -
|
|
59 |
#pragma mark Table view data source
|
|
60 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
|
|
61 |
return 2;
|
|
62 |
}
|
|
63 |
|
|
64 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
65 |
NSInteger rows;
|
|
66 |
if (0 == section)
|
|
67 |
rows = 1;
|
|
68 |
else
|
|
69 |
rows = [self.hatList count];
|
|
70 |
return rows;
|
|
71 |
}
|
|
72 |
|
|
73 |
// Customize the appearance of table view cells.
|
|
74 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
75 |
|
|
76 |
static NSString *CellIdentifier = @"Cell";
|
|
77 |
|
|
78 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
79 |
if (cell == nil) {
|
|
80 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
81 |
}
|
|
82 |
|
3276
|
83 |
if (0 == [indexPath section]) {
|
3270
|
84 |
cell.textLabel.text = [hog objectForKey:@"hogname"];
|
3276
|
85 |
cell.imageView.image = nil;
|
|
86 |
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
87 |
} else {
|
3270
|
88 |
cell.textLabel.text = [[hatList objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
|
3276
|
89 |
if ([cell.textLabel.text isEqualToString:[hog objectForKey:@"hat"]]) {
|
|
90 |
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
91 |
} else {
|
|
92 |
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
93 |
}
|
|
94 |
|
|
95 |
NSString *hatsPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"];
|
|
96 |
NSString *hatFile = [hatsPath stringByAppendingString:[hatList objectAtIndex:[indexPath row]]];
|
|
97 |
UIImage *image = [UIImage imageWithContentsOfFile: hatFile];
|
|
98 |
|
|
99 |
CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
|
|
100 |
CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
|
|
101 |
cell.imageView.image = [UIImage imageWithCGImage: cgImgage];
|
|
102 |
CGImageRelease(cgImgage);
|
|
103 |
}
|
3270
|
104 |
|
|
105 |
return cell;
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
/*
|
|
110 |
// Override to support conditional editing of the table view.
|
|
111 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
112 |
// Return NO if you do not want the specified item to be editable.
|
|
113 |
return YES;
|
|
114 |
}
|
|
115 |
*/
|
|
116 |
|
|
117 |
|
|
118 |
/*
|
|
119 |
// Override to support editing the table view.
|
|
120 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
121 |
|
|
122 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
123 |
// Delete the row from the data source
|
|
124 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
125 |
}
|
|
126 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
127 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
128 |
}
|
|
129 |
}
|
|
130 |
*/
|
|
131 |
|
|
132 |
|
|
133 |
/*
|
|
134 |
// Override to support rearranging the table view.
|
|
135 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
136 |
}
|
|
137 |
*/
|
|
138 |
|
|
139 |
|
|
140 |
/*
|
|
141 |
// Override to support conditional rearranging of the table view.
|
|
142 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
143 |
// Return NO if you do not want the item to be re-orderable.
|
|
144 |
return YES;
|
|
145 |
}
|
|
146 |
*/
|
|
147 |
|
|
148 |
|
|
149 |
#pragma mark -
|
|
150 |
#pragma mark Table view delegate
|
|
151 |
|
|
152 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
153 |
// Navigation logic may go here. Create and push another view controller.
|
|
154 |
/*
|
|
155 |
<#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
|
|
156 |
// ...
|
|
157 |
// Pass the selected object to the new view controller.
|
|
158 |
[self.navigationController pushViewController:detailViewController animated:YES];
|
|
159 |
[detailViewController release];
|
|
160 |
*/
|
|
161 |
}
|
|
162 |
|
|
163 |
|
|
164 |
#pragma mark -
|
|
165 |
#pragma mark Memory management
|
|
166 |
|
|
167 |
- (void)didReceiveMemoryWarning {
|
|
168 |
// Releases the view if it doesn't have a superview.
|
|
169 |
[super didReceiveMemoryWarning];
|
|
170 |
|
|
171 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
172 |
}
|
|
173 |
|
|
174 |
- (void)viewDidUnload {
|
|
175 |
[super viewDidUnload];
|
|
176 |
self.hatList = nil;
|
|
177 |
self.hog = nil;
|
|
178 |
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
|
|
179 |
// For example: self.myOutlet = nil;
|
|
180 |
}
|
|
181 |
|
|
182 |
|
|
183 |
- (void)dealloc {
|
|
184 |
[hog release];
|
|
185 |
[hatList release];
|
|
186 |
[super dealloc];
|
|
187 |
}
|
|
188 |
|
|
189 |
|
|
190 |
@end
|
|
191 |
|