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