22 #import "SchemeWeaponConfigViewController.h" |
22 #import "SchemeWeaponConfigViewController.h" |
23 #import <QuartzCore/QuartzCore.h> |
23 #import <QuartzCore/QuartzCore.h> |
24 |
24 |
25 |
25 |
26 #define LABEL_TAG 57423 |
26 #define LABEL_TAG 57423 |
|
27 #define TABLE_TAG 45657 |
27 |
28 |
28 static SchemeWeaponConfigViewController *controllerInstance; |
29 static SchemeWeaponConfigViewController *controllerInstance; |
29 |
30 |
30 @implementation SchemeWeaponConfigViewController |
31 @implementation SchemeWeaponConfigViewController |
31 @synthesize tableView, listOfSchemes, listOfWeapons, listOfScripts, lastIndexPath_sc, lastIndexPath_we, lastIndexPath_lu, |
32 @synthesize listOfSchemes, listOfWeapons, listOfScripts, lastIndexPath_sc, lastIndexPath_we, lastIndexPath_lu, |
32 selectedScheme, selectedWeapon, selectedScript, scriptCommand, topControl, sectionsHidden; |
33 selectedScheme, selectedWeapon, selectedScript, scriptCommand, topControl, sectionsHidden; |
33 |
34 |
34 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
35 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { |
35 return rotationManager(interfaceOrientation); |
36 return rotationManager(interfaceOrientation); |
36 } |
37 } |
99 #pragma mark - |
100 #pragma mark - |
100 #pragma mark View lifecycle |
101 #pragma mark View lifecycle |
101 -(void) viewDidLoad { |
102 -(void) viewDidLoad { |
102 self.sectionsHidden = NO; |
103 self.sectionsHidden = NO; |
103 |
104 |
104 UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) |
105 UITableView *aTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 45, self.view.frame.size.width, self.view.frame.size.height-48) |
105 style:UITableViewStyleGrouped]; |
106 style:UITableViewStyleGrouped]; |
106 aTableView.delegate = self; |
107 aTableView.delegate = self; |
107 aTableView.dataSource = self; |
108 aTableView.dataSource = self; |
108 if (IS_IPAD()) { |
109 if (IS_IPAD()) { |
109 [aTableView setBackgroundColorForAnyTable:[UIColor darkBlueColorTransparent]]; |
110 [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
110 aTableView.layer.borderColor = [[UIColor darkYellowColor] CGColor]; |
111 UILabel *background = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) |
111 aTableView.layer.borderWidth = 2.7f; |
112 andTitle:nil |
112 aTableView.layer.cornerRadius = 8; |
113 withBorderWidth:2.7f]; |
113 aTableView.contentInset = UIEdgeInsetsMake(5, 0, 5, 0); |
114 background.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
|
115 [self.view insertSubview:background atIndex:0]; |
|
116 [background release]; |
|
117 |
|
118 self.topControl.frame = CGRectMake(0, 4, self.view.frame.size.width * 80/100, 30); |
|
119 self.topControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; |
|
120 self.topControl.center = CGPointMake(self.view.frame.size.width/2, 24); |
|
121 [self.topControl addTarget:aTableView action:@selector(reloadData) forControlEvents:UIControlEventValueChanged]; |
|
122 [self.view addSubview:self.topControl]; |
114 } else { |
123 } else { |
115 UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
124 UIImage *backgroundImage = [[UIImage alloc] initWithContentsOfFile:@"background~iphone.png"]; |
116 UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
125 UIImageView *background = [[UIImageView alloc] initWithImage:backgroundImage]; |
117 [backgroundImage release]; |
126 [backgroundImage release]; |
118 [self.view addSubview:background]; |
127 [self.view addSubview:background]; |
119 [background release]; |
128 [background release]; |
120 [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
129 [aTableView setBackgroundColorForAnyTable:[UIColor clearColor]]; |
121 } |
130 } |
122 |
131 |
|
132 aTableView.tag = TABLE_TAG; |
123 aTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
133 aTableView.indicatorStyle = UIScrollViewIndicatorStyleWhite; |
124 aTableView.separatorColor = [UIColor whiteColor]; |
134 aTableView.separatorColor = [UIColor whiteColor]; |
125 aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
135 aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; |
126 aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
136 aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
127 self.tableView = aTableView; |
137 [self.view addSubview:aTableView]; |
128 [aTableView release]; |
138 [aTableView release]; |
129 [self.view addSubview:self.tableView]; |
|
130 |
139 |
131 [super viewDidLoad]; |
140 [super viewDidLoad]; |
132 controllerInstance = self; |
141 controllerInstance = self; |
133 } |
142 } |
134 |
143 |
135 // this is a workaround to keep the uisegmented control visible |
|
136 -(void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { |
|
137 [self.tableView reloadData]; |
|
138 } |
|
139 |
|
140 #pragma mark - |
144 #pragma mark - |
141 #pragma mark Table view data source |
145 #pragma mark Table view data source |
142 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { |
146 -(NSInteger) numberOfSectionsInTableView:(UITableView *)aTableView { |
143 return (self.sectionsHidden ? 0 : 1); |
147 return (self.sectionsHidden ? 0 : 1); |
144 } |
148 } |
145 |
149 |
146 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
150 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { |
147 if (self.topControl.selectedSegmentIndex == 0) |
151 if (self.topControl.selectedSegmentIndex == 0) |
207 cell.textLabel.adjustsFontSizeToFitWidth = YES; |
211 cell.textLabel.adjustsFontSizeToFitWidth = YES; |
208 cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
212 cell.detailTextLabel.adjustsFontSizeToFitWidth = YES; |
209 return cell; |
213 return cell; |
210 } |
214 } |
211 |
215 |
212 -(CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { |
216 -(CGFloat) tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section { |
213 return 50.0; |
217 return IS_IPAD() ? 50.0 : 0; |
214 } |
218 } |
215 |
219 |
216 -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { |
220 -(UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section { |
|
221 if (IS_IPAD()) |
|
222 return nil; |
217 UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)]; |
223 UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 30)]; |
218 theView.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
224 theView.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
219 self.topControl.frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
225 self.topControl.frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 30); |
220 self.topControl.center = CGPointMake(self.view.frame.size.width/2, 24); |
226 self.topControl.center = CGPointMake(self.view.frame.size.width/2, 24); |
221 [self.topControl addTarget:self.tableView action:@selector(reloadData) forControlEvents:UIControlEventValueChanged]; |
227 [self.topControl addTarget:aTableView action:@selector(reloadData) forControlEvents:UIControlEventValueChanged]; |
222 [theView addSubview:self.topControl]; |
228 [theView addSubview:self.topControl]; |
223 return [theView autorelease]; |
229 return [theView autorelease]; |
224 } |
230 } |
225 |
231 |
226 #pragma mark - |
232 #pragma mark - |
305 #pragma mark called externally to empty or fill the sections completely |
311 #pragma mark called externally to empty or fill the sections completely |
306 +(void) fillInstanceSections { |
312 +(void) fillInstanceSections { |
307 if (controllerInstance.sectionsHidden == YES) { |
313 if (controllerInstance.sectionsHidden == YES) { |
308 controllerInstance.sectionsHidden = NO; |
314 controllerInstance.sectionsHidden = NO; |
309 NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]; |
315 NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]; |
310 [controllerInstance.tableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
316 UITableView *aTableView = (UITableView *)[controllerInstance.view viewWithTag:TABLE_TAG]; |
311 controllerInstance.tableView.scrollEnabled = YES; |
317 [aTableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
312 |
318 aTableView.scrollEnabled = YES; |
313 [[controllerInstance.view viewWithTag:LABEL_TAG] removeFromSuperview]; |
319 [[controllerInstance.view viewWithTag:LABEL_TAG] removeFromSuperview]; |
314 } |
320 } |
315 } |
321 } |
316 |
322 |
317 +(void) emptyInstanceSections { |
323 +(void) emptyInstanceSections { |
318 if (controllerInstance.sectionsHidden == NO) { |
324 if (controllerInstance.sectionsHidden == NO) { |
319 controllerInstance.sectionsHidden = YES; |
325 controllerInstance.sectionsHidden = YES; |
320 NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]; |
326 NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)]; |
321 [controllerInstance.tableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
327 UITableView *aTableView = (UITableView *)[controllerInstance.view viewWithTag:TABLE_TAG]; |
322 controllerInstance.tableView.scrollEnabled = NO; |
328 [aTableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade]; |
|
329 aTableView.scrollEnabled = NO; |
323 |
330 |
324 CGRect frame = CGRectMake(0, 0, controllerInstance.view.frame.size.width * 80/100, 60); |
331 CGRect frame = CGRectMake(0, 0, controllerInstance.view.frame.size.width * 80/100, 60); |
325 UILabel *theLabel = [[UILabel alloc] initWithFrame:frame |
332 UILabel *theLabel = [[UILabel alloc] initWithFrame:frame |
326 andTitle:NSLocalizedString(@"Missions don't need further configuration",@"")]; |
333 andTitle:NSLocalizedString(@"Missions don't need further configuration",@"")]; |
327 theLabel.center = CGPointMake(controllerInstance.view.frame.size.width/2, controllerInstance.view.frame.size.height/2); |
334 theLabel.center = CGPointMake(controllerInstance.view.frame.size.width/2, controllerInstance.view.frame.size.height/2); |