author | koda |
Thu, 24 Jun 2010 01:08:25 +0200 | |
changeset 3548 | 4d220ee7c75f |
parent 3547 | 02875b1145b7 |
child 3619 | 1155d8970646 |
permissions | -rw-r--r-- |
3547 | 1 |
// |
2 |
// SchemeWeaponConfigViewController.m |
|
3 |
// Hedgewars |
|
4 |
// |
|
5 |
// Created by Vittorio on 13/06/10. |
|
6 |
// Copyright 2010 __MyCompanyName__. All rights reserved. |
|
7 |
// |
|
8 |
||
9 |
#import "SchemeWeaponConfigViewController.h" |
|
10 |
#import "CommodityFunctions.h" |
|
11 |
||
12 |
@implementation SchemeWeaponConfigViewController |
|
13 |
@synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon; |
|
14 |
||
15 |
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
|
16 |
return rotationManager(interfaceOrientation); |
|
17 |
} |
|
18 |
||
19 |
#pragma mark - |
|
20 |
#pragma mark View lifecycle |
|
21 |
-(void) viewDidLoad { |
|
22 |
[super viewDidLoad]; |
|
23 |
||
24 |
CGSize screenSize = [[UIScreen mainScreen] bounds].size; |
|
25 |
self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44); |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
26 |
|
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
27 |
self.selectedScheme = @""; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
28 |
self.selectedWeapon = @""; |
3547 | 29 |
} |
30 |
||
31 |
-(void) viewWillAppear:(BOOL) animated { |
|
32 |
[super viewWillAppear:animated]; |
|
33 |
||
34 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL]; |
|
35 |
self.listOfSchemes = contentsOfDir; |
|
36 |
||
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
37 |
if ([listOfSchemes containsObject:@"Default.plist"]) |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
38 |
self.selectedScheme = @"Default.plist"; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
39 |
|
3547 | 40 |
contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL]; |
41 |
self.listOfWeapons = contentsOfDir; |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
42 |
|
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
43 |
if ([listOfWeapons containsObject:@"Default.plist"]) |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
44 |
self.selectedWeapon = @"Default.plist"; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
45 |
|
3547 | 46 |
[self.tableView reloadData]; |
47 |
} |
|
48 |
||
49 |
||
50 |
||
51 |
#pragma mark - |
|
52 |
#pragma mark Table view data source |
|
53 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
54 |
return 2; |
|
55 |
} |
|
56 |
||
57 |
||
58 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
59 |
if (section == 0) |
|
60 |
return [self.listOfSchemes count]; |
|
61 |
else |
|
62 |
return [self.listOfWeapons count]; |
|
63 |
} |
|
64 |
||
65 |
||
66 |
// Customize the appearance of table view cells. |
|
67 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
68 |
static NSString *CellIdentifier = @"Cell"; |
|
69 |
NSInteger row = [indexPath row]; |
|
70 |
||
71 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
72 |
if (cell == nil) { |
|
73 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
74 |
} |
|
75 |
||
76 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
77 |
if ([indexPath section] == 0) { |
|
78 |
cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; |
|
79 |
if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) { |
|
80 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
81 |
self.lastIndexPath_sc = indexPath; |
|
82 |
} |
|
83 |
} else { |
|
84 |
cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
|
85 |
if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) { |
|
86 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
87 |
self.lastIndexPath_we = indexPath; |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
return cell; |
|
92 |
} |
|
93 |
||
94 |
||
95 |
#pragma mark - |
|
96 |
#pragma mark Table view delegate |
|
97 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
98 |
NSIndexPath *lastIndexPath; |
|
99 |
if ([indexPath section] == 0) |
|
100 |
lastIndexPath = self.lastIndexPath_sc; |
|
101 |
else |
|
102 |
lastIndexPath = self.lastIndexPath_we; |
|
103 |
||
104 |
int newRow = [indexPath row]; |
|
105 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
106 |
||
107 |
if (newRow != oldRow) { |
|
108 |
//TODO: this code works only for a single section table |
|
109 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
110 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
111 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
112 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
113 |
||
114 |
if ([indexPath section] == 0) { |
|
115 |
self.lastIndexPath_sc = indexPath; |
|
116 |
self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
|
117 |
} else { |
|
118 |
self.lastIndexPath_we = indexPath; |
|
119 |
self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
|
120 |
} |
|
121 |
||
122 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
123 |
} |
|
124 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
125 |
} |
|
126 |
||
127 |
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger) section { |
|
128 |
if (section == 0) { |
|
129 |
return NSLocalizedString(@"Schemes",@""); |
|
130 |
} else { |
|
131 |
return NSLocalizedString(@"Weapons",@"");; |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
#pragma mark - |
|
136 |
#pragma mark Memory management |
|
137 |
-(void) didReceiveMemoryWarning { |
|
138 |
// Releases the view if it doesn't have a superview. |
|
139 |
[super didReceiveMemoryWarning]; |
|
140 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
141 |
} |
|
142 |
||
143 |
-(void) viewDidUnload { |
|
144 |
self.listOfSchemes = nil; |
|
145 |
self.listOfWeapons = nil; |
|
146 |
self.lastIndexPath_sc = nil; |
|
147 |
self.lastIndexPath_we = nil; |
|
148 |
self.selectedScheme = nil; |
|
149 |
self.selectedWeapon = nil; |
|
150 |
MSG_DIDUNLOAD(); |
|
151 |
} |
|
152 |
||
153 |
||
154 |
-(void) dealloc { |
|
155 |
[listOfSchemes release]; |
|
156 |
[listOfWeapons release]; |
|
157 |
[lastIndexPath_sc release]; |
|
158 |
[lastIndexPath_we release]; |
|
159 |
[selectedScheme release]; |
|
160 |
[selectedWeapon release]; |
|
161 |
[super dealloc]; |
|
162 |
} |
|
163 |
||
164 |
||
165 |
@end |
|
166 |