author | smaxx |
Wed, 04 Aug 2010 17:35:45 +0200 | |
changeset 3724 | b8678667e7dc |
parent 3697 | d5b30d6373fc |
child 3829 | 81db3c85784b |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// GravesViewController.m |
|
3 |
// HedgewarsMobile |
|
4 |
// |
|
5 |
// Created by Vittorio on 02/04/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "GravesViewController.h" |
|
10 |
#import "CommodityFunctions.h" |
|
11 |
#import "UIImageExtra.h" |
|
12 |
||
13 |
@implementation GravesViewController |
|
14 |
@synthesize teamDictionary, graveArray, 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 grave names and store them into graveArray |
|
28 |
self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; |
|
3697 | 29 |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
30 |
self.title = NSLocalizedString(@"Choose hedgehog graves",@""); |
3547 | 31 |
} |
32 |
||
33 |
-(void) viewWillAppear:(BOOL)animated { |
|
34 |
[super viewWillAppear:animated]; |
|
35 |
[self.tableView reloadData]; |
|
36 |
// this moves the tableview to the top |
|
37 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
38 |
} |
|
39 |
||
40 |
||
41 |
#pragma mark - |
|
42 |
#pragma mark Table view data source |
|
43 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
44 |
return 1; |
|
45 |
} |
|
46 |
||
47 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
48 |
return [self.graveArray count]; |
|
49 |
} |
|
50 |
||
51 |
// Customize the appearance of table view cells. |
|
52 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
53 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 54 |
|
3547 | 55 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
56 |
if (cell == nil) |
|
57 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
3697 | 58 |
|
3547 | 59 |
NSString *grave = [self.graveArray objectAtIndex:[indexPath row]]; |
60 |
cell.textLabel.text = [grave stringByDeletingPathExtension]; |
|
3697 | 61 |
|
3547 | 62 |
if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) { |
63 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
64 |
self.lastIndexPath = indexPath; |
|
65 |
} else { |
|
66 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
67 |
} |
|
68 |
||
69 |
NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave]; |
|
70 |
// because we also have multi frame graves, let's take the first one only |
|
71 |
UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)]; |
|
3697 | 72 |
[graveFilePath release]; |
3547 | 73 |
cell.imageView.image = graveSprite; |
74 |
[graveSprite release]; |
|
3697 | 75 |
|
3547 | 76 |
return cell; |
77 |
} |
|
78 |
||
79 |
||
80 |
#pragma mark - |
|
81 |
#pragma mark Table view delegate |
|
82 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
83 |
int newRow = [indexPath row]; |
|
84 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 85 |
|
3547 | 86 |
if (newRow != oldRow) { |
87 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
|
3697 | 88 |
|
3547 | 89 |
// tell our boss to write this new stuff on disk |
90 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 91 |
|
3547 | 92 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
93 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
94 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
95 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
96 |
self.lastIndexPath = indexPath; |
|
97 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
98 |
} |
|
99 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
100 |
[self.navigationController popViewControllerAnimated:YES]; |
|
101 |
} |
|
102 |
||
103 |
||
104 |
#pragma mark - |
|
105 |
#pragma mark Memory management |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
106 |
-(void) didReceiveMemoryWarning { |
3547 | 107 |
// Releases the view if it doesn't have a superview. |
108 |
[super didReceiveMemoryWarning]; |
|
109 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
110 |
} |
|
111 |
||
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
112 |
-(void) viewDidUnload { |
3547 | 113 |
self.lastIndexPath = nil; |
114 |
self.teamDictionary = nil; |
|
115 |
self.graveArray = nil; |
|
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
116 |
MSG_DIDUNLOAD(); |
3547 | 117 |
[super viewDidUnload]; |
118 |
} |
|
119 |
||
3662
a44406f4369b
polish polish polish polish (also: panning horizontal fix, panning momentum, settings page reworked yet again, memory leaks, crashes, segfaults)
koda
parents:
3547
diff
changeset
|
120 |
-(void) dealloc { |
3547 | 121 |
[graveArray release]; |
122 |
[teamDictionary release]; |
|
123 |
[lastIndexPath release]; |
|
124 |
[super dealloc]; |
|
125 |
} |
|
126 |
||
127 |
||
128 |
@end |
|
129 |