author | koda |
Sat, 02 Oct 2010 04:23:32 +0200 | |
changeset 3922 | 44804043b691 |
parent 3829 | 81db3c85784b |
child 3950 | 296cbdd85e50 |
permissions | -rw-r--r-- |
3829 | 1 |
/* |
2 |
* Hedgewars-iOS, a Hedgewars port for iOS devices |
|
3 |
* Copyright (c) 2009-2010 Vittorio Giovara <vittorio.giovara@gmail.com> |
|
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 08/04/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "FlagsViewController.h" |
|
23 |
#import "CommodityFunctions.h" |
|
24 |
||
25 |
@implementation FlagsViewController |
|
26 |
@synthesize teamDictionary, flagArray, 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 |
self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL]; |
|
3697 | 40 |
|
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
|
41 |
self.title = NSLocalizedString(@"Set team flag",@""); |
3547 | 42 |
} |
43 |
||
44 |
-(void) viewWillAppear:(BOOL)animated { |
|
45 |
[super viewWillAppear:animated]; |
|
46 |
[self.tableView reloadData]; |
|
47 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
48 |
} |
|
49 |
||
50 |
||
51 |
#pragma mark - |
|
52 |
#pragma mark Table view data source |
|
53 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
54 |
return 1; |
|
55 |
} |
|
56 |
||
57 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
58 |
return [flagArray count]; |
|
59 |
} |
|
60 |
||
61 |
// Customize the appearance of table view cells. |
|
62 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3697 | 63 |
|
3547 | 64 |
static NSString *CellIdentifier = @"Cell"; |
3697 | 65 |
|
3547 | 66 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
67 |
if (cell == nil) { |
|
68 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
69 |
} |
|
3697 | 70 |
|
3547 | 71 |
NSString *flag = [flagArray objectAtIndex:[indexPath row]]; |
3697 | 72 |
|
3547 | 73 |
NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flag]; |
74 |
UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile]; |
|
75 |
[flagFile release]; |
|
76 |
cell.imageView.image = flagSprite; |
|
77 |
[flagSprite release]; |
|
3697 | 78 |
|
3547 | 79 |
cell.textLabel.text = [flag stringByDeletingPathExtension]; |
80 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) { |
|
81 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
82 |
self.lastIndexPath = indexPath; |
|
83 |
} else { |
|
84 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
85 |
} |
|
3697 | 86 |
|
3547 | 87 |
return cell; |
88 |
} |
|
89 |
||
90 |
||
91 |
#pragma mark - |
|
92 |
#pragma mark Table view delegate |
|
93 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
94 |
int newRow = [indexPath row]; |
|
95 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 96 |
|
3547 | 97 |
if (newRow != oldRow) { |
98 |
// if the two selected rows differ update data on the hog dictionary and reload table content |
|
99 |
[self.teamDictionary setValue:[[flagArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"flag"]; |
|
100 |
||
101 |
// tell our boss to write this new stuff on disk |
|
102 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
103 |
||
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 |
|
118 |
-(void) didReceiveMemoryWarning { |
|
119 |
// Releases the view if it doesn't have a superview. |
|
120 |
[super didReceiveMemoryWarning]; |
|
121 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
122 |
} |
|
123 |
||
124 |
-(void) viewDidUnload { |
|
125 |
self.teamDictionary = nil; |
|
126 |
self.lastIndexPath = nil; |
|
127 |
self.flagArray = 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 |
||
132 |
-(void) dealloc { |
|
133 |
[teamDictionary release]; |
|
134 |
[lastIndexPath release]; |
|
135 |
[flagArray release]; |
|
136 |
[super dealloc]; |
|
137 |
} |
|
138 |
||
139 |
||
140 |
@end |
|
141 |