project_files/HedgewarsMobile/Classes/SingleTeamViewController.m
author koda
Sun, 27 Jun 2010 18:34:17 +0200
changeset 3574 78fc6e61570b
parent 3547 02875b1145b7
child 3659 f8d5ac50e307
permissions -rw-r--r--
insert a default name when a void string is used polish schemes configuration fixed strange bug in the general panel
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     1
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     2
//  SingleTeamViewController.m
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     3
//  HedgewarsMobile
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     4
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     5
//  Created by Vittorio on 02/04/10.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     6
//  Copyright 2010 __MyCompanyName__. All rights reserved.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     7
//
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     8
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
     9
#import "SingleTeamViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    10
#import "HogHatViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    11
#import "GravesViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    12
#import "VoicesViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    13
#import "FortsViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    14
#import "FlagsViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    15
#import "LevelViewController.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    16
#import "CommodityFunctions.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    17
#import "UIImageExtra.h"
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    18
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    19
#define TEAMNAME_TAG 1234
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    20
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    21
@implementation SingleTeamViewController
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    22
@synthesize teamDictionary, normalHogSprite, secondaryItems, textFieldBeingEdited, teamName;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    23
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    24
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    25
-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    26
    return rotationManager(interfaceOrientation);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    27
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    28
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    29
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    30
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    31
#pragma mark textfield methods
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    32
-(void) cancel:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    33
    if (textFieldBeingEdited != nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    34
        [self.textFieldBeingEdited resignFirstResponder];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    35
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    36
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    37
// set the new value
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    38
-(BOOL) save:(id) sender {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    39
    NSInteger index = textFieldBeingEdited.tag;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    40
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    41
    if (textFieldBeingEdited != nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    42
        if (TEAMNAME_TAG == index) {
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3547
diff changeset
    43
            if ([textFieldBeingEdited.text length] == 0) 
78fc6e61570b insert a default name when a void string is used
koda
parents: 3547
diff changeset
    44
                textFieldBeingEdited.text = self.title;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    45
            [self.teamDictionary setObject:textFieldBeingEdited.text forKey:@"teamname"];
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3547
diff changeset
    46
            self.title = textFieldBeingEdited.text;
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    47
        } else {
3574
78fc6e61570b insert a default name when a void string is used
koda
parents: 3547
diff changeset
    48
            if ([textFieldBeingEdited.text length] == 0) 
78fc6e61570b insert a default name when a void string is used
koda
parents: 3547
diff changeset
    49
                textFieldBeingEdited.text = [NSString stringWithFormat:@"hedgehog %d",index];
78fc6e61570b insert a default name when a void string is used
koda
parents: 3547
diff changeset
    50
            
3547
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    51
            //replace the old value with the new one            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    52
            NSMutableDictionary *hog = [[teamDictionary objectForKey:@"hedgehogs"] objectAtIndex:index];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    53
            [hog setObject:textFieldBeingEdited.text forKey:@"hogname"];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    54
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    55
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    56
        isWriteNeeded = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    57
        [self.textFieldBeingEdited resignFirstResponder];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    58
        return YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    59
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    60
    return NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    61
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    62
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    63
// the textfield is being modified, update the navigation controller
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    64
-(void) textFieldDidBeginEditing:(UITextField *)aTextField{   
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    65
    self.textFieldBeingEdited = aTextField;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    66
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    67
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Cancel",@"from the hog name table")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    68
                                                                     style:UIBarButtonItemStylePlain
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    69
                                                                    target:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    70
                                                                    action:@selector(cancel:)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    71
    self.navigationItem.leftBarButtonItem = cancelButton;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    72
    [cancelButton release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    73
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    74
    UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Save",@"from the hog name table")
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    75
                                                                     style:UIBarButtonItemStyleDone
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    76
                                                                    target:self
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    77
                                                                    action:@selector(save:)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    78
    self.navigationItem.rightBarButtonItem = saveButton;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    79
    [saveButton release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    80
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    81
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    82
// the textfield has been modified, check for empty strings and restore original navigation bar
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    83
-(void) textFieldDidEndEditing:(UITextField *)aTextField{
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    84
    if ([textFieldBeingEdited.text length] == 0) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    85
        textFieldBeingEdited.text = [NSString stringWithFormat:@"hedgehog %d",textFieldBeingEdited.tag];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    86
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    87
    self.textFieldBeingEdited = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    88
    self.navigationItem.rightBarButtonItem = self.navigationItem.backBarButtonItem;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    89
    self.navigationItem.leftBarButtonItem = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    90
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    91
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    92
// limit the size of the field to 64 characters like in original frontend
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    93
-(BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    94
    int limit = 64;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    95
    return !([textField.text length] > limit && [string length] > range.length);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    96
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    97
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    98
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
    99
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   100
#pragma mark View lifecycle
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   101
-(void) viewDidLoad {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   102
    [super viewDidLoad];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   103
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   104
    // labels for the entries
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   105
    NSArray *array = [[NSArray alloc] initWithObjects:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   106
                      NSLocalizedString(@"Grave",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   107
                      NSLocalizedString(@"Voice",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   108
                      NSLocalizedString(@"Fort",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   109
                      NSLocalizedString(@"Flag",@""),
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   110
                      NSLocalizedString(@"Level",@""),nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   111
    self.secondaryItems = array;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   112
    [array release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   113
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   114
    // load the base hog image, drawing will occure in cellForRow...
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   115
    NSString *normalHogFile = [[NSString alloc] initWithFormat:@"%@/Hedgehog.png",GRAPHICS_DIRECTORY()];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   116
    UIImage *hogSprite = [[UIImage alloc] initWithContentsOfFile:normalHogFile andCutAt:CGRectMake(96, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   117
    [normalHogFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   118
    self.normalHogSprite = hogSprite;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   119
    [hogSprite release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   120
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   121
    // listen if any childController modifies the plist and write it if needed
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   122
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setWriteNeeded) name:@"setWriteNeedTeams" object:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   123
    isWriteNeeded = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   124
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   125
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   126
-(void) viewWillAppear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   127
    [super viewWillAppear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   128
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   129
    // load data about the team and write if there has been a change
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   130
    if (isWriteNeeded) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   131
        [self writeFile];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   132
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   133
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.title];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   134
    NSMutableDictionary *teamDict = [[NSMutableDictionary alloc] initWithContentsOfFile:teamFile];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   135
    self.teamDictionary = teamDict;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   136
    [teamDict release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   137
    [teamFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   138
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   139
    self.teamName = self.title;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   140
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   141
    [self.tableView reloadData];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   142
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   143
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   144
// write on file if there has been a change
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   145
-(void) viewWillDisappear:(BOOL)animated {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   146
    [super viewWillDisappear:animated];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   147
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   148
    // end the editing of the current field
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   149
    if (textFieldBeingEdited != nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   150
        [self save:nil];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   151
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   152
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   153
    if (isWriteNeeded) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   154
        [self writeFile];        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   155
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   156
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   157
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   158
// needed by other classes to warn about a user change
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   159
-(void) setWriteNeeded {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   160
    isWriteNeeded = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   161
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   162
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   163
-(void) writeFile {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   164
    NSString *teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),self.title];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   165
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   166
    NSString *newTeamName = [self.teamDictionary objectForKey:@"teamname"];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   167
    if (![newTeamName isEqualToString:self.teamName]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   168
        //delete old
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   169
        [[NSFileManager defaultManager] removeItemAtPath:teamFile error:NULL];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   170
        [teamFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   171
        self.title = newTeamName;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   172
        self.teamName = newTeamName;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   173
        teamFile = [[NSString alloc] initWithFormat:@"%@/%@.plist",TEAMS_DIRECTORY(),newTeamName];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   174
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   175
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   176
    [self.teamDictionary writeToFile:teamFile atomically:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   177
    NSLog(@"writing: %@",teamDictionary);
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   178
    isWriteNeeded = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   179
    [teamFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   180
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   181
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   182
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   183
#pragma mark Table view data source
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   184
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   185
    return 3;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   186
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   187
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   188
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   189
    NSInteger rows = 0;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   190
    switch (section) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   191
        case 0: // team name
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   192
            rows = 1;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   193
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   194
        case 1: // team members
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   195
            rows = MAX_HOGS;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   196
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   197
        case 2: // team details
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   198
            rows = [self.secondaryItems count];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   199
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   200
        default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   201
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   202
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   203
    return rows;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   204
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   205
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   206
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   207
    static NSString *CellIdentifier0 = @"Cell0";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   208
    static NSString *CellIdentifier1 = @"Cell1";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   209
    static NSString *CellIdentifier2 = @"Cell2";
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   210
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   211
    NSArray *hogArray;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   212
    UITableViewCell *cell = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   213
    NSInteger row = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   214
    UIImage *accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   215
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   216
    switch ([indexPath section]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   217
        case 0:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   218
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier0];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   219
            if (cell == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   220
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   221
                                               reuseIdentifier:CellIdentifier0] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   222
                // create a uitextfield for each row, expand it to take the maximum size
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   223
                UITextField *aTextField = [[UITextField alloc] 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   224
                                           initWithFrame:CGRectMake(5, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   225
                aTextField.clearsOnBeginEditing = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   226
                aTextField.returnKeyType = UIReturnKeyDone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   227
                aTextField.adjustsFontSizeToFitWidth = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   228
                aTextField.delegate = self;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   229
                aTextField.tag = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   230
                aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   231
                aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   232
                [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   233
                [cell.contentView addSubview:aTextField];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   234
                [aTextField release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   235
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   236
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   237
            cell.imageView.image = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   238
            cell.accessoryType = UITableViewCellAccessoryNone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   239
            for (UIView *oneView in cell.contentView.subviews) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   240
                if ([oneView isMemberOfClass:[UITextField class]]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   241
                    // we find the uitextfied and we'll use its tag to understand which one is being edited
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   242
                    UITextField *textFieldFound = (UITextField *)oneView;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   243
                    textFieldFound.text = [self.teamDictionary objectForKey:@"teamname"];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   244
                    textFieldFound.tag = TEAMNAME_TAG;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   245
                }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   246
            }            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   247
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   248
        case 1:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   249
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   250
            if (cell == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   251
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   252
                                               reuseIdentifier:CellIdentifier1] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   253
                
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   254
                // create a uitextfield for each row, expand it to take the maximum size
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   255
                UITextField *aTextField = [[UITextField alloc] 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   256
                                           initWithFrame:CGRectMake(42, 12, (cell.frame.size.width + cell.frame.size.width/3) - 42, 25)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   257
                aTextField.clearsOnBeginEditing = NO;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   258
                aTextField.returnKeyType = UIReturnKeyDone;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   259
                aTextField.adjustsFontSizeToFitWidth = YES;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   260
                aTextField.delegate = self;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   261
                aTextField.tag = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   262
                aTextField.font = [UIFont boldSystemFontOfSize:[UIFont systemFontSize] + 2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   263
                aTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   264
                [aTextField addTarget:self action:@selector(save:) forControlEvents:UIControlEventEditingDidEndOnExit];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   265
                [cell.contentView addSubview:aTextField];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   266
                [aTextField release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   267
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   268
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   269
            hogArray = [self.teamDictionary objectForKey:@"hedgehogs"];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   270
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   271
            NSString *hatFile = [[NSString alloc] initWithFormat:@"%@/%@.png", HATS_DIRECTORY(), [[hogArray objectAtIndex:row] objectForKey:@"hat"]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   272
            UIImage *hatSprite = [[UIImage alloc] initWithContentsOfFile: hatFile andCutAt:CGRectMake(0, 0, 32, 32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   273
            [hatFile release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   274
            cell.imageView.image = [self.normalHogSprite mergeWith:hatSprite atPoint:CGPointMake(0, -5)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   275
            [hatSprite release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   276
                        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   277
            for (UIView *oneView in cell.contentView.subviews) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   278
                if ([oneView isMemberOfClass:[UITextField class]]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   279
                    // we find the uitextfied and we'll use its tag to understand which one is being edited
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   280
                    UITextField *textFieldFound = (UITextField *)oneView;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   281
                    textFieldFound.text = [[hogArray objectAtIndex:row] objectForKey:@"hogname"];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   282
                }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   283
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   284
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   285
            cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   286
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   287
        case 2:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   288
            cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   289
            if (cell == nil) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   290
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   291
                                               reuseIdentifier:CellIdentifier2] autorelease];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   292
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   293
            
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   294
            cell.textLabel.text = [self.secondaryItems objectAtIndex:row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   295
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   296
            switch (row) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   297
                case 0: // grave
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   298
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   299
                                                                              GRAVES_DIRECTORY(),[teamDictionary objectForKey:@"grave"]]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   300
                                                                    andCutAt:CGRectMake(0,0,32,32)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   301
                    cell.imageView.image = accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   302
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   303
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   304
                case 2: // fort
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   305
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@L.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   306
                                                                              FORTS_DIRECTORY(),[teamDictionary objectForKey:@"fort"]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   307
                    cell.imageView.image = [accessoryImage scaleToSize:CGSizeMake(42, 42)];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   308
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   309
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   310
                    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   311
                case 3: // flags
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   312
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   313
                                                                              FLAGS_DIRECTORY(),[teamDictionary objectForKey:@"flag"]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   314
                    cell.imageView.image = accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   315
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   316
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   317
                case 4: // level
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   318
                    accessoryImage = [[UIImage alloc] initWithContentsOfFile:[NSString stringWithFormat:@"%@/%d.png",
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   319
                                                                              BOTLEVELS_DIRECTORY(),[[[[teamDictionary objectForKey:@"hedgehogs"]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   320
                                                                                                      objectAtIndex:0] objectForKey:@"level"]
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   321
                                                                                                     intValue]]];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   322
                    cell.imageView.image = accessoryImage;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   323
                    [accessoryImage release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   324
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   325
                default:
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   326
                    cell.imageView.image = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   327
                    break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   328
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   329
            break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   330
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   331
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   332
    return cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   333
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   334
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   335
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   336
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   337
#pragma mark Table view delegate
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   338
-(void) tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   339
    NSInteger row = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   340
    NSInteger section = [indexPath section];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   341
    UITableViewController *nextController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   342
    UITableViewCell *cell;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   343
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   344
    if (2 == section) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   345
        switch (row) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   346
            case 0: // grave
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   347
                if (nil == gravesViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   348
                    gravesViewController = [[GravesViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   349
                
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   350
                nextController = gravesViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   351
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   352
            case 1: // voice
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   353
                if (nil == voicesViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   354
                    voicesViewController = [[VoicesViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   355
                
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   356
                nextController = voicesViewController;                    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   357
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   358
            case 2: // fort
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   359
                if (nil == fortsViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   360
                    fortsViewController = [[FortsViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   361
                
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   362
                nextController = fortsViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   363
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   364
            case 3: // flag
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   365
                if (nil == flagsViewController) 
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   366
                    flagsViewController = [[FlagsViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   367
                
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   368
                nextController = flagsViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   369
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   370
            case 4: // level
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   371
                if (nil == levelViewController)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   372
                    levelViewController = [[LevelViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   373
                
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   374
                nextController = levelViewController;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   375
                break;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   376
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   377
        
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   378
        nextController.title = [secondaryItems objectAtIndex:row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   379
        [nextController setTeamDictionary:teamDictionary];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   380
        [self.navigationController pushViewController:nextController animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   381
    } else {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   382
        cell = [aTableView cellForRowAtIndexPath:indexPath];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   383
        for (UIView *oneView in cell.contentView.subviews) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   384
            if ([oneView isMemberOfClass:[UITextField class]]) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   385
                textFieldBeingEdited = (UITextField *)oneView;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   386
                [textFieldBeingEdited becomeFirstResponder];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   387
            }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   388
        }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   389
        [aTableView deselectRowAtIndexPath:indexPath animated:NO];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   390
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   391
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   392
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   393
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   394
// action to perform when you want to change a hog hat
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   395
-(void) tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   396
    if (nil == hogHatViewController) {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   397
        hogHatViewController = [[HogHatViewController alloc] initWithStyle:UITableViewStyleGrouped];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   398
    }
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   399
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   400
    // cache the dictionary file of the team, so that other controllers can modify it
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   401
    hogHatViewController.teamDictionary = self.teamDictionary;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   402
    hogHatViewController.selectedHog = [indexPath row];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   403
    
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   404
    [self.navigationController pushViewController:hogHatViewController animated:YES];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   405
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   406
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   407
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   408
#pragma mark -
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   409
#pragma mark Memory management
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   410
-(void) didReceiveMemoryWarning {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   411
    // Releases the view if it doesn't have a superview.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   412
    [super didReceiveMemoryWarning];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   413
    // Relinquish ownership any cached data, images, etc that aren't in use.
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   414
    if (hogHatViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   415
        hogHatViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   416
    if (gravesViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   417
        gravesViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   418
    if (voicesViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   419
        voicesViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   420
    if (fortsViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   421
        fortsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   422
    if (flagsViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   423
        flagsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   424
    if (levelViewController.view.superview == nil)
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   425
        levelViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   426
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   427
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   428
-(void) viewDidUnload {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   429
    self.teamDictionary = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   430
    self.textFieldBeingEdited = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   431
    self.teamName = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   432
    self.normalHogSprite = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   433
    self.secondaryItems = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   434
    hogHatViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   435
    flagsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   436
    fortsViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   437
    gravesViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   438
    levelViewController = nil;
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   439
    [super viewDidUnload];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   440
    MSG_DIDUNLOAD();
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   441
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   442
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   443
-(void) dealloc {
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   444
    [teamDictionary release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   445
    [textFieldBeingEdited release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   446
    [teamName release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   447
    [normalHogSprite release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   448
    [secondaryItems release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   449
    [hogHatViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   450
    [fortsViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   451
    [gravesViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   452
    [flagsViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   453
    [levelViewController release];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   454
    [super dealloc];
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   455
}
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   456
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   457
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   458
@end
02875b1145b7 i <3 mercurial
koda
parents: 3546
diff changeset
   459