project_files/HedgewarsMobile/Classes/FlagsViewController.m
author koda
Sun, 20 Jun 2010 18:35:59 +0200
changeset 3523 6592fbb969da
parent 3514 59dbd31e9953
child 3546 ccf4854df294
permissions -rw-r--r--
fix zoom smoothness some more work for weapons on the ifrontend bugfix for the gameconfig page
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     1
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     2
//  FlagsViewController.m
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     3
//  HedgewarsMobile
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     4
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     5
//  Created by Vittorio on 08/04/10.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     7
//
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     8
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
     9
#import "FlagsViewController.h"
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    10
#import "CommodityFunctions.h"
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    11
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    12
@implementation FlagsViewController
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    13
@synthesize teamDictionary, flagArray, lastIndexPath;
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    14
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    15
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3325
diff changeset
    16
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3325
diff changeset
    17
	return rotationManager(interfaceOrientation);
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    18
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    19
3335
2520ee7a5484 new manager for handling (future) rotations
koda
parents: 3325
diff changeset
    20
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    21
#pragma mark -
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    22
#pragma mark View lifecycle
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    23
-(void) viewDidLoad {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    24
    [super viewDidLoad];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    25
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    26
    self.flagArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:FLAGS_DIRECTORY() error:NULL];
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    27
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    28
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    29
-(void) viewWillAppear:(BOOL)animated {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    30
    [super viewWillAppear:animated];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    31
    [self.tableView reloadData];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    32
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    33
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    34
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    35
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    36
#pragma mark -
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    37
#pragma mark Table view data source
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    38
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    39
    return 1;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    40
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    41
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    42
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    43
    return [flagArray count];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    44
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    45
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    46
// Customize the appearance of table view cells.
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    47
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    48
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    49
    static NSString *CellIdentifier = @"Cell";
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    50
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    51
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    52
    if (cell == nil) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    53
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    54
    }
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    55
    
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    56
    NSString *flag = [flagArray objectAtIndex:[indexPath row]];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    57
    
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    58
    NSString *flagFile = [[NSString alloc] initWithFormat:@"%@/%@", FLAGS_DIRECTORY(), flag];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    59
    UIImage *flagSprite = [[UIImage alloc] initWithContentsOfFile:flagFile];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    60
    [flagFile release];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    61
    cell.imageView.image = flagSprite;
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    62
    [flagSprite release];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    63
    
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    64
    cell.textLabel.text = [flag stringByDeletingPathExtension];
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    65
    if ([cell.textLabel.text isEqualToString:[self.teamDictionary objectForKey:@"flag"]]) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    66
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    67
        self.lastIndexPath = indexPath;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    68
    } else {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    69
        cell.accessoryType = UITableViewCellAccessoryNone;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    70
    }
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    71
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    72
    return cell;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    73
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    74
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    75
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    76
#pragma mark -
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    77
#pragma mark Table view delegate
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    78
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    79
    int newRow = [indexPath row];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    80
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    81
    
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    82
    if (newRow != oldRow) {
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    83
        // if the two selected rows differ update data on the hog dictionary and reload table content
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    84
        [self.teamDictionary setValue:[[flagArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"flag"];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    85
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    86
        // tell our boss to write this new stuff on disk
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    87
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    88
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    89
        UITableViewCell *newCell = [aTableView cellForRowAtIndexPath:indexPath];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    90
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    91
        UITableViewCell *oldCell = [aTableView cellForRowAtIndexPath:lastIndexPath];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    92
        oldCell.accessoryType = UITableViewCellAccessoryNone;
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    93
        self.lastIndexPath = indexPath;
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    94
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    95
    }
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
    96
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    97
    [self.navigationController popViewControllerAnimated:YES];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    98
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
    99
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   100
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   101
#pragma mark -
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   102
#pragma mark Memory management
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
   103
-(void) didReceiveMemoryWarning {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   104
    // Releases the view if it doesn't have a superview.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   105
    [super didReceiveMemoryWarning];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   106
    // Relinquish ownership any cached data, images, etc that aren't in use.
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   107
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   108
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
   109
-(void) viewDidUnload {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   110
    self.teamDictionary = nil;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   111
    self.lastIndexPath = nil;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   112
    self.flagArray = nil;
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   113
    [super viewDidUnload];
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3374
diff changeset
   114
    MSG_DIDUNLOAD();
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   115
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   116
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3335
diff changeset
   117
-(void) dealloc {
3325
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   118
    [teamDictionary release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   119
    [lastIndexPath release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   120
    [flagArray release];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   121
    [super dealloc];
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   122
}
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   123
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   124
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   125
@end
652a8ebdf667 moved around team creation
koda
parents:
diff changeset
   126