project_files/HedgewarsMobile/Classes/SchemeWeaponConfigViewController.m
changeset 6829 60b039d88dab
parent 6718 686ebfd50f56
child 6831 f848120b3fcc
equal deleted inserted replaced
6828:6a5d33bff0b0 6829:60b039d88dab
    24 
    24 
    25 
    25 
    26 #define LABEL_TAG 57423
    26 #define LABEL_TAG 57423
    27 #define TABLE_TAG 45657
    27 #define TABLE_TAG 45657
    28 
    28 
    29 static SchemeWeaponConfigViewController *controllerInstance;
       
    30 
       
    31 @implementation SchemeWeaponConfigViewController
    29 @implementation SchemeWeaponConfigViewController
    32 @synthesize listOfSchemes, listOfWeapons, listOfScripts, lastIndexPath_sc, lastIndexPath_we, lastIndexPath_lu,
    30 @synthesize listOfSchemes, listOfWeapons, listOfScripts, lastIndexPath_sc, lastIndexPath_we, lastIndexPath_lu,
    33             selectedScheme, selectedWeapon, selectedScript, scriptCommand, topControl, sectionsHidden;
    31             selectedScheme, selectedWeapon, selectedScript, scriptCommand, topControl, sectionsHidden;
    34 
    32 
    35 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    33 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   136     aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
   134     aTableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
   137     [self.view addSubview:aTableView];
   135     [self.view addSubview:aTableView];
   138     [aTableView release];
   136     [aTableView release];
   139 
   137 
   140     [super viewDidLoad];
   138     [super viewDidLoad];
   141     controllerInstance = self;
   139 
       
   140     // display or hide the lists, driven by MapConfigViewController
       
   141     [[NSNotificationCenter defaultCenter] addObserver:self
       
   142                                              selector:@selector(fillSections)
       
   143                                                  name:@"fillsections"
       
   144                                                object:nil];
       
   145     [[NSNotificationCenter defaultCenter] addObserver:self
       
   146                                              selector:@selector(emptySections)
       
   147                                                  name:@"emptysections"
       
   148                                                object:nil];
   142 }
   149 }
   143 
   150 
   144 #pragma mark -
   151 #pragma mark -
   145 #pragma mark Table view data source
   152 #pragma mark Table view data source
   146 -(NSInteger) numberOfSectionsInTableView:(UITableView *)aTableView {
   153 -(NSInteger) numberOfSectionsInTableView:(UITableView *)aTableView {
   306     }
   313     }
   307     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   314     [aTableView deselectRowAtIndexPath:indexPath animated:YES];
   308 }
   315 }
   309 
   316 
   310 #pragma mark -
   317 #pragma mark -
   311 #pragma mark called externally to empty or fill the sections completely
   318 #pragma mark called by an NSNotification to empty or fill the sections completely
   312 +(void) fillInstanceSections {
   319 -(void) fillSections {
   313     if (controllerInstance.sectionsHidden == YES) {
   320     if (self.sectionsHidden == YES) {
   314         controllerInstance.sectionsHidden = NO;
   321         self.sectionsHidden = NO;
   315         NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
   322         NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
   316         UITableView *aTableView = (UITableView *)[controllerInstance.view viewWithTag:TABLE_TAG];
   323         UITableView *aTableView = (UITableView *)[self.view viewWithTag:TABLE_TAG];
   317         [aTableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade];
   324         [aTableView insertSections:sections withRowAnimation:UITableViewRowAnimationFade];
   318         aTableView.scrollEnabled = YES;
   325         aTableView.scrollEnabled = YES;
   319         [[controllerInstance.view viewWithTag:LABEL_TAG] removeFromSuperview];
   326         [[self.view viewWithTag:LABEL_TAG] removeFromSuperview];
   320     }
   327     }
   321 }
   328 }
   322 
   329 
   323 +(void) emptyInstanceSections {
   330 -(void) emptySections {
   324     if (controllerInstance.sectionsHidden == NO) {
   331     if (self.sectionsHidden == NO) {
   325         controllerInstance.sectionsHidden = YES;
   332         self.sectionsHidden = YES;
   326         NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
   333         NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
   327         UITableView *aTableView = (UITableView *)[controllerInstance.view viewWithTag:TABLE_TAG];
   334         UITableView *aTableView = (UITableView *)[self.view viewWithTag:TABLE_TAG];
   328         [aTableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade];
   335         [aTableView deleteSections:sections withRowAnimation:UITableViewRowAnimationFade];
   329         aTableView.scrollEnabled = NO;
   336         aTableView.scrollEnabled = NO;
   330 
   337 
   331         CGRect frame = CGRectMake(0, 0, controllerInstance.view.frame.size.width * 80/100, 60);
   338         CGRect frame = CGRectMake(0, 0, self.view.frame.size.width * 80/100, 60);
   332         UILabel *theLabel = [[UILabel alloc] initWithFrame:frame
   339         UILabel *theLabel = [[UILabel alloc] initWithFrame:frame
   333                                                   andTitle:NSLocalizedString(@"Missions don't need further configuration",@"")];
   340                                                   andTitle:NSLocalizedString(@"Missions don't need further configuration",@"")];
   334         theLabel.center = CGPointMake(controllerInstance.view.frame.size.width/2, controllerInstance.view.frame.size.height/2);
   341         theLabel.center = CGPointMake(self.view.frame.size.width/2, self.view.frame.size.height/2);
   335         theLabel.numberOfLines = 2;
   342         theLabel.numberOfLines = 2;
   336         theLabel.tag = LABEL_TAG;
   343         theLabel.tag = LABEL_TAG;
   337         theLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth |
   344         theLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth |
   338                                     UIViewAutoresizingFlexibleTopMargin |
   345                                     UIViewAutoresizingFlexibleTopMargin |
   339                                     UIViewAutoresizingFlexibleBottomMargin;
   346                                     UIViewAutoresizingFlexibleBottomMargin;
   340 
   347 
   341         [controllerInstance.view addSubview:theLabel];
   348         [self.view addSubview:theLabel];
   342         [theLabel release];
   349         [theLabel release];
   343     }
   350     }
   344 }
   351 }
   345 
   352 
   346 #pragma mark -
   353 #pragma mark -
   362     MSG_MEMCLEAN();
   369     MSG_MEMCLEAN();
   363     [super didReceiveMemoryWarning];
   370     [super didReceiveMemoryWarning];
   364 }
   371 }
   365 
   372 
   366 -(void) viewDidUnload {
   373 -(void) viewDidUnload {
       
   374     [[NSNotificationCenter defaultCenter] removeObserver:self];
   367     self.listOfSchemes = nil;
   375     self.listOfSchemes = nil;
   368     self.listOfWeapons = nil;
   376     self.listOfWeapons = nil;
   369     self.listOfScripts = nil;
   377     self.listOfScripts = nil;
   370     self.lastIndexPath_sc = nil;
   378     self.lastIndexPath_sc = nil;
   371     self.lastIndexPath_we = nil;
   379     self.lastIndexPath_we = nil;