author | koda |
Sat, 04 Sep 2010 16:24:00 +0200 | |
changeset 3829 | 81db3c85784b |
parent 3697 | d5b30d6373fc |
child 3880 | 24810907e853 |
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 02/04/2010. |
|
19 |
*/ |
|
20 |
||
3547 | 21 |
|
22 |
#import "LevelViewController.h" |
|
23 |
#import "CommodityFunctions.h" |
|
24 |
||
25 |
||
26 |
@implementation LevelViewController |
|
27 |
@synthesize teamDictionary, levelArray, levelSprites, lastIndexPath; |
|
28 |
||
29 |
||
30 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { |
|
31 |
return rotationManager(interfaceOrientation); |
|
32 |
} |
|
33 |
||
34 |
||
35 |
#pragma mark - |
|
36 |
#pragma mark View lifecycle |
|
37 |
- (void)viewDidLoad { |
|
38 |
[super viewDidLoad]; |
|
39 |
||
40 |
NSArray *array = [[NSArray alloc] initWithObjects: |
|
41 |
NSLocalizedString(@"Human",@""), |
|
42 |
NSLocalizedString(@"Brutal",@""), |
|
43 |
NSLocalizedString(@"Aggressive",@""), |
|
44 |
NSLocalizedString(@"Bully",@""), |
|
45 |
NSLocalizedString(@"Average",@""), |
|
46 |
NSLocalizedString(@"Weaky",@""), |
|
47 |
nil]; |
|
48 |
self.levelArray = array; |
|
49 |
[array release]; |
|
3697 | 50 |
|
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
|
51 |
self.title = NSLocalizedString(@"Set difficulty level",@""); |
3547 | 52 |
} |
53 |
||
54 |
- (void)viewWillAppear:(BOOL)animated { |
|
55 |
[super viewWillAppear:animated]; |
|
56 |
[self.tableView reloadData]; |
|
57 |
// this moves the tableview to the top |
|
58 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO]; |
|
59 |
} |
|
60 |
||
61 |
#pragma mark - |
|
62 |
#pragma mark Table view data source |
|
63 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
64 |
return 1; |
|
65 |
} |
|
66 |
||
67 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
68 |
return [self.levelArray count]; |
|
69 |
} |
|
70 |
||
71 |
// Customize the appearance of table view cells. |
|
72 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
73 |
static NSString *CellIdentifier = @"Cell"; |
|
3697 | 74 |
|
3547 | 75 |
NSInteger row = [indexPath row]; |
76 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
77 |
if (cell == nil) { |
|
78 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
79 |
} |
|
3697 | 80 |
|
3547 | 81 |
cell.textLabel.text = [levelArray objectAtIndex:row]; |
82 |
NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0]; |
|
83 |
if ([[hog objectForKey:@"level"] intValue] == row) { |
|
84 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
85 |
self.lastIndexPath = indexPath; |
|
86 |
} else { |
|
87 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
88 |
} |
|
3697 | 89 |
|
3547 | 90 |
NSString *botlevelPath = [[NSString alloc] initWithFormat:@"%@/%d.png",BOTLEVELS_DIRECTORY(),row]; |
91 |
UIImage *levelImage = [[UIImage alloc] initWithContentsOfFile:botlevelPath]; |
|
92 |
[botlevelPath release]; |
|
93 |
cell.imageView.image = levelImage; |
|
94 |
[levelImage release]; |
|
95 |
||
96 |
return cell; |
|
97 |
} |
|
98 |
||
99 |
||
100 |
/* |
|
101 |
// Override to support conditional editing of the table view. |
|
102 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { |
|
103 |
// Return NO if you do not want the specified item to be editable. |
|
104 |
return YES; |
|
105 |
} |
|
106 |
*/ |
|
107 |
||
108 |
||
109 |
/* |
|
110 |
// Override to support editing the table view. |
|
111 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { |
|
3697 | 112 |
|
3547 | 113 |
if (editingStyle == UITableViewCellEditingStyleDelete) { |
114 |
// Delete the row from the data source |
|
115 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES]; |
|
3697 | 116 |
} |
3547 | 117 |
else if (editingStyle == UITableViewCellEditingStyleInsert) { |
118 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view |
|
3697 | 119 |
} |
3547 | 120 |
} |
121 |
*/ |
|
122 |
||
123 |
||
124 |
/* |
|
125 |
// Override to support rearranging the table view. |
|
126 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { |
|
127 |
} |
|
128 |
*/ |
|
129 |
||
130 |
||
131 |
/* |
|
132 |
// Override to support conditional rearranging of the table view. |
|
133 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { |
|
134 |
// Return NO if you do not want the item to be re-orderable. |
|
135 |
return YES; |
|
136 |
} |
|
137 |
*/ |
|
138 |
||
139 |
||
140 |
#pragma mark - |
|
141 |
#pragma mark Table view delegate |
|
142 |
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
143 |
int newRow = [indexPath row]; |
|
144 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
3697 | 145 |
|
3547 | 146 |
if (newRow != oldRow) { |
147 |
NSMutableArray *hogs = [teamDictionary objectForKey:@"hedgehogs"]; |
|
3697 | 148 |
|
3547 | 149 |
for (NSMutableDictionary *hog in hogs) { |
150 |
[hog setObject:[NSNumber numberWithInt:newRow] forKey:@"level"]; |
|
151 |
} |
|
3697 | 152 |
|
3547 | 153 |
// tell our boss to write this new stuff on disk |
154 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil]; |
|
155 |
[self.tableView reloadData]; |
|
3697 | 156 |
|
3547 | 157 |
self.lastIndexPath = indexPath; |
158 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
159 |
} |
|
160 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
161 |
[self.navigationController popViewControllerAnimated:YES]; |
|
162 |
} |
|
163 |
||
164 |
||
165 |
#pragma mark - |
|
166 |
#pragma mark Memory management |
|
167 |
-(void) didReceiveMemoryWarning { |
|
168 |
// Releases the view if it doesn't have a superview. |
|
169 |
[super didReceiveMemoryWarning]; |
|
170 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
171 |
} |
|
172 |
||
173 |
-(void) viewDidUnload { |
|
174 |
self.lastIndexPath = nil; |
|
175 |
self.teamDictionary = nil; |
|
176 |
self.levelArray = nil; |
|
177 |
self.levelSprites = 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
|
178 |
MSG_DIDUNLOAD(); |
3547 | 179 |
[super viewDidUnload]; |
180 |
} |
|
181 |
||
182 |
-(void) dealloc { |
|
183 |
[levelArray release]; |
|
184 |
[levelSprites release]; |
|
185 |
[teamDictionary release]; |
|
186 |
[lastIndexPath release]; |
|
187 |
[super dealloc]; |
|
188 |
} |
|
189 |
||
190 |
||
191 |
@end |
|
192 |