author | dag10 |
Fri, 01 Mar 2013 17:22:09 -0500 | |
changeset 8623 | 93645b4ba0de |
parent 6908 | 896ed2afcfb8 |
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 "FortsViewController.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:
5982
diff
changeset
|
21 |
|
3547 | 22 |
|
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
23 |
#define IMGNUM_PER_FORT 6 |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
24 |
|
3547 | 25 |
@implementation FortsViewController |
26 |
@synthesize teamDictionary, fortArray, 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 |
NSArray *directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FORTS_DIRECTORY() error:NULL]; |
|
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
40 |
NSMutableArray *filteredContents = [[NSMutableArray alloc] initWithCapacity:([directoryContents count] / IMGNUM_PER_FORT)]; |
3547 | 41 |
// we need to remove the double entries and the L.png suffix |
6908
896ed2afcfb8
ios: turn on more warning messages and start correcting them
koda
parents:
6832
diff
changeset
|
42 |
for (NSUInteger i = 0; i < [directoryContents count]; i++) { |
5982
283be2ca54a7
mad several updates to the resource copying phase in the ios project file, changed paths of some images and added some smaller forts version
koda
parents:
5208
diff
changeset
|
43 |
if (i % IMGNUM_PER_FORT == IMGNUM_PER_FORT-1) { |
3547 | 44 |
NSString *currentName = [directoryContents objectAtIndex:i]; |
45 |
NSString *correctName = [currentName substringToIndex:([currentName length] - 5)]; |
|
46 |
[filteredContents addObject:correctName]; |
|
3697 | 47 |
} |
3547 | 48 |
} |
49 |
self.fortArray = filteredContents; |
|
50 |
[filteredContents release]; |
|
3697 | 51 |
|
3547 | 52 |
// statically set row height instead of using delegate method for performance reasons |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
53 |
self.tableView.rowHeight = 128; |
3697 | 54 |
|
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
|
55 |
self.title = NSLocalizedString(@"Choose team fort",@""); |
3547 | 56 |
} |
57 |
||
58 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
59 |
-(void) viewWillAppear:(BOOL)animated { |
3547 | 60 |
[super viewWillAppear:animated]; |
61 |
[self.tableView reloadData]; |
|
62 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
63 |
} |
|
64 |
||
65 |
||
66 |
#pragma mark - |
|
67 |
#pragma mark Table view data source |
|
68 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
69 |
return 1; |
|
70 |
} |
|
71 |
||
72 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
73 |
return [self.fortArray count]; |
|
74 |
} |
|
75 |
||
76 |
// Customize the appearance of table view cells. |
|
77 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
78 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 79 |
|
3547 | 80 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
81 |
if (cell == nil) |
3547 | 82 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
83 |
reuseIdentifier:CellIdentifier] autorelease]; |
|
3697 | 84 |
|
3547 | 85 |
NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
86 |
cell.textLabel.text = fortName; |
|
3697 | 87 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
88 |
NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@-preview.png", FORTS_DIRECTORY(), fortName]; |
3547 | 89 |
UIImage *fortSprite = [[UIImage alloc] initWithContentsOfFile:fortFile]; |
90 |
[fortFile release]; |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
91 |
cell.imageView.image = fortSprite; |
3547 | 92 |
[fortSprite release]; |
3697 | 93 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
94 |
//cell.detailTextLabel.text = @"Insert funny description here"; |
3547 | 95 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"fort"]]) { |
96 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
97 |
self.lastIndexPath = indexPath; |
|
98 |
} else { |
|
99 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
100 |
} |
|
3697 | 101 |
|
3547 | 102 |
return cell; |
103 |
} |
|
104 |
||
105 |
||
106 |
#pragma mark - |
|
107 |
#pragma mark Table view delegate |
|
108 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
109 |
int newRow = [indexPath row]; |
|
110 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 111 |
|
3547 | 112 |
if (newRow != oldRow) { |
113 |
// if the two selected rows differ update data on the hog dictionary and reload table content |
|
114 |
[self.teamDictionary setValue:[fortArray objectAtIndex:newRow] forKey:@"fort"]; |
|
115 |
||
116 |
// tell our boss to write this new stuff on disk |
|
117 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 118 |
|
3547 | 119 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
120 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
121 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
122 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
123 |
self.lastIndexPath = indexPath; |
|
124 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
125 |
} |
|
126 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
127 |
[self.navigationController popViewControllerAnimated:YES]; |
|
128 |
} |
|
129 |
||
130 |
||
131 |
#pragma mark - |
|
132 |
#pragma mark Memory management |
|
133 |
-(void) didReceiveMemoryWarning { |
|
3971 | 134 |
self.lastIndexPath = nil; |
135 |
MSG_MEMCLEAN(); |
|
3547 | 136 |
[super didReceiveMemoryWarning]; |
137 |
} |
|
138 |
||
139 |
-(void) viewDidUnload { |
|
140 |
self.teamDictionary = nil; |
|
141 |
self.lastIndexPath = nil; |
|
142 |
self.fortArray = 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
|
143 |
MSG_DIDUNLOAD(); |
3547 | 144 |
[super viewDidUnload]; |
145 |
} |
|
146 |
||
147 |
||
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3662
diff
changeset
|
148 |
-(void) dealloc { |
5208 | 149 |
releaseAndNil(teamDictionary); |
150 |
releaseAndNil(lastIndexPath); |
|
151 |
releaseAndNil(fortArray); |
|
3547 | 152 |
[super dealloc]; |
153 |
} |
|
154 |
||
155 |
||
156 |
@end |
|
157 |