author | sheepluva |
Tue, 22 Jun 2021 22:13:55 +0200 | |
changeset 15802 | d5c37e78ab83 |
parent 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 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
29 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3547 | 30 |
return rotationManager(interfaceOrientation); |
31 |
} |
|
32 |
||
33 |
||
34 |
#pragma mark - |
|
35 |
#pragma mark View lifecycle |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
36 |
- (void)viewDidLoad { |
3547 | 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; |
|
3697 | 52 |
|
3547 | 53 |
// 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
|
54 |
self.tableView.rowHeight = 128; |
3697 | 55 |
|
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
|
56 |
self.title = NSLocalizedString(@"Choose team fort",@""); |
3547 | 57 |
} |
58 |
||
59 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
60 |
- (void)viewWillAppear:(BOOL)animated { |
3547 | 61 |
[super viewWillAppear:animated]; |
62 |
[self.tableView reloadData]; |
|
63 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
64 |
} |
|
65 |
||
66 |
||
67 |
#pragma mark - |
|
68 |
#pragma mark Table view data source |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
69 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3547 | 70 |
return 1; |
71 |
} |
|
72 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
73 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3547 | 74 |
return [self.fortArray count]; |
75 |
} |
|
76 |
||
77 |
// Customize the appearance of table view cells. |
|
78 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
79 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 80 |
|
3547 | 81 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
4476
4bf74e158f44
team selection completely refactored, now has animation and more performance
koda
parents:
3971
diff
changeset
|
82 |
if (cell == nil) |
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
83 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle |
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
84 |
reuseIdentifier:CellIdentifier]; |
3697 | 85 |
|
3547 | 86 |
NSString *fortName = [fortArray objectAtIndex:[indexPath row]]; |
87 |
cell.textLabel.text = fortName; |
|
3697 | 88 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
89 |
NSString *fortFile = [[NSString alloc] initWithFormat:@"%@/%@-preview.png", FORTS_DIRECTORY(), fortName]; |
3547 | 90 |
UIImage *fortSprite = [[UIImage alloc] initWithContentsOfFile:fortFile]; |
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
91 |
cell.imageView.image = fortSprite; |
3697 | 92 |
|
3789
c3eb56754e92
added a smaller version of forts, fixed a couple of regressions
koda
parents:
3697
diff
changeset
|
93 |
//cell.detailTextLabel.text = @"Insert funny description here"; |
3547 | 94 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"fort"]]) { |
95 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
96 |
self.lastIndexPath = indexPath; |
|
97 |
} else { |
|
98 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
99 |
} |
|
3697 | 100 |
|
3547 | 101 |
return cell; |
102 |
} |
|
103 |
||
104 |
||
105 |
#pragma mark - |
|
106 |
#pragma mark Table view delegate |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
107 |
- (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
|
108 |
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
|
109 |
NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
3697 | 110 |
|
3547 | 111 |
if (newRow != oldRow) { |
112 |
// if the two selected rows differ update data on the hog dictionary and reload table content |
|
113 |
[self.teamDictionary setValue:[fortArray objectAtIndex:newRow] forKey:@"fort"]; |
|
114 |
||
115 |
// tell our boss to write this new stuff on disk |
|
116 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 117 |
|
3547 | 118 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
119 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
120 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
121 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
122 |
self.lastIndexPath = indexPath; |
|
123 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
124 |
} |
|
125 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
126 |
[self.navigationController popViewControllerAnimated:YES]; |
|
127 |
} |
|
128 |
||
129 |
||
130 |
#pragma mark - |
|
131 |
#pragma mark Memory management |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
132 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11184
diff
changeset
|
133 |
- (void)didReceiveMemoryWarning { |
3971 | 134 |
self.lastIndexPath = nil; |
135 |
MSG_MEMCLEAN(); |
|
3547 | 136 |
[super didReceiveMemoryWarning]; |
137 |
} |
|
138 |
||
139 |
@end |
|
140 |