author | nemo |
Thu, 18 Oct 2012 14:04:24 -0400 | |
changeset 7767 | d1ea9b3f543e |
parent 6832 | fae8fd118da9 |
child 10108 | c68cf030eded |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
6700 | 3 |
* Copyright (c) 2009-2012 Vittorio Giovara <vittorio.giovara@gmail.com> |
3829 | 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 |
||
3547 | 19 |
|
20 |
#import "GravesViewController.h" |
|
6078
8c0cc07731e5
headers cleanup, converted some function-only sources into proper class method files, more use of OOP power, removed some 'respondsToSelector' calls, moved defines into their own header, more use of objc categories
koda
parents:
5208
diff
changeset
|
21 |
|
3547 | 22 |
|
23 |
@implementation GravesViewController |
|
24 |
@synthesize teamDictionary, graveArray, lastIndexPath; |
|
25 |
||
26 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
27 |
return rotationManager(interfaceOrientation); |
|
28 |
} |
|
29 |
||
30 |
#pragma mark - |
|
31 |
#pragma mark View lifecycle |
|
32 |
-(void) viewDidLoad { |
|
33 |
[super viewDidLoad]; |
|
34 |
||
35 |
// load all the grave names and store them into graveArray |
|
36 |
self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL]; |
|
3697 | 37 |
|
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
|
38 |
self.title = NSLocalizedString(@"Choose hedgehog graves",@""); |
3547 | 39 |
} |
40 |
||
41 |
-(void) viewWillAppear:(BOOL)animated { |
|
42 |
[super viewWillAppear:animated]; |
|
43 |
[self.tableView reloadData]; |
|
44 |
// this moves the tableview to the top |
|
45 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
46 |
} |
|
47 |
||
48 |
||
49 |
#pragma mark - |
|
50 |
#pragma mark Table view data source |
|
51 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
52 |
return 1; |
|
53 |
} |
|
54 |
||
55 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
56 |
return [self.graveArray count]; |
|
57 |
} |
|
58 |
||
59 |
// Customize the appearance of table view cells. |
|
60 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
61 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 62 |
|
3547 | 63 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
64 |
if (cell == nil) |
|
65 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
3697 | 66 |
|
3547 | 67 |
NSString *grave = [self.graveArray objectAtIndex:[indexPath row]]; |
68 |
cell.textLabel.text = [grave stringByDeletingPathExtension]; |
|
3697 | 69 |
|
3547 | 70 |
if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) { |
71 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
72 |
self.lastIndexPath = indexPath; |
|
73 |
} else { |
|
74 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
75 |
} |
|
76 |
||
77 |
NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave]; |
|
78 |
// because we also have multi frame graves, let's take the first one only |
|
79 |
UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)]; |
|
3697 | 80 |
[graveFilePath release]; |
3547 | 81 |
cell.imageView.image = graveSprite; |
82 |
[graveSprite release]; |
|
3697 | 83 |
|
3547 | 84 |
return cell; |
85 |
} |
|
86 |
||
87 |
||
88 |
#pragma mark - |
|
89 |
#pragma mark Table view delegate |
|
90 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
91 |
int newRow = [indexPath row]; |
|
92 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 93 |
|
3547 | 94 |
if (newRow != oldRow) { |
95 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
|
3697 | 96 |
|
3547 | 97 |
// tell our boss to write this new stuff on disk |
98 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 99 |
|
3547 | 100 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
101 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
102 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
103 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
104 |
self.lastIndexPath = indexPath; |
|
105 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
106 |
} |
|
107 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
108 |
[self.navigationController popViewControllerAnimated:YES]; |
|
109 |
} |
|
110 |
||
111 |
||
112 |
#pragma mark - |
|
113 |
#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
|
114 |
-(void) didReceiveMemoryWarning { |
3971 | 115 |
self.lastIndexPath = nil; |
116 |
MSG_MEMCLEAN(); |
|
3547 | 117 |
[super didReceiveMemoryWarning]; |
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) viewDidUnload { |
3547 | 121 |
self.lastIndexPath = nil; |
122 |
self.teamDictionary = nil; |
|
123 |
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
|
124 |
MSG_DIDUNLOAD(); |
3547 | 125 |
[super viewDidUnload]; |
126 |
} |
|
127 |
||
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
|
128 |
-(void) dealloc { |
5208 | 129 |
releaseAndNil(graveArray); |
130 |
releaseAndNil(teamDictionary); |
|
131 |
releaseAndNil(lastIndexPath); |
|
3547 | 132 |
[super dealloc]; |
133 |
} |
|
134 |
||
135 |
||
136 |
@end |
|
137 |