cocoaTouch/LevelViewController.m
author sheepluva
Thu, 17 Jun 2010 13:56:30 +0200
changeset 3511 76e2d79b91b1
parent 3490 016b3172b645
permissions -rw-r--r--
some pt_BR translation changes by arrom
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
//  LevelViewController.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 "LevelViewController.h"
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    10
#import "CommodityFunctions.h"
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    11
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 LevelViewController
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    14
@synthesize teamDictionary, levelArray, levelSprites, lastIndexPath;
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
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    24
- (void)viewDidLoad {
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
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    27
    NSArray *array = [[NSArray alloc] initWithObjects:
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    28
                      NSLocalizedString(@"Human",@""),
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    29
                      NSLocalizedString(@"Brutal",@""),
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    30
                      NSLocalizedString(@"Aggressive",@""),
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    31
                      NSLocalizedString(@"Bully",@""),
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    32
                      NSLocalizedString(@"Average",@""),
3352
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    33
                      NSLocalizedString(@"Weaky",@""),
ac5d14a35482 complete previews on the team settings
koda
parents: 3340
diff changeset
    34
                      nil];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    35
    self.levelArray = array;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    36
    [array release];
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
- (void)viewWillAppear:(BOOL)animated {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    40
    [super viewWillAppear:animated];
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    41
    [self.tableView reloadData];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    42
    // this moves the tableview to the top
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    43
    [self.tableView setContentOffset:CGPointMake(0,0) animated:NO];
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
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    46
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    47
#pragma mark Table view data source
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    48
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    49
    return 1;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    50
}
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
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    53
    return [self.levelArray count];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    54
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    55
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    56
// Customize the appearance of table view cells.
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    57
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    58
    static NSString *CellIdentifier = @"Cell";
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    59
    
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    60
    NSInteger row = [indexPath row];
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    61
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    62
    if (cell == nil) {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    63
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    64
    }
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    65
    
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    66
    cell.textLabel.text = [levelArray objectAtIndex:row];
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    67
    NSDictionary *hog = [[self.teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:0];
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
    68
    if ([[hog objectForKey:@"level"] intValue] == row) {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    69
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    70
        self.lastIndexPath = indexPath;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    71
    } else {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    72
        cell.accessoryType = UITableViewCellAccessoryNone;
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
    
3374
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    75
    NSString *botlevelPath = [[NSString alloc] initWithFormat:@"%@/%d.png",BOTLEVELS_DIRECTORY(),row];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    76
    UIImage *levelImage = [[UIImage alloc] initWithContentsOfFile:botlevelPath];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    77
    [botlevelPath release];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    78
    cell.imageView.image = levelImage;
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    79
    [levelImage release];
0d522416d97f lazy loading for all the tables with images (might affect performance but ui feels much more responsive)
koda
parents: 3352
diff changeset
    80
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    81
    return cell;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    82
}
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
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    85
/*
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    86
// Override to support conditional editing of the table view.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    87
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    88
    // Return NO if you do not want the specified item to be editable.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    89
    return YES;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    90
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    91
*/
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    92
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    93
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    94
/*
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    95
// Override to support editing the table view.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    96
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    97
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    98
    if (editingStyle == UITableViewCellEditingStyleDelete) {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
    99
        // Delete the row from the data source
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   100
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
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
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   103
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   104
    }   
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   105
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   106
*/
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   107
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
// Override to support rearranging the table view.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   111
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   112
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   113
*/
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   114
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   115
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
// Override to support conditional rearranging of the table view.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   118
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   119
    // Return NO if you do not want the item to be re-orderable.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   120
    return YES;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   121
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   122
*/
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
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   126
#pragma mark Table view delegate
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   127
- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   128
    int newRow = [indexPath row];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   129
    int oldRow = (lastIndexPath != nil) ? [lastIndexPath row] : -1;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   130
    
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   131
    if (newRow != oldRow) {
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   132
        NSMutableArray *hogs = [teamDictionary objectForKey:@"hedgehogs"];
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   133
        
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   134
        for (NSMutableDictionary *hog in hogs) {
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   135
            [hog setObject:[NSNumber numberWithInt:newRow] forKey:@"level"];
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   136
        }
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   137
        
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   138
        // tell our boss to write this new stuff on disk
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   139
        [[NSNotificationCenter defaultCenter] postNotificationName:@"setWriteNeedTeams" object:nil];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   140
        [self.tableView reloadData];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   141
        
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   142
        self.lastIndexPath = indexPath;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   143
        [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   144
    }
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   145
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   146
    [self.navigationController popViewControllerAnimated:YES];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   147
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   148
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   149
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   150
#pragma mark -
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   151
#pragma mark Memory management
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   152
-(void) didReceiveMemoryWarning {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   153
    // Releases the view if it doesn't have a superview.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   154
    [super didReceiveMemoryWarning];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   155
    // Relinquish ownership any cached data, images, etc that aren't in use.
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   156
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   157
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   158
-(void) viewDidUnload {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   159
    self.lastIndexPath = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   160
    self.teamDictionary = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   161
    self.levelArray = nil;
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   162
    self.levelSprites = nil;
3490
016b3172b645 a bunch of minor stuff
koda
parents: 3374
diff changeset
   163
    [super viewDidUnload];
016b3172b645 a bunch of minor stuff
koda
parents: 3374
diff changeset
   164
    MSG_DIDUNLOAD();
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   165
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   166
3340
96dd168b080b fix all of what was committed before
koda
parents: 3339
diff changeset
   167
-(void) dealloc {
3339
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   168
    [levelArray release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   169
    [levelSprites release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   170
    [teamDictionary release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   171
    [lastIndexPath release];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   172
    [super dealloc];
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   173
}
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   174
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   175
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   176
@end
d558bc5a73c5 lots of untested stuff for the ifrontend
koda
parents:
diff changeset
   177