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