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];
|
|
37 |
}
|
|
38 |
|
|
39 |
- (void)viewWillAppear:(BOOL)animated {
|
|
40 |
[super viewWillAppear:animated];
|
|
41 |
[self.tableView reloadData];
|
|
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.
|
|
57 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
58 |
static NSString *CellIdentifier = @"Cell";
|
|
59 |
|
|
60 |
NSInteger row = [indexPath row];
|
|
61 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
62 |
if (cell == nil) {
|
|
63 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
64 |
}
|
|
65 |
|
|
66 |
cell.textLabel.text = [levelArray objectAtIndex:row];
|
|
67 |
NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0];
|
|
68 |
if ([[hog objectForKey:@"level"] intValue] == row) {
|
|
69 |
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
70 |
self.lastIndexPath = indexPath;
|
|
71 |
} else {
|
|
72 |
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
73 |
}
|
|
74 |
|
|
75 |
NSString *botlevelPath = [[NSString alloc] initWithFormat:@"%@/%d.png",BOTLEVELS_DIRECTORY(),row];
|
|
76 |
UIImage *levelImage = [[UIImage alloc] initWithContentsOfFile:botlevelPath];
|
|
77 |
[botlevelPath release];
|
|
78 |
cell.imageView.image = levelImage;
|
|
79 |
[levelImage release];
|
|
80 |
|
|
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) {
|
|
132 |
NSMutableArray *hogs = [teamDictionary objectForKey:@"hedgehogs"];
|
|
133 |
|
|
134 |
for (NSMutableDictionary *hog in hogs) {
|
|
135 |
[hog setObject:[NSNumber numberWithInt:newRow] forKey:@"level"];
|
|
136 |
}
|
|
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];
|
|
144 |
}
|
|
145 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
146 |
[self.navigationController popViewControllerAnimated:YES];
|
|
147 |
}
|
|
148 |
|
|
149 |
|
|
150 |
#pragma mark -
|
|
151 |
#pragma mark Memory management
|
|
152 |
-(void) didReceiveMemoryWarning {
|
|
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 |
|
|
158 |
-(void) viewDidUnload {
|
|
159 |
self.lastIndexPath = nil;
|
|
160 |
self.teamDictionary = nil;
|
|
161 |
self.levelArray = nil;
|
|
162 |
self.levelSprites = nil;
|
|
163 |
[super viewDidUnload];
|
|
164 |
MSG_DIDUNLOAD();
|
|
165 |
}
|
|
166 |
|
|
167 |
-(void) dealloc {
|
|
168 |
[levelArray release];
|
|
169 |
[levelSprites release];
|
|
170 |
[teamDictionary release];
|
|
171 |
[lastIndexPath release];
|
|
172 |
[super dealloc];
|
|
173 |
}
|
|
174 |
|
|
175 |
|
|
176 |
@end
|
|
177 |
|