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