3325
|
1 |
//
|
|
2 |
// FlagsViewController.m
|
|
3 |
// HedgewarsMobile
|
|
4 |
//
|
|
5 |
// Created by Vittorio on 08/04/10.
|
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
|
7 |
//
|
|
8 |
|
|
9 |
#import "FlagsViewController.h"
|
|
10 |
#import "CommodityFunctions.h"
|
|
11 |
|
|
12 |
@implementation FlagsViewController
|
|
13 |
@synthesize teamDictionary, flagArray, flagSprites, lastIndexPath;
|
|
14 |
|
|
15 |
|
3335
|
16 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
|
|
17 |
return rotationManager(interfaceOrientation);
|
3325
|
18 |
}
|
|
19 |
|
3335
|
20 |
|
3325
|
21 |
#pragma mark -
|
|
22 |
#pragma mark View lifecycle
|
|
23 |
- (void)viewDidLoad {
|
|
24 |
[super viewDidLoad];
|
|
25 |
|
|
26 |
NSString *flagsDirectory = FLAGS_DIRECTORY();
|
|
27 |
NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:flagsDirectory error:NULL];
|
|
28 |
self.flagArray = array;
|
|
29 |
|
|
30 |
NSMutableArray *spriteArray = [[NSMutableArray alloc] initWithCapacity:[flagArray count]];
|
|
31 |
for (NSString *flagName in flagArray) {
|
|
32 |
NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", flagsDirectory, flagName];
|
|
33 |
UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile];
|
|
34 |
[flagFile release];
|
|
35 |
[spriteArray addObject:flagSprite];
|
|
36 |
[flagSprite release];
|
|
37 |
}
|
|
38 |
self.flagSprites = spriteArray;
|
|
39 |
[spriteArray release];
|
|
40 |
}
|
|
41 |
|
|
42 |
- (void)viewWillAppear:(BOOL)animated {
|
|
43 |
[super viewWillAppear:animated];
|
|
44 |
[self.tableView reloadData];
|
|
45 |
[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
|
|
46 |
}
|
|
47 |
|
|
48 |
/*
|
|
49 |
- (void)viewDidAppear:(BOOL)animated {
|
|
50 |
[super viewDidAppear:animated];
|
|
51 |
}
|
|
52 |
*/
|
|
53 |
/*
|
|
54 |
- (void)viewWillDisappear:(BOOL)animated {
|
|
55 |
[super viewWillDisappear:animated];
|
|
56 |
}
|
|
57 |
*/
|
|
58 |
/*
|
|
59 |
- (void)viewDidDisappear:(BOOL)animated {
|
|
60 |
[super viewDidDisappear:animated];
|
|
61 |
}
|
|
62 |
*/
|
|
63 |
|
|
64 |
|
|
65 |
#pragma mark -
|
|
66 |
#pragma mark Table view data source
|
|
67 |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
|
68 |
return 1;
|
|
69 |
}
|
|
70 |
|
|
71 |
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
72 |
return [flagArray count];
|
|
73 |
}
|
|
74 |
|
|
75 |
// Customize the appearance of table view cells.
|
|
76 |
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
77 |
|
|
78 |
static NSString *CellIdentifier = @"Cell";
|
|
79 |
|
|
80 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
|
|
81 |
if (cell == nil) {
|
|
82 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
|
|
83 |
}
|
|
84 |
|
|
85 |
cell.imageView.image = [flagSprites objectAtIndex:[indexPath row]];
|
|
86 |
cell.textLabel.text = [[flagArray objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
|
|
87 |
if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) {
|
|
88 |
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
89 |
self.lastIndexPath = indexPath;
|
|
90 |
} else {
|
|
91 |
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
92 |
}
|
|
93 |
|
|
94 |
return cell;
|
|
95 |
}
|
|
96 |
|
|
97 |
|
|
98 |
/*
|
|
99 |
// Override to support conditional editing of the table view.
|
|
100 |
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
101 |
// Return NO if you do not want the specified item to be editable.
|
|
102 |
return YES;
|
|
103 |
}
|
|
104 |
*/
|
|
105 |
|
|
106 |
|
|
107 |
/*
|
|
108 |
// Override to support editing the table view.
|
|
109 |
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
110 |
|
|
111 |
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
|
112 |
// Delete the row from the data source
|
|
113 |
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
|
|
114 |
}
|
|
115 |
else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
|
116 |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
|
|
117 |
}
|
|
118 |
}
|
|
119 |
*/
|
|
120 |
|
|
121 |
|
|
122 |
/*
|
|
123 |
// Override to support rearranging the table view.
|
|
124 |
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
|
125 |
}
|
|
126 |
*/
|
|
127 |
|
|
128 |
|
|
129 |
/*
|
|
130 |
// Override to support conditional rearranging of the table view.
|
|
131 |
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
132 |
// Return NO if you do not want the item to be re-orderable.
|
|
133 |
return YES;
|
|
134 |
}
|
|
135 |
*/
|
|
136 |
|
|
137 |
|
|
138 |
#pragma mark -
|
|
139 |
#pragma mark Table view delegate
|
|
140 |
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
141 |
int newRow = [indexPath row];
|
|
142 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
|
|
143 |
|
|
144 |
if (newRow != oldRow) {
|
|
145 |
// if the two selected rows differ update data on the hog dictionary and reload table content
|
|
146 |
[self.teamDictionary setValue:[[flagArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"flag"];
|
|
147 |
|
|
148 |
// tell our boss to write this new stuff on disk
|
|
149 |
[[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
|
|
150 |
[self.tableView reloadData];
|
|
151 |
|
|
152 |
self.lastIndexPath = indexPath;
|
|
153 |
[self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
|
154 |
}
|
|
155 |
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
156 |
[self.navigationController popViewControllerAnimated:YES];
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
#pragma mark -
|
|
161 |
#pragma mark Memory management
|
|
162 |
- (void)didReceiveMemoryWarning {
|
|
163 |
// Releases the view if it doesn't have a superview.
|
|
164 |
[super didReceiveMemoryWarning];
|
|
165 |
// Relinquish ownership any cached data, images, etc that aren't in use.
|
|
166 |
}
|
|
167 |
|
|
168 |
- (void)viewDidUnload {
|
|
169 |
self.teamDictionary = nil;
|
|
170 |
self.lastIndexPath = nil;
|
|
171 |
self.flagArray = nil;
|
|
172 |
self.flagSprites = nil;
|
|
173 |
[super viewDidUnload];
|
|
174 |
}
|
|
175 |
|
|
176 |
|
|
177 |
- (void)dealloc {
|
|
178 |
[teamDictionary release];
|
|
179 |
[lastIndexPath release];
|
|
180 |
[flagArray release];
|
|
181 |
[flagSprites release];
|
|
182 |
[super dealloc];
|
|
183 |
}
|
|
184 |
|
|
185 |
|
|
186 |
@end
|
|
187 |
|