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