cocoaTouch/HogHatViewController.m
author koda
Sun, 04 Apr 2010 19:51:53 +0000
changeset 3305 91074496d5c9
child 3308 b6dcae4b6d2c
permissions -rw-r--r--
merged code from ipad and iphone frontends (aka HedgewarsMobile is a universal application)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3305
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     1
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     2
//  HogHatViewController.m
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     3
//  HedgewarsMobile
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     4
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     5
//  Created by Vittorio on 02/04/10.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     7
//
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     8
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
     9
#import "HogHatViewController.h"
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    10
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    11
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    12
@implementation HogHatViewController
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    13
@synthesize hatList, hog;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    14
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    15
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    16
#pragma mark View lifecycle
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    17
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    18
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    19
- (void)viewDidLoad {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    20
    [super viewDidLoad];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    21
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    22
    //NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    23
    NSString *hatPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    24
    NSArray *array = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:hatPath
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    25
                                                                         error:NULL];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    26
    self.hatList = array;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    27
    //NSLog(@"%@", hatList);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    28
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    29
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    30
- (void)viewWillAppear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    31
    [super viewWillAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    32
    self.title = [hog objectForKey:@"hogname"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    33
    [self.tableView reloadData];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    34
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    35
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    36
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    37
- (void)viewDidAppear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    38
    [super viewDidAppear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    39
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    40
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    41
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    42
- (void)viewWillDisappear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    43
    [super viewWillDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    44
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    45
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    46
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    47
- (void)viewDidDisappear:(BOOL)animated {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    48
    [super viewDidDisappear:animated];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    49
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    50
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    51
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    52
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    53
    // Override to allow orientations other than the default portrait orientation.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    54
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    55
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    56
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    57
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    58
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    59
#pragma mark Table view data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    60
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    61
    return 2;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    62
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    63
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    64
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    65
    NSInteger rows;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    66
    if (0 == section) 
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    67
        rows = 1;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    68
    else
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    69
        rows = [self.hatList count];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    70
    return rows;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    71
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    72
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    73
// Customize the appearance of table view cells.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    74
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    75
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    76
    static NSString *CellIdentifier = @"Cell";
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    77
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    78
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    79
    if (cell == nil) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    80
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    81
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    82
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    83
    if (0 == [indexPath section]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    84
        cell.textLabel.text = [hog objectForKey:@"hogname"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    85
        cell.imageView.image = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    86
        cell.accessoryType = UITableViewCellAccessoryNone;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    87
    } else {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    88
        cell.textLabel.text = [[hatList objectAtIndex:[indexPath row]] stringByDeletingPathExtension];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    89
        if ([cell.textLabel.text isEqualToString:[hog objectForKey:@"hat"]]) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    90
            cell.accessoryType = UITableViewCellAccessoryCheckmark;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    91
        } else {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    92
            cell.accessoryType = UITableViewCellAccessoryNone;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    93
        }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    94
        
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    95
        NSString *hatsPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/Data/Graphics/Hats/"];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    96
        NSString *hatFile = [hatsPath stringByAppendingString:[hatList objectAtIndex:[indexPath row]]];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    97
        UIImage *image = [UIImage imageWithContentsOfFile: hatFile];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    98
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
    99
        CGRect firstSpriteArea = CGRectMake(0, 0, 32, 32);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   100
        CGImageRef cgImgage = CGImageCreateWithImageInRect([image CGImage], firstSpriteArea);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   101
        cell.imageView.image = [UIImage imageWithCGImage: cgImgage];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   102
        CGImageRelease(cgImgage);
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   103
    }
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   104
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   105
    return cell;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   106
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   107
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   108
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   109
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   110
// Override to support conditional editing of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   111
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   112
    // Return NO if you do not want the specified item to be editable.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   113
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   114
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   115
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   116
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   117
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   118
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   119
// Override to support editing the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   120
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   121
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   122
    if (editingStyle == UITableViewCellEditingStyleDelete) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   123
        // Delete the row from the data source
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   124
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   125
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   126
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   127
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   128
    }   
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   129
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   130
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   131
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   132
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   133
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   134
// Override to support rearranging the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   135
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   136
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   137
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   138
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   139
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   140
/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   141
// Override to support conditional rearranging of the table view.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   142
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   143
    // Return NO if you do not want the item to be re-orderable.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   144
    return YES;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   145
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   146
*/
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   147
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   148
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   149
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   150
#pragma mark Table view delegate
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   151
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   152
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   153
    // Navigation logic may go here. Create and push another view controller.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   154
	/*
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   155
	 <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   156
     // ...
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   157
     // Pass the selected object to the new view controller.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   158
	 [self.navigationController pushViewController:detailViewController animated:YES];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   159
	 [detailViewController release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   160
	 */
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   161
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   162
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   163
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   164
#pragma mark -
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   165
#pragma mark Memory management
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   166
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   167
- (void)didReceiveMemoryWarning {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   168
    // Releases the view if it doesn't have a superview.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   169
    [super didReceiveMemoryWarning];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   170
    
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   171
    // Relinquish ownership any cached data, images, etc that aren't in use.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   172
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   173
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   174
- (void)viewDidUnload {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   175
    [super viewDidUnload];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   176
    self.hatList = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   177
    self.hog = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   178
    // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   179
    // For example: self.myOutlet = nil;
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   180
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   181
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   182
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   183
- (void)dealloc {
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   184
    [hog release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   185
    [hatList release];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   186
    [super dealloc];
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   187
}
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   188
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   189
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   190
@end
91074496d5c9 merged code from ipad and iphone frontends
koda
parents:
diff changeset
   191