project_files/HedgewarsMobile/Classes/TeamConfigViewController.m
changeset 3739 97cf933e5bd2
parent 3703 12d17c6e8855
child 3780 7c704e69242e
equal deleted inserted replaced
3738:f10626e18b8a 3739:97cf933e5bd2
    10 #import "CommodityFunctions.h"
    10 #import "CommodityFunctions.h"
    11 #import "HogButtonView.h"
    11 #import "HogButtonView.h"
    12 #import "SquareButtonView.h"
    12 #import "SquareButtonView.h"
    13 
    13 
    14 @implementation TeamConfigViewController
    14 @implementation TeamConfigViewController
    15 @synthesize listOfTeams, listOfSelectedTeams;
    15 @synthesize listOfTeams, listOfSelectedTeams, cachedContentsOfDir;
    16 
    16 
    17 #define NUMBERBUTTON_TAG 123456
    17 #define NUMBERBUTTON_TAG 123456
    18 #define SQUAREBUTTON_TAG 654321
    18 #define SQUAREBUTTON_TAG 654321
    19 #define LABEL_TAG        456123
    19 #define LABEL_TAG        456123
    20 
    20 
    23 -(void) viewDidLoad {
    23 -(void) viewDidLoad {
    24     [super viewDidLoad];
    24     [super viewDidLoad];
    25 
    25 
    26     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    26     CGSize screenSize = [[UIScreen mainScreen] bounds].size;
    27     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
    27     self.view.frame = CGRectMake(0, 0, screenSize.height, screenSize.width - 44);
    28     isFirstLoad = YES;
       
    29     
    28     
    30     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    29     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    31         [self.tableView setBackgroundView:nil];
    30         [self.tableView setBackgroundView:nil];
    32         self.view.backgroundColor = [UIColor clearColor];
    31         self.view.backgroundColor = [UIColor clearColor];
    33         self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
    32         self.tableView.separatorColor = UICOLOR_HW_YELLOW_BODER;
    36 }
    35 }
    37 
    36 
    38 -(void) viewWillAppear:(BOOL)animated {
    37 -(void) viewWillAppear:(BOOL)animated {
    39     [super viewWillAppear:animated];
    38     [super viewWillAppear:animated];
    40 
    39 
       
    40     NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
    41     // avoid overwriting selected teams when returning on this view
    41     // avoid overwriting selected teams when returning on this view
    42     if (isFirstLoad) {
    42     if ([cachedContentsOfDir isEqualToArray:contentsOfDir] == NO) {
    43         // integer representation of various color (defined in SquareButtonView)
    43         // integer representation of various color (defined in SquareButtonView)
    44         NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 };
    44         NSUInteger colors[6] = { 4421353, 4100897, 10632635, 16749353, 14483456, 7566195 };
    45         NSArray *contentsOfDir = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:TEAMS_DIRECTORY() error:NULL];
       
    46         NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]];
    45         NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:[contentsOfDir count]];
    47         for (int i = 0; i < [contentsOfDir count]; i++) {
    46         for (int i = 0; i < [contentsOfDir count]; i++) {
    48             NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    47             NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
    49                                          [contentsOfDir objectAtIndex:i],@"team",
    48                                          [contentsOfDir objectAtIndex:i],@"team",
    50                                          [NSNumber numberWithInt:4],@"number",
    49                                          [NSNumber numberWithInt:4],@"number",
    56         [array release];
    55         [array release];
    57 
    56 
    58         NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil];
    57         NSMutableArray *emptyArray = [[NSMutableArray alloc] initWithObjects:nil];
    59         self.listOfSelectedTeams = emptyArray;
    58         self.listOfSelectedTeams = emptyArray;
    60         [emptyArray release];
    59         [emptyArray release];
    61         isFirstLoad = NO;
    60         
       
    61         cachedContentsOfDir = [[NSArray alloc] initWithArray:contentsOfDir copyItems:YES];
    62     }
    62     }
    63     [self.tableView reloadData];
    63     [self.tableView reloadData];
    64 }
    64 }
    65 
    65 
    66 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    66 -(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
   189 #pragma mark Memory management
   189 #pragma mark Memory management
   190 -(void) didReceiveMemoryWarning {
   190 -(void) didReceiveMemoryWarning {
   191     // Releases the view if it doesn't have a superview.
   191     // Releases the view if it doesn't have a superview.
   192     [super didReceiveMemoryWarning];
   192     [super didReceiveMemoryWarning];
   193     // Relinquish ownership any cached data, images, etc that aren't in use.
   193     // Relinquish ownership any cached data, images, etc that aren't in use.
       
   194     self.cachedContentsOfDir = nil;
   194 }
   195 }
   195 
   196 
   196 -(void) viewDidUnload {
   197 -(void) viewDidUnload {
   197     self.listOfTeams = nil;
   198     self.listOfTeams = nil;
       
   199     self.listOfSelectedTeams = nil;
       
   200     self.cachedContentsOfDir = nil;
   198     MSG_DIDUNLOAD();
   201     MSG_DIDUNLOAD();
   199     [super viewDidUnload];
   202     [super viewDidUnload];
   200 }
   203 }
   201 
   204 
   202 
   205 
   203 -(void) dealloc {
   206 -(void) dealloc {
   204     [self.listOfTeams release];
   207     [listOfTeams release];
       
   208     [listOfSelectedTeams release];
       
   209     [cachedContentsOfDir release];
   205     [super dealloc];
   210     [super dealloc];
   206 }
   211 }
   207 
   212 
   208 
   213 
   209 @end
   214 @end