author | nemo |
Tue, 07 Dec 2010 17:29:02 -0500 | |
changeset 4479 | 59e11a5a3bfa |
parent 3971 | 5c82ee165ed5 |
child 4976 | 088d40d8aba2 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
17 |
* |
|
18 |
* File created on 02/04/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "GravesViewController.h" |
|
23 |
#import "CommodityFunctions.h" |
|
24 |
#import "UIImageExtra.h" |
|
25 |
||
26 |
@implementation GravesViewController |
|
27 |
@synthesize teamDictionary, graveArray, lastIndexPath; |
|
28 |
||
29 |
||
30 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
31 |
return rotationManager(interfaceOrientation); |
|
32 |
} |
|
33 |
||
34 |
||
35 |
#pragma mark - |
|
36 |
#pragma mark View lifecycle |
|
37 |
-(void) viewDidLoad { |
|
38 |
[super viewDidLoad]; |
|
39 |
||
40 |
// load all the grave names and store them into graveArray |
|
41 |
self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; |
|
3697 | 42 |
|
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
|
43 |
self.title = NSLocalizedString(@"Choose hedgehog graves",@""); |
3547 | 44 |
} |
45 |
||
46 |
-(void) viewWillAppear:(BOOL)animated { |
|
47 |
[super viewWillAppear:animated]; |
|
48 |
[self.tableView reloadData]; |
|
49 |
// this moves the tableview to the top |
|
50 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
51 |
} |
|
52 |
||
53 |
||
54 |
#pragma mark - |
|
55 |
#pragma mark Table view data source |
|
56 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
57 |
return 1; |
|
58 |
} |
|
59 |
||
60 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
61 |
return [self.graveArray count]; |
|
62 |
} |
|
63 |
||
64 |
// Customize the appearance of table view cells. |
|
65 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
66 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 67 |
|
3547 | 68 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
69 |
if (cell == nil) |
|
70 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
3697 | 71 |
|
3547 | 72 |
NSString *grave = [self.graveArray objectAtIndex:[indexPath row]]; |
73 |
cell.textLabel.text = [grave stringByDeletingPathExtension]; |
|
3697 | 74 |
|
3547 | 75 |
if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) { |
76 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
77 |
self.lastIndexPath = indexPath; |
|
78 |
} else { |
|
79 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
80 |
} |
|
81 |
||
82 |
NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave]; |
|
83 |
// because we also have multi frame graves, let's take the first one only |
|
84 |
UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)]; |
|
3697 | 85 |
[graveFilePath release]; |
3547 | 86 |
cell.imageView.image = graveSprite; |
87 |
[graveSprite release]; |
|
3697 | 88 |
|
3547 | 89 |
return cell; |
90 |
} |
|
91 |
||
92 |
||
93 |
#pragma mark - |
|
94 |
#pragma mark Table view delegate |
|
95 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
96 |
int newRow = [indexPath row]; |
|
97 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 98 |
|
3547 | 99 |
if (newRow != oldRow) { |
100 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
|
3697 | 101 |
|
3547 | 102 |
// tell our boss to write this new stuff on disk |
103 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 104 |
|
3547 | 105 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
106 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
107 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
108 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
109 |
self.lastIndexPath = indexPath; |
|
110 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
111 |
} |
|
112 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
113 |
[self.navigationController popViewControllerAnimated:YES]; |
|
114 |
} |
|
115 |
||
116 |
||
117 |
#pragma mark - |
|
118 |
#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
|
119 |
-(void) didReceiveMemoryWarning { |
3971 | 120 |
self.lastIndexPath = nil; |
121 |
MSG_MEMCLEAN(); |
|
3547 | 122 |
[super didReceiveMemoryWarning]; |
123 |
} |
|
124 |
||
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
|
125 |
-(void) viewDidUnload { |
3547 | 126 |
self.lastIndexPath = nil; |
127 |
self.teamDictionary = nil; |
|
128 |
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
|
129 |
MSG_DIDUNLOAD(); |
3547 | 130 |
[super viewDidUnload]; |
131 |
} |
|
132 |
||
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
|
133 |
-(void) dealloc { |
3547 | 134 |
[graveArray release]; |
135 |
[teamDictionary release]; |
|
136 |
[lastIndexPath release]; |
|
137 |
[super dealloc]; |
|
138 |
} |
|
139 |
||
140 |
||
141 |
@end |
|
142 |