project_files/HedgewarsMobile/Classes/GravesViewController.m
author koda
Thu, 17 Jun 2010 20:30:39 +0200
changeset 3514 59dbd31e9953
parent 3513 cocoaTouch/GravesViewController.m@f589230fa21b
child 3546 ccf4854df294
permissions -rw-r--r--
move stuff around and update iphone project
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
    static NSString *CellIdentifier = @"Cell";
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    52
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    53
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
3373
c1ff724a5c34 use a proper bundle identifier
koda
parents: 3364
diff changeset
    54
    if (cell == nil)
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    55
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    56
    
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    57
    NSString *grave = [self.graveArray objectAtIndex:[indexPath row]];
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
    cell.textLabel.text = [grave stringByDeletingPathExtension];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    59
    
3513
f589230fa21b now it's possible to select the scheme file in the ifrontendfix a type about loading an image (iphone file system IS case senstive)
koda
parents: 3490
diff changeset
    60
    if ([grave isEqualToString:[self.teamDictionary objectForKey:@"grave"]]) {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    61
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    62
        self.lastIndexPath = indexPath;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    63
    } else {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    64
        cell.accessoryType = UITableViewCellAccessoryNone;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    65
    }
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    66
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    67
    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
    68
    // 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
    69
    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
    70
    [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
    71
    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
    72
    [graveSprite release];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    73
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    74
    return cell;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    75
}
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
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    79
#pragma mark Table view delegate
3364
e5403e2bf02c no more hardcoded teams, team selection is real \o/
koda
parents: 3352
diff changeset
    80
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    81
    int newRow = [indexPath row];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    82
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    83
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    84
    if (newRow != oldRow) {
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    85
        [teamDictionary setObject:[[graveArray objectAtIndex:newRow] stringByDeletingPathExtension] forKey:@"grave"];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    86
        
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    87
        // tell our boss to write this new stuff on disk
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    88
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    89
        
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    90
        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
    91
        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
    92
        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
    93
        oldCell.accessoryType = UITableViewCellAccessoryNone;
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    94
        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
    95
        [aTableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    96
    }
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3373
diff changeset
    97
    [aTableView deselectRowAtIndexPath:indexPath animated:YES];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    98
    [self.navigationController popViewControllerAnimated:YES];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    99
}
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
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   103
#pragma mark Memory management
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   104
- (void)didReceiveMemoryWarning {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   105
    // Releases the view if it doesn't have a superview.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   106
    [super didReceiveMemoryWarning];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   107
    // Relinquish ownership any cached data, images, etc that aren't in use.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   108
}
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
- (void)viewDidUnload {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   111
    self.lastIndexPath = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   112
    self.teamDictionary = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   113
    self.graveArray = nil;
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3374
diff changeset
   114
    [super viewDidUnload];
016b3172b645 a bunch of minor stuff
koda
parents: 3374
diff changeset
   115
    MSG_DIDUNLOAD();
3339
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