author | Wuzzy <almikes@aol.com> |
Tue, 02 May 2017 21:16:07 +0200 | |
changeset 12390 | c051ac2544f2 |
parent 11184 | e03bb95edf44 |
child 12872 | 00215a7ec5f5 |
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 |
|
10108
c68cf030eded
update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents:
6908
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 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)]; |
11184
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
41 |
// we assume here that fort's images has one image with the 'L.png' suffix and we remove this suffix to get the correct name |
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
42 |
for (NSUInteger i = 0; i < [directoryContents count]; i++) |
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
43 |
{ |
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
44 |
NSString *currentName = [directoryContents objectAtIndex:i]; |
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
45 |
if ([currentName rangeOfString:@"L.png"].location != NSNotFound) |
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
46 |
{ |
e03bb95edf44
- Fix for getting the correct fort name in FortsViewController
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
47 |
NSString *correctName = [currentName stringByReplacingOccurrencesOfString:@"L.png" withString:@""]; |
3547 | 48 |
[filteredContents addObject:correctName]; |
3697 | 49 |
} |
3547 | 50 |
} |
51 |
self.fortArray = filteredContents; |
|
52 |
[filteredContents release]; |
|
3697 | 53 |
|
3547 | 54 |
// 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
|
55 |
self.tableView.rowHeight = 128; |
3697 | 56 |
|
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
|
57 |
self.title = NSLocalizedString(@"Choose team fort",@""); |
3547 | 58 |
} |
59 |
||
60 |
||
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
61 |
-(void) viewWillAppear:(BOOL)animated { |
3547 | 62 |
[super viewWillAppear:animated]; |
63 |
[self.tableView reloadData]; |
|
64 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
65 |
} |
|
66 |
||
67 |
||
68 |
#pragma mark - |
|
69 |
#pragma mark Table view data source |
|
70 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
71 |
return 1; |
|
72 |
} |
|
73 |
||
74 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
75 |
return [self.fortArray count]; |
|
76 |
} |
|
77 |
||
78 |
// Customize the appearance of table view cells. |
|
79 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
80 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 81 |
|
3547 | 82 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
83 |
if (cell == nil) |
3547 | 84 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
85 |
reuseIdentifier:CellIdentifier] autorelease]; |
|
3697 | 86 |
|
3547 | 87 |
NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
88 |
cell.textLabel.text = fortName; |
|
3697 | 89 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
90 |
NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@-preview.png", FORTS_DIRECTORY(), fortName]; |
3547 | 91 |
UIImage *fortSprite = [[UIImage alloc] initWithContentsOfFile:fortFile]; |
92 |
[fortFile release]; |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
93 |
cell.imageView.image = fortSprite; |
3547 | 94 |
[fortSprite release]; |
3697 | 95 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
96 |
//cell.detailTextLabel.text = @"Insert funny description here"; |
3547 | 97 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"fort"]]) { |
98 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
99 |
self.lastIndexPath = indexPath; |
|
100 |
} else { |
|
101 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
102 |
} |
|
3697 | 103 |
|
3547 | 104 |
return cell; |
105 |
} |
|
106 |
||
107 |
||
108 |
#pragma mark - |
|
109 |
#pragma mark Table view delegate |
|
110 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
11148
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
111 |
NSInteger newRow = [indexPath row]; |
064a53861759
- Refactoring in order to remove some warning related to using of int instead of NSInteger
antonc27 <antonc27@mail.ru>
parents:
10108
diff
changeset
|
112 |
NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
3697 | 113 |
|
3547 | 114 |
if (newRow != oldRow) { |
115 |
// if the two selected rows differ update data on the hog dictionary and reload table content |
|
116 |
[self.teamDictionary setValue:[fortArray objectAtIndex:newRow] forKey:@"fort"]; |
|
117 |
||
118 |
// tell our boss to write this new stuff on disk |
|
119 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 120 |
|
3547 | 121 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
122 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
123 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
124 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
125 |
self.lastIndexPath = indexPath; |
|
126 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
127 |
} |
|
128 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
129 |
[self.navigationController popViewControllerAnimated:YES]; |
|
130 |
} |
|
131 |
||
132 |
||
133 |
#pragma mark - |
|
134 |
#pragma mark Memory management |
|
135 |
-(void) didReceiveMemoryWarning { |
|
3971 | 136 |
self.lastIndexPath = nil; |
137 |
MSG_MEMCLEAN(); |
|
3547 | 138 |
[super didReceiveMemoryWarning]; |
139 |
} |
|
140 |
||
141 |
-(void) viewDidUnload { |
|
142 |
self.teamDictionary = nil; |
|
143 |
self.lastIndexPath = nil; |
|
144 |
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
|
145 |
MSG_DIDUNLOAD(); |
3547 | 146 |
[super viewDidUnload]; |
147 |
} |
|
148 |
||
149 |
||
3663
8c28abf427f5
reduce the number of keywords used and switch to BMP format for screenshots
koda
parents:
3662
diff
changeset
|
150 |
-(void) dealloc { |
5208 | 151 |
releaseAndNil(teamDictionary); |
152 |
releaseAndNil(lastIndexPath); |
|
153 |
releaseAndNil(fortArray); |
|
3547 | 154 |
[super dealloc]; |
155 |
} |
|
156 |
||
157 |
||
158 |
@end |
|
159 |