cocoaTouch/GravesViewController.m
author nemo
Mon, 17 May 2010 02:54:56 +0000
changeset 3470 2b0c88693535
parent 3374 0d522416d97f
child 3490 016b3172b645
permissions -rw-r--r--
Change to just set timer to 0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     1
//
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
     2
//  GravesViewController.m
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     3
//  HedgewarsMobile
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     4
//
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     5
//  Created by Vittorio on 02/04/10.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     7
//
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
     8
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
     9
#import "GravesViewController.h"
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    10
#import "CommodityFunctions.h"
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    11
#import "UIImageExtra.h"
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    12
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    13
@implementation GravesViewController
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    14
@synthesize teamDictionary, graveArray, lastIndexPath;
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    15
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    16
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    17
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    18
	return rotationManager(interfaceOrientation);
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    19
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    20
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    21
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    22
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    23
#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: 3373
diff changeset
    24
-(void) viewDidLoad {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    25
    [super viewDidLoad];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    26
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    27
    // load all the grave names and store them into graveArray
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    28
    self.graveArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:GRAVES_DIRECTORY() error:NULL];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    29
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    30
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    31
-(void) viewWillAppear:(BOOL)animated {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    32
    [super viewWillAppear:animated];
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    33
    [self.tableView reloadData];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    34
    // this moves the tableview to the top
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    35
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    36
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    37
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    38
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    39
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    40
#pragma mark Table view data source
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    41
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    42
    return 1;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    43
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    44
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    45
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    46
    return [self.graveArray count];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    47
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    48
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    49
// 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: 3373
diff changeset
    50
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    51
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    52
    static NSString *CellIdentifier = @"Cell";
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    53
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    54
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
3373
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3364
diff changeset
    55
    if (cell == nil)
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    56
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    57
    
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    58
    NSString *grave = [graveArray objectAtIndex:[indexPath row]];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    59
    cell.textLabel.text = [grave stringByDeletingPathExtension];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    60
    
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    61
    if ([grave isEqualToString:[teamDictionary objectForKey:@"grave"]]) {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    62
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    63
        self.lastIndexPath = indexPath;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    64
    } else {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    65
        cell.accessoryType = UITableViewCellAccessoryNone;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    66
    }
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    67
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    68
    NSString *graveFilePath = [[NSString alloc] initWithFormat:@"%@/%@",GRAVES_DIRECTORY(),grave];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    69
    // because we also have multi frame graves, let's take the first one only
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    70
    UIImage *graveSprite = [[UIImage alloc] initWithContentsOfFile:graveFilePath andCutAt:CGRectMake(0, 0, 32, 32)];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    71
    [graveFilePath release];        
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    72
    cell.imageView.image = graveSprite;
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    73
    [graveSprite release];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    74
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    75
    return cell;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    76
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    77
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    78
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    79
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    80
#pragma mark Table view delegate
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3352
diff changeset
    81
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    82
    int newRow = [indexPath row];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    83
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    84
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    85
    if (newRow != oldRow) {
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    86
        [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    87
        
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    88
        // tell our boss to write this new stuff on disk
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    89
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    90
        
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    91
        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: 3373
diff changeset
    92
        newCell.accessoryType = UITableViewCellAccessoryCheckmark;
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    93
        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: 3373
diff changeset
    94
        oldCell.accessoryType = UITableViewCellAccessoryNone;
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    95
        self.lastIndexPath = indexPath;
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    96
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    97
    }
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    98
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    99
    [self.navigationController popViewControllerAnimated:YES];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   100
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   101
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   102
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   103
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   104
#pragma mark Memory management
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   105
- (void)didReceiveMemoryWarning {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   106
    // Releases the view if it doesn't have a superview.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   107
    [super didReceiveMemoryWarning];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   108
    // Relinquish ownership any cached data, images, etc that aren't in use.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   109
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   110
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   111
- (void)viewDidUnload {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   112
    [super viewDidUnload];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   113
    self.lastIndexPath = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   114
    self.teamDictionary = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   115
    self.graveArray = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   116
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   117
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   118
- (void)dealloc {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   119
    [graveArray release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   120
    [teamDictionary release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   121
    [lastIndexPath release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   122
    [super dealloc];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   123
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   124
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   125
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   126
@end
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   127