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:
6832
diff
changeset
|
16 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3829 | 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 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
26 |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
3547 | 27 |
return rotationManager(interfaceOrientation); |
28 |
} |
|
29 |
||
30 |
#pragma mark - |
|
31 |
#pragma mark View lifecycle |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
32 |
- (void)viewDidLoad { |
3547 | 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 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
41 |
- (void)viewWillAppear:(BOOL)animated { |
3547 | 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 |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
51 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { |
3547 | 52 |
return 1; |
53 |
} |
|
54 |
||
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
55 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
3547 | 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) |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
65 |
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; |
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)]; |
|
80 |
cell.imageView.image = graveSprite; |
|
3697 | 81 |
|
3547 | 82 |
return cell; |
83 |
} |
|
84 |
||
85 |
||
86 |
#pragma mark - |
|
87 |
#pragma mark Table view delegate |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
88 |
- (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
|
89 |
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
|
90 |
NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
3697 | 91 |
|
3547 | 92 |
if (newRow != oldRow) { |
93 |
[teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"]; |
|
3697 | 94 |
|
3547 | 95 |
// tell our boss to write this new stuff on disk |
96 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
3697 | 97 |
|
3547 | 98 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
99 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
100 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
101 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
102 |
self.lastIndexPath = indexPath; |
|
103 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
104 |
} |
|
105 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
106 |
[self.navigationController popViewControllerAnimated:YES]; |
|
107 |
} |
|
108 |
||
109 |
||
110 |
#pragma mark - |
|
111 |
#pragma mark Memory management |
|
12872
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
112 |
|
00215a7ec5f5
- BIG CHANGE: Convert iOS project to use ARC
antonc27 <antonc27@mail.ru>
parents:
11148
diff
changeset
|
113 |
- (void)didReceiveMemoryWarning { |
3971 | 114 |
self.lastIndexPath = nil; |
115 |
MSG_MEMCLEAN(); |
|
3547 | 116 |
[super didReceiveMemoryWarning]; |
117 |
} |
|
118 |
||
119 |
@end |
|
120 |