22 #import "SchemeWeaponConfigViewController.h" |
22 #import "SchemeWeaponConfigViewController.h" |
23 #import "CommodityFunctions.h" |
23 #import "CommodityFunctions.h" |
24 #import "SDL_uikitappdelegate.h" |
24 #import "SDL_uikitappdelegate.h" |
25 |
25 |
26 @implementation SchemeWeaponConfigViewController |
26 @implementation SchemeWeaponConfigViewController |
27 @synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon; |
27 @synthesize listOfSchemes, listOfWeapons, lastIndexPath_sc, lastIndexPath_we, selectedScheme, selectedWeapon, syncSwitch; |
28 |
28 |
29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
29 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
30 return rotationManager(interfaceOrientation); |
30 return rotationManager(interfaceOrientation); |
31 } |
31 } |
32 |
32 |
79 |
79 |
80 |
80 |
81 #pragma mark - |
81 #pragma mark - |
82 #pragma mark Table view data source |
82 #pragma mark Table view data source |
83 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
83 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
84 return 2; |
84 return 3; |
85 } |
85 } |
86 |
86 |
87 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
87 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
88 if (section == 0) |
88 if (section == 0) |
89 return [self.listOfSchemes count]; |
89 return [self.listOfSchemes count]; |
|
90 else if (section == 1) |
|
91 return [self.listOfWeapons count]; |
90 else |
92 else |
91 return [self.listOfWeapons count]; |
93 return 1; |
92 } |
94 } |
93 |
95 |
94 // Customize the appearance of table view cells. |
96 // Customize the appearance of table view cells. |
95 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
97 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { |
96 static NSString *CellIdentifier = @"Cell"; |
98 static NSString *CellIdentifier = @"Cell"; |
97 NSInteger row = [indexPath row]; |
99 NSInteger row = [indexPath row]; |
|
100 NSInteger section = [indexPath section]; |
98 |
101 |
99 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
102 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; |
100 if (cell == nil) |
103 if (cell == nil) |
101 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; |
104 cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; |
102 |
105 |
103 cell.accessoryView = nil; |
106 cell.accessoryView = nil; |
104 if ([indexPath section] == 0) { |
107 if (0 == section) { |
105 cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; |
108 cell.textLabel.text = [[self.listOfSchemes objectAtIndex:row] stringByDeletingPathExtension]; |
106 NSString *str = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]]; |
109 NSString *str = [NSString stringWithFormat:@"%@/%@",SCHEMES_DIRECTORY(),[self.listOfSchemes objectAtIndex:row]]; |
107 NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
110 NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
108 cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
111 cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
109 [dict release]; |
112 [dict release]; |
111 UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
114 UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
112 cell.accessoryView = checkbox; |
115 cell.accessoryView = checkbox; |
113 [checkbox release]; |
116 [checkbox release]; |
114 self.lastIndexPath_sc = indexPath; |
117 self.lastIndexPath_sc = indexPath; |
115 } |
118 } |
116 } else { |
119 } else if (1 == section) { |
117 cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
120 cell.textLabel.text = [[self.listOfWeapons objectAtIndex:row] stringByDeletingPathExtension]; |
118 NSString *str = [NSString stringWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]]; |
121 NSString *str = [NSString stringWithFormat:@"%@/%@",WEAPONS_DIRECTORY(),[self.listOfWeapons objectAtIndex:row]]; |
119 NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
122 NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:str]; |
120 cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
123 cell.detailTextLabel.text = [dict objectForKey:@"description"]; |
121 [dict release]; |
124 [dict release]; |
123 UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
126 UIImageView *checkbox = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:@"checkbox.png"]]; |
124 cell.accessoryView = checkbox; |
127 cell.accessoryView = checkbox; |
125 [checkbox release]; |
128 [checkbox release]; |
126 self.lastIndexPath_we = indexPath; |
129 self.lastIndexPath_we = indexPath; |
127 } |
130 } |
128 } |
131 } else { |
129 |
132 if (self.syncSwitch == nil) { |
|
133 UISwitch *theSwitch = [[UISwitch alloc] init]; |
|
134 [theSwitch setOn:YES]; |
|
135 self.syncSwitch = theSwitch; |
|
136 [theSwitch release]; |
|
137 } |
|
138 cell.textLabel.text = IS_IPAD() ? NSLocalizedString(@"Sync Schemes",@"") : NSLocalizedString(@"Sync Schemes and Weapons",@""); |
|
139 cell.detailTextLabel.text = IS_IPAD() ? nil : NSLocalizedString(@"Choosing a Scheme will select its associated Weapon",@""); |
|
140 cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
|
141 cell.accessoryView = self.syncSwitch; |
|
142 } |
|
143 |
130 cell.backgroundColor = [UIColor blackColor]; |
144 cell.backgroundColor = [UIColor blackColor]; |
131 cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
145 cell.textLabel.textColor = UICOLOR_HW_YELLOW_TEXT; |
132 cell.detailTextLabel.textColor = [UIColor whiteColor]; |
146 cell.detailTextLabel.textColor = [UIColor whiteColor]; |
133 return cell; |
147 return cell; |
134 } |
148 } |
140 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
154 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
141 CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
155 CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
142 NSString *text; |
156 NSString *text; |
143 if (section == 0) |
157 if (section == 0) |
144 text = NSLocalizedString(@"Schemes",@""); |
158 text = NSLocalizedString(@"Schemes",@""); |
|
159 else if (section == 1) |
|
160 text = NSLocalizedString(@"Weapons",@""); |
145 else |
161 else |
146 text = NSLocalizedString(@"Weapons",@""); |
162 text = NSLocalizedString(@"Options",@""); |
|
163 |
147 UILabel *theLabel = createBlueLabel(text, frame); |
164 UILabel *theLabel = createBlueLabel(text, frame); |
148 theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
165 theLabel.center = CGPointMake(self.view.frame.size.width/2, 20); |
149 |
166 |
150 UIView *theView = [[[UIView alloc] init] autorelease]; |
167 UIView *theView = [[[UIView alloc] init] autorelease]; |
151 [theView addSubview:theLabel]; |
168 [theView addSubview:theLabel]; |
175 oldCell.accessoryView = nil; |
192 oldCell.accessoryView = nil; |
176 |
193 |
177 if ([indexPath section] == 0) { |
194 if ([indexPath section] == 0) { |
178 self.lastIndexPath_sc = indexPath; |
195 self.lastIndexPath_sc = indexPath; |
179 self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
196 self.selectedScheme = [self.listOfSchemes objectAtIndex:newRow]; |
|
197 if (self.syncSwitch.on) { |
|
198 for (NSString *str in self.listOfWeapons) { |
|
199 if ([str isEqualToString:self.selectedScheme]) { |
|
200 int index = [self.listOfSchemes indexOfObject:str]; |
|
201 self.selectedWeapon = str; |
|
202 self.lastIndexPath_we = [NSIndexPath indexPathForRow:index inSection:1]; |
|
203 [self.tableView reloadData]; |
|
204 break; |
|
205 } |
|
206 } |
|
207 } |
180 } else { |
208 } else { |
181 self.lastIndexPath_we = indexPath; |
209 self.lastIndexPath_we = indexPath; |
182 self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
210 self.selectedWeapon = [self.listOfWeapons objectAtIndex:newRow]; |
183 } |
211 } |
184 |
212 |
193 if ([[SDLUIKitDelegate sharedAppDelegate] isInGame]) { |
221 if ([[SDLUIKitDelegate sharedAppDelegate] isInGame]) { |
194 self.lastIndexPath_sc = nil; |
222 self.lastIndexPath_sc = nil; |
195 self.lastIndexPath_we = nil; |
223 self.lastIndexPath_we = nil; |
196 self.listOfSchemes = nil; |
224 self.listOfSchemes = nil; |
197 self.listOfWeapons = nil; |
225 self.listOfWeapons = nil; |
|
226 self.syncSwitch = nil; |
198 MSG_MEMCLEAN(); |
227 MSG_MEMCLEAN(); |
199 } |
228 } |
200 [super didReceiveMemoryWarning]; |
229 [super didReceiveMemoryWarning]; |
201 } |
230 } |
202 |
231 |
205 self.listOfWeapons = nil; |
234 self.listOfWeapons = nil; |
206 self.lastIndexPath_sc = nil; |
235 self.lastIndexPath_sc = nil; |
207 self.lastIndexPath_we = nil; |
236 self.lastIndexPath_we = nil; |
208 self.selectedScheme = nil; |
237 self.selectedScheme = nil; |
209 self.selectedWeapon = nil; |
238 self.selectedWeapon = nil; |
|
239 self.syncSwitch = nil; |
210 MSG_DIDUNLOAD(); |
240 MSG_DIDUNLOAD(); |
211 [super viewDidUnload]; |
241 [super viewDidUnload]; |
212 } |
242 } |
213 |
243 |
214 |
244 |
217 [listOfWeapons release]; |
247 [listOfWeapons release]; |
218 [lastIndexPath_sc release]; |
248 [lastIndexPath_sc release]; |
219 [lastIndexPath_we release]; |
249 [lastIndexPath_we release]; |
220 [selectedScheme release]; |
250 [selectedScheme release]; |
221 [selectedWeapon release]; |
251 [selectedWeapon release]; |
|
252 [syncSwitch release]; |
222 [super dealloc]; |
253 [super dealloc]; |
223 } |
254 } |
224 |
255 |
225 |
256 |
226 @end |
257 @end |