author | koda |
Sat, 17 Jul 2010 06:56:39 +0200 | |
changeset 3648 | 2477029463ed |
parent 3619 | 1155d8970646 |
child 3659 | f8d5ac50e307 |
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 = @""; |
3619 | 29 |
|
30 |
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { |
|
31 |
[self.tableView setBackgroundView:nil]; |
|
32 |
self.view.backgroundColor = [UIColor clearColor]; |
|
33 |
} |
|
3547 | 34 |
} |
35 |
||
36 |
-(void) viewWillAppear:(BOOL) animated { |
|
37 |
[super viewWillAppear:animated]; |
|
38 |
||
39 |
NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:SCHEMES_DIRECTORY() error:NULL]; |
|
40 |
self.listOfSchemes = contentsOfDir; |
|
41 |
||
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
42 |
if ([listOfSchemes containsObject:@"Default.plist"]) |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
43 |
self.selectedScheme = @"Default.plist"; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
44 |
|
3547 | 45 |
contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:WEAPONS_DIRECTORY() error:NULL]; |
46 |
self.listOfWeapons = contentsOfDir; |
|
3548
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
47 |
|
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
48 |
if ([listOfWeapons containsObject:@"Default.plist"]) |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
49 |
self.selectedWeapon = @"Default.plist"; |
4d220ee7c75f
server somewhat simplified and correct sporadic crasher
koda
parents:
3547
diff
changeset
|
50 |
|
3547 | 51 |
[self.tableView reloadData]; |
52 |
} |
|
53 |
||
54 |
||
55 |
||
56 |
#pragma mark - |
|
57 |
#pragma mark Table view data source |
|
58 |
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
|
59 |
return 2; |
|
60 |
} |
|
61 |
||
62 |
||
63 |
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
|
64 |
if (section == 0) |
|
65 |
return [self.listOfSchemes count]; |
|
66 |
else |
|
67 |
return [self.listOfWeapons count]; |
|
68 |
} |
|
69 |
||
70 |
||
71 |
// Customize the appearance of table view cells. |
|
72 |
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
|
73 |
static NSString *CellIdentifier = @"Cell"; |
|
74 |
NSInteger row = [indexPath row]; |
|
75 |
||
76 |
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
|
77 |
if (cell == nil) { |
|
78 |
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; |
|
79 |
} |
|
80 |
||
81 |
cell.accessoryType = UITableViewCellAccessoryNone; |
|
82 |
if ([indexPath section] == 0) { |
|
83 |
cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; |
|
84 |
if ([[self.listOfSchemes objectAtIndex:row] isEqualToString:self.selectedScheme]) { |
|
85 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
86 |
self.lastIndexPath_sc = indexPath; |
|
87 |
} |
|
88 |
} else { |
|
89 |
cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
|
90 |
if ([[self.listOfWeapons objectAtIndex:row] isEqualToString:self.selectedWeapon]) { |
|
91 |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
92 |
self.lastIndexPath_we = indexPath; |
|
93 |
} |
|
94 |
} |
|
95 |
||
96 |
return cell; |
|
97 |
} |
|
98 |
||
99 |
||
100 |
#pragma mark - |
|
101 |
#pragma mark Table view delegate |
|
102 |
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { |
|
103 |
NSIndexPath *lastIndexPath; |
|
104 |
if ([indexPath section] == 0) |
|
105 |
lastIndexPath = self.lastIndexPath_sc; |
|
106 |
else |
|
107 |
lastIndexPath = self.lastIndexPath_we; |
|
108 |
||
109 |
int newRow = [indexPath row]; |
|
110 |
int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1; |
|
111 |
||
112 |
if (newRow != oldRow) { |
|
113 |
//TODO: this code works only for a single section table |
|
114 |
UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath]; |
|
115 |
newCell.accessoryType = UITableViewCellAccessoryCheckmark; |
|
116 |
UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath]; |
|
117 |
oldCell.accessoryType = UITableViewCellAccessoryNone; |
|
118 |
||
119 |
if ([indexPath section] == 0) { |
|
120 |
self.lastIndexPath_sc = indexPath; |
|
121 |
self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
|
122 |
} else { |
|
123 |
self.lastIndexPath_we = indexPath; |
|
124 |
self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
|
125 |
} |
|
126 |
||
127 |
[aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone]; |
|
128 |
} |
|
129 |
[aTableView deselectRowAtIndexPath:indexPath animated:YES]; |
|
130 |
} |
|
131 |
||
132 |
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger) section { |
|
133 |
if (section == 0) { |
|
134 |
return NSLocalizedString(@"Schemes",@""); |
|
135 |
} else { |
|
136 |
return NSLocalizedString(@"Weapons",@"");; |
|
137 |
} |
|
138 |
} |
|
139 |
||
140 |
#pragma mark - |
|
141 |
#pragma mark Memory management |
|
142 |
-(void) didReceiveMemoryWarning { |
|
143 |
// Releases the view if it doesn't have a superview. |
|
144 |
[super didReceiveMemoryWarning]; |
|
145 |
// Relinquish ownership any cached data, images, etc that aren't in use. |
|
146 |
} |
|
147 |
||
148 |
-(void) viewDidUnload { |
|
149 |
self.listOfSchemes = nil; |
|
150 |
self.listOfWeapons = nil; |
|
151 |
self.lastIndexPath_sc = nil; |
|
152 |
self.lastIndexPath_we = nil; |
|
153 |
self.selectedScheme = nil; |
|
154 |
self.selectedWeapon = nil; |
|
155 |
MSG_DIDUNLOAD(); |
|
156 |
} |
|
157 |
||
158 |
||
159 |
-(void) dealloc { |
|
160 |
[listOfSchemes release]; |
|
161 |
[listOfWeapons release]; |
|
162 |
[lastIndexPath_sc release]; |
|
163 |
[lastIndexPath_we release]; |
|
164 |
[selectedScheme release]; |
|
165 |
[selectedWeapon release]; |
|
166 |
[super dealloc]; |
|
167 |
} |
|
168 |
||
169 |
||
170 |
@end |
|
171 |