project_files/HedgewarsMobile/Classes/FlagsViewController.m
branchios-develop
changeset 12877 00215a7ec5f5
parent 11148 064a53861759
child 13171 ba5c794adae3
equal deleted inserted replaced
12876:2c06b1120749 12877:00215a7ec5f5
    22 
    22 
    23 
    23 
    24 @implementation FlagsViewController
    24 @implementation FlagsViewController
    25 @synthesize teamDictionary, flagArray, communityArray, lastIndexPath;
    25 @synthesize teamDictionary, flagArray, communityArray, lastIndexPath;
    26 
    26 
    27 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
    27 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    28     return rotationManager(interfaceOrientation);
    28     return rotationManager(interfaceOrientation);
    29 }
    29 }
    30 
    30 
    31 #pragma mark -
    31 #pragma mark -
    32 #pragma mark View lifecycle
    32 #pragma mark View lifecycle
    33 -(void) viewDidLoad {
    33 - (void)viewDidLoad {
    34     [super viewDidLoad];
    34     [super viewDidLoad];
    35 
    35 
    36     NSMutableArray *array_na = [[NSMutableArray alloc] init];
    36     NSMutableArray *array_na = [[NSMutableArray alloc] init];
    37     NSMutableArray *array_cm = [[NSMutableArray alloc] init];
    37     NSMutableArray *array_cm = [[NSMutableArray alloc] init];
    38 
    38 
    43         } else
    43         } else
    44              [array_na addObject:name];
    44              [array_na addObject:name];
    45     }
    45     }
    46 
    46 
    47     self.flagArray = array_na;
    47     self.flagArray = array_na;
    48     [array_na release];
       
    49     self.communityArray = array_cm;
    48     self.communityArray = array_cm;
    50     [array_cm release];
       
    51 
    49 
    52     self.title = NSLocalizedString(@"Set team flag",@"");
    50     self.title = NSLocalizedString(@"Set team flag",@"");
    53 }
    51 }
    54 
    52 
    55 -(void) viewWillAppear:(BOOL)animated {
    53 - (void)viewWillAppear:(BOOL)animated {
    56     [super viewWillAppear:animated];
    54     [super viewWillAppear:animated];
    57     // reloadData needed because team might change
    55     // reloadData needed because team might change
    58     [self.tableView reloadData];
    56     [self.tableView reloadData];
    59     //[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    57     //[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
    60 }
    58 }
    61 
    59 
    62 
    60 
    63 #pragma mark -
    61 #pragma mark -
    64 #pragma mark Table view data source
    62 #pragma mark Table view data source
    65 -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    63 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    66     return 2;
    64     return 2;
    67 }
    65 }
    68 
    66 
    69 -(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    67 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    70     if (section == 0)
    68     if (section == 0)
    71         return [self.flagArray count];
    69         return [self.flagArray count];
    72     else
    70     else
    73         return [self.communityArray count];
    71         return [self.communityArray count];
    74 }
    72 }
    78     static NSString *CellIdentifier = @"Cell";
    76     static NSString *CellIdentifier = @"Cell";
    79     NSInteger row = [indexPath row];
    77     NSInteger row = [indexPath row];
    80 
    78 
    81     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    79     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    82     if (cell == nil) {
    80     if (cell == nil) {
    83         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    81         cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    84     }
    82     }
    85 
    83 
    86     NSString *flagName = nil;
    84     NSString *flagName = nil;
    87     NSArray *source = nil;
    85     NSArray *source = nil;
    88     if ([indexPath section] == 0) {
    86     if ([indexPath section] == 0) {
    92         source = self.communityArray;
    90         source = self.communityArray;
    93         flagName = [NSString stringWithFormat:@"cm_%@",[source objectAtIndex:row]];
    91         flagName = [NSString stringWithFormat:@"cm_%@",[source objectAtIndex:row]];
    94     }
    92     }
    95     NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flagName];
    93     NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flagName];
    96     UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile];
    94     UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile];
    97     [flagFile release];
       
    98     cell.imageView.image = flagSprite;
    95     cell.imageView.image = flagSprite;
    99     [flagSprite release];
       
   100     cell.imageView.layer.borderWidth = 1;
    96     cell.imageView.layer.borderWidth = 1;
   101     cell.imageView.layer.borderColor = [[UIColor blackColor] CGColor];
    97     cell.imageView.layer.borderColor = [[UIColor blackColor] CGColor];
   102 
    98 
   103     cell.textLabel.text = [[source objectAtIndex:row] stringByDeletingPathExtension];
    99     cell.textLabel.text = [[source objectAtIndex:row] stringByDeletingPathExtension];
   104     if ([[flagName stringByDeletingPathExtension] isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) {
   100     if ([[flagName stringByDeletingPathExtension] isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) {
   128 }
   124 }
   129 
   125 
   130 
   126 
   131 #pragma mark -
   127 #pragma mark -
   132 #pragma mark Table view delegate
   128 #pragma mark Table view delegate
   133 -(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   129 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   134     NSInteger newRow = [indexPath row];
   130     NSInteger newRow = [indexPath row];
   135     NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   131     NSInteger oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
   136     NSInteger newSection = [indexPath section];
   132     NSInteger newSection = [indexPath section];
   137     NSInteger oldSection = (lastIndexPath != nil) ? [lastIndexPath section] : -1;
   133     NSInteger oldSection = (lastIndexPath != nil) ? [lastIndexPath section] : -1;
   138 
   134 
   161 }
   157 }
   162 
   158 
   163 
   159 
   164 #pragma mark -
   160 #pragma mark -
   165 #pragma mark Memory management
   161 #pragma mark Memory management
   166 -(void) didReceiveMemoryWarning {
   162 
       
   163 - (void)didReceiveMemoryWarning {
   167     self.lastIndexPath = nil;
   164     self.lastIndexPath = nil;
   168     MSG_MEMCLEAN();
   165     MSG_MEMCLEAN();
   169     [super didReceiveMemoryWarning];
   166     [super didReceiveMemoryWarning];
   170 }
   167 }
   171 
   168 
   172 -(void) viewDidUnload {
       
   173     self.teamDictionary = nil;
       
   174     self.lastIndexPath = nil;
       
   175     self.flagArray = nil;
       
   176     self.communityArray = nil;
       
   177     MSG_DIDUNLOAD();
       
   178     [super viewDidUnload];
       
   179 }
       
   180 
       
   181 -(void) dealloc {
       
   182     releaseAndNil(teamDictionary);
       
   183     releaseAndNil(lastIndexPath);
       
   184     releaseAndNil(flagArray);
       
   185     releaseAndNil(communityArray);
       
   186     [super dealloc];
       
   187 }
       
   188 
       
   189 
       
   190 @end
   169 @end
   191 
   170