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